]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/logwatch/bacula
License cleanups
[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 Kern Sibbald 2005-2015
9 # License: BSD 2-Clause
10
11 use strict;
12 use POSIX qw(strftime);
13
14 my (@JobName,$JobStatus,$ThisName,$ThisStatus,$ThisDate);
15 my ($Job,$JobId,$JobDate,$Debug,$DebugCounter,%data);
16
17 # set debug level
18 $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
19
20 if ( $Debug >= 5 ) {
21         print STDERR "\n\nDEBUG: Inside Bacula Filter \n\n";
22         $DebugCounter = 1;
23 }
24
25 while (<STDIN>) {
26         chomp;
27         if ( $Debug >= 5 ) {
28                 print STDERR "DEBUG($DebugCounter): $_\n";
29                 $DebugCounter++;
30         }
31
32         # Test the line for a new entry, which is a jobid record
33         if (/^\s*JobId:\s+(\d+)/) {
34                 $JobId = $1;
35                 next;
36         }
37
38         (/^\s*Job:\s*(.*)/) and $Job = $1; 
39         (/^\s*Termination:\s*(.*)/) and $JobStatus = $1;
40         (/^\s*Job:.*(\d{4}-\d{2}-\d{2})/) and $JobDate = $1;
41
42         if ($JobId and $Job and $JobStatus and $JobDate) {
43                 $data{$JobId} = { 
44                         "Job" => $Job, 
45                         "JobStatus" => $JobStatus,
46                         "JobDate" => $JobDate,
47                 };
48                 $JobId = $Job = $JobStatus = $JobDate = "";
49         }
50 }
51
52 # if we have data print it out, otherwise do nothing
53 if (scalar(keys(%data))) {
54         print "\nJobs Run:\n";
55         foreach my $Id (sort {$a<=>$b} (keys(%data))) {
56                 $ThisName = $data{$Id}{Job};
57                 $ThisStatus = $data{$Id}{JobStatus};
58                 $ThisDate = $data{$Id}{JobDate};
59                 $ThisName =~ s/\s//g;
60                 $ThisStatus =~ s/\s//g;
61                 print "$ThisDate $Id $ThisName\n     $ThisStatus\n\n";
62         }
63 }
64
65 exit(0);