1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#!/usr/bin/perl -w
#
# logwatch filter script for bacula log files
#
# Mon Jan 03 2005
# D. Scott Barninger and Karl Cunningham
#
# Copyright 2005-2006 Free Software Foundation Europe e.V.
# licensed under GPL-v2
use strict;
use POSIX qw(strftime);
my (@JobName,$JobStatus,$ThisName,$ThisStatus,$ThisDate);
my ($Job,$JobId,$JobDate,$Debug,$DebugCounter,%data);
# set debug level
$Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
if ( $Debug >= 5 ) {
print STDERR "\n\nDEBUG: Inside Bacula Filter \n\n";
$DebugCounter = 1;
}
while (<STDIN>) {
chomp;
if ( $Debug >= 5 ) {
print STDERR "DEBUG($DebugCounter): $_\n";
$DebugCounter++;
}
# Test the line for a new entry, which is a jobid record
if (/^\s*JobId:\s+(\d+)/) {
$JobId = $1;
next;
}
(/^\s*Job:\s*(.*)/) and $Job = $1;
(/^\s*Termination:\s*(.*)/) and $JobStatus = $1;
(/^\s*Job:.*(\d{4}-\d{2}-\d{2})/) and $JobDate = $1;
if ($JobId and $Job and $JobStatus and $JobDate) {
$data{$JobId} = {
"Job" => $Job,
"JobStatus" => $JobStatus,
"JobDate" => $JobDate,
};
$JobId = $Job = $JobStatus = $JobDate = "";
}
}
# if we have data print it out, otherwise do nothing
if (scalar(keys(%data))) {
print "\nJobs Run:\n";
foreach my $Id (sort {$a<=>$b} (keys(%data))) {
$ThisName = $data{$Id}{Job};
$ThisStatus = $data{$Id}{JobStatus};
$ThisDate = $data{$Id}{JobDate};
$ThisName =~ s/\s//g;
$ThisStatus =~ s/\s//g;
print "$ThisDate $Id $ThisName\n $ThisStatus\n\n";
}
}
exit(0);
|