]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/logwatch/bacula
Remove obsolete .cvsignore files.
[bacula/bacula] / bacula / scripts / logwatch / bacula
1 #!/usr/bin/perl -w
2 #
3 # logwatch filter script for bacula log files
4 #
5 # Mon Jan 03 2005
6 # D. Scott Barninger and Karl Cunningham
7 #
8 # Copyright 2005-2006 Free Software Foundation Europe e.V.
9 # licensed under GPL-v2
10
11 use strict;
12 use POSIX qw(strftime);
13
14 my (@JobName,$JobStatus,$ThisName,$ThisStatus,$ThisDate,$SearchDate);
15 my ($Job,$JobId,$JobDate,$Debug,$DebugCounter,%data,$time);
16
17 # set the logwatch search date we want
18 $time = time;
19
20 if ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'yesterday') {
21    $SearchDate = strftime("%Y-%m-%d", localtime($time-86400));
22 }
23 elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
24    $SearchDate = strftime("%Y-%m-%d", localtime($time));
25 }
26
27 # set debug level
28 $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
29
30 if ( $Debug >= 5 ) {
31         print STDERR "\n\nDEBUG: Inside Bacula Filter \n\n";
32         $DebugCounter = 1;
33 }
34
35 while (<STDIN>) {
36         chomp;
37         if ( $Debug >= 5 ) {
38                 print STDERR "DEBUG($DebugCounter): $_\n";
39                 $DebugCounter++;
40         }
41
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) {
47                         $data{$JobId} = { 
48                                 "Job" => $Job, 
49                                 "JobStatus" => $JobStatus,
50                                 "JobDate" => $JobDate,
51                         };
52                         $Job = $JobStatus = $JobDate = "";
53                 }
54                 $JobId = $1;
55                 next;
56         }
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;
60 }
61
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};
69                 $ThisName =~ s/\s//g;
70                 $ThisStatus =~ s/\s//g;
71                 if ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
72                         $SearchDate = $ThisDate;
73                 }
74                 if ($ThisDate eq $SearchDate) {
75                         print "$ThisDate $Id $ThisName\n     $ThisStatus\n\n";
76                 }
77         }
78 }
79
80 exit(0);
81