3 # logwatch filter script for bacula log files
6 # D. Scott Barninger and Karl Cunningham
8 # Copyright 2005-2006 Free Software Foundation Europe e.V.
9 # licensed under GPL-v2
12 use POSIX qw(strftime);
14 my (@JobName,$JobStatus,$ThisName,$ThisStatus,$ThisDate,$SearchDate);
15 my ($Job,$JobId,$JobDate,$Debug,$DebugCounter,%data,$time);
17 # set the logwatch search date we want
20 if ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'yesterday') {
21 $SearchDate = strftime("%Y-%m-%d", localtime($time-86400));
23 elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
24 $SearchDate = strftime("%Y-%m-%d", localtime($time));
28 $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
31 print STDERR "\n\nDEBUG: Inside Bacula Filter \n\n";
38 print STDERR "DEBUG($DebugCounter): $_\n";
42 # Test the line for a new entry, which is a jobid record
43 if (/^\s*JobId:\s+(\d+)/) {
44 # A new entry. Test, then save the previous stuff and
45 # set up to grab more.
46 if ($JobId and $Job and $JobStatus and $JobDate) {
49 "JobStatus" => $JobStatus,
50 "JobDate" => $JobDate,
52 $Job = $JobStatus = $JobDate = "";
57 (/^\s*Job:\s*(.*)/) and $Job = $1;
58 (/^\s*Termination:\s*(.*)/) and $JobStatus = $1;
59 (/^\s*Job:.*(\d{4}-\d{2}-\d{2})/) and $JobDate = $1;
62 # if we have data print it out, otherwise do nothing
63 if (scalar(keys(%data))) {
64 print "\nJobs Run:\n";
65 foreach my $Id (sort {$a<=>$b} (keys(%data))) {
66 $ThisName = $data{$Id}{Job};
67 $ThisStatus = $data{$Id}{JobStatus};
68 $ThisDate = $data{$Id}{JobDate};
70 $ThisStatus =~ s/\s//g;
71 if ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
72 $SearchDate = $ThisDate;
74 if ($ThisDate eq $SearchDate) {
75 print "$ThisDate $Id $ThisName\n $ThisStatus\n\n";