5 check_bacula.pl -- check for bacula status
10 -C|--Client=ss List of clients
11 -g|--group=ss List of groups
13 -a|--age=i Age in hours (default 10h)
14 -w|--warning=i warning threshold (jobs)
15 -c|--critical=i critical threshold (jobs)
17 -S|--Storage=ss List of SDs to test
19 -s|--scratch=i threshold scratch number
20 -m|--mediatype=ss Media type to check for scratch
25 check_bacula.pl -C c1 -C c2 -w 10 -c 15 -S S1_LTO1 -S S1_LTO2 -m 2 -m S%
29 Bweb - A Bacula web interface
30 Bacula® - The Network Backup Solution
32 Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
34 The main author of Bweb is Eric Bollengier.
35 The main author of Bacula is Kern Sibbald, with contributions from
36 many others, a complete list can be found in the file AUTHORS.
38 This program is Free Software; you can redistribute it and/or
39 modify it under the terms of version two of the GNU General Public
40 License as published by the Free Software Foundation plus additions
41 that are listed in the file LICENSE.
43 This program is distributed in the hope that it will be useful, but
44 WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
46 General Public License for more details.
48 You should have received a copy of the GNU General Public License
49 along with this program; if not, write to the Free Software
50 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
53 Bacula® is a registered trademark of John Walker.
54 The licensor of Bacula is the Free Software Foundation Europe
55 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
56 Switzerland, email:ftf@fsfeurope.org.
64 use POSIX qw/strftime/;
65 use Getopt::Long qw/:config no_ignore_case/;
68 my $config_file = $Bweb::config_file;
69 my (@client, @group, $help, $query, $verbose, @msg, @storage);
71 my $mediatype='%'; # check for all mediatype
72 my $nb_scratch=5; # check for more than 5 scratch media
78 my $timeout=50; # timeout for storage status command
80 GetOptions("Client=s@" => \@client,
81 "group=s@" => \@group,
83 "scratch=i" => \$nb_scratch,
84 "warning=i" => \$warn,
85 "critical=i"=> \$crit,
86 "verbose" => \$verbose,
87 "timeout=i" => \$timeout,
88 "Storage=s@"=> \@storage,
89 "mediatype=s"=> \$mediatype,
91 || Pod::Usage::pod2usage(-exitval => 2, -verbose => 1) ;
93 Pod::Usage::pod2usage(-verbose => 1) if ( $help ) ;
101 my $since = time - $age;
102 my $trig = time - 2*60*60;
104 my $conf = new Bweb::Config(config_file => $config_file);
106 my $bweb = new Bweb(info => $conf);
108 my $b = $bweb->get_bconsole();
109 $b->{timeout} = $timeout;
111 CGI::param(-name=> 'client',-value => \@client);
112 CGI::param(-name=> 'client_group', -value => \@group);
114 my ($where, undef) = $bweb->get_param(qw/clients client_groups/);
116 ################################################################
117 # check if more than X jobs are running for too long (more than
118 # 2 hours) since Y ago
121 SELECT count(1) AS nb
123 WHERE JobStatus = 'R'
125 AND JobTDate > $since
130 $res = $bweb->dbh_selectrow_hashref($query);
134 push @msg, "$nb jobs are running";
136 } elsif ($nb > $warn) {
137 push @msg, "$nb jobs are running";
138 $ret = ($ret>1)?$ret:1;
142 ################################################################
143 # check failed jobs (more than X) since x time ago
146 SELECT count(1) AS nb
148 WHERE JobStatus IN ('E','e','f','A')
150 AND JobTDate > $since
154 $res = $bweb->dbh_selectrow_hashref($query);
158 push @msg, "$nb jobs are in error";
160 } elsif ($nb > $warn) {
161 push @msg, "$nb jobs are in error";
162 $ret = ($ret>1)?$ret:1;
166 ################################################################
167 # check storage status command
169 foreach my $st (@storage) {
171 my $out = $b->send_cmd("status storage=\"$st\"");
172 if (!$out || $out !~ /Attr spooling/) {
173 push @msg, "timeout ($timeout s) on status storage $st";
178 ################################################################
179 # check for Scratch volume
182 SELECT MediaType AS mediatype, count(MediaId) AS nb
183 FROM Media JOIN Pool USING (PoolId)
184 WHERE Pool.Name = 'Scratch'
185 AND Media.MediaType LIKE '$mediatype'
190 $res = $bweb->dbh_selectall_hashref($query, 'mediatype');
192 foreach my $k (keys %$res) {
193 if ($res->{$k}->{nb} < $nb_scratch) {
194 push @msg, "no more scratch for $k ($res->{$k}->{nb})";
200 ################################################################
204 print "OK - All checks ok\n";
205 } elsif ($ret == 1) {
206 print "WARNING - ", join(", ", @msg), "\n";
208 print "CRITICAL - ", join(", ", @msg), "\n";