5 check_bacula.pl -- check for bacula status
10 -C|--Client=ss List of clients
11 -g|--group=ss List of groups
13 -l|--level=F/I/D Specify job level
15 -a|--age=i Age in hours (default 10h)
16 -w|--warning=i warning threshold (jobs)
17 -c|--critical=i critical threshold (jobs)
19 -S|--Storage=ss List of SDs to test
21 -s|--scratch=i threshold scratch number
22 -m|--mediatype=ss Media type to check for scratch
24 -M|--MaxRun Test for maximum running jobs
25 -F|--Failed Test for canceled or failed jobs
30 - if more than 10 jobs are running for client c1 and c2 for 1 hour
31 check_bacula.pl -M -C c1 -C c2 -w 10 -c 15 -a 1
33 - if more than 10 jobs are running for group g1 for 2 hours
34 check_bacula.pl -M -g g1 -w 10 -c 15 -a 2
36 - if more than 10 jobs are failed of canceled for 2 hours for group g1
37 check_bacula.pl -F -g g1 -w 10 -c 15 -a 2
39 - if S1_LTO1 and S1_LTO2 storage deamon are responding to status cmd
40 check_bacula.pl -S S1_LTO1 -S S1_LTO2
42 - if the scratch pool contains 5 volumes with mediatype Tape% at minimum
43 check_bacula.pl -s 2 -m Tape%
45 You can mix all options
47 check_bacula.pl -g g1 -w 10 -c 15 -S S1_LTO1 -s 2 -m Tape%
49 - if we have more than 10 jobs in error or already running for 2 hours
50 check_bacula.pl -M -F -w 10 -c 15 -a 2
54 Bweb - A Bacula web interface
55 Bacula® - The Network Backup Solution
57 Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
59 The main author of Bweb is Eric Bollengier.
60 The main author of Bacula is Kern Sibbald, with contributions from
61 many others, a complete list can be found in the file AUTHORS.
63 This program is Free Software; you can redistribute it and/or
64 modify it under the terms of version two of the GNU General Public
65 License as published by the Free Software Foundation plus additions
66 that are listed in the file LICENSE.
68 This program is distributed in the hope that it will be useful, but
69 WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71 General Public License for more details.
73 You should have received a copy of the GNU General Public License
74 along with this program; if not, write to the Free Software
75 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
78 Bacula® is a registered trademark of John Walker.
79 The licensor of Bacula is the Free Software Foundation Europe
80 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
81 Switzerland, email:ftf@fsfeurope.org.
89 use POSIX qw/strftime/;
90 use Getopt::Long qw/:config no_ignore_case/;
93 my $config_file = $Bweb::config_file;
94 my (@client, @group, $help, $query, $verbose, @msg, @storage);
98 my $mediatype='%'; # check for all mediatype
99 my $nb_scratch; # check for scratch media
106 my $timeout=50; # timeout for storage status command
108 GetOptions("Client=s@" => \@client,
109 "group=s@" => \@group,
111 "scratch=i" => \$nb_scratch,
112 "warning=i" => \$warn,
113 "critical=i"=> \$crit,
114 "verbose" => \$verbose,
115 "timeout=i" => \$timeout,
116 "Storage=s@"=> \@storage,
117 "mediatype=s"=> \$mediatype,
118 "MaxRun" => \$max_run,
119 "Failed" => \$test_failed,
120 "level=s" => \$level,
122 || Pod::Usage::pod2usage(-exitval => 2, -verbose => 1) ;
124 Pod::Usage::pod2usage(-verbose => 1) if ( $help ) ;
129 $age = 10*60*60; # set default to 10h
132 my $since = time - $age;
133 my $trig = time - 2*60*60;
135 my $conf = new Bweb::Config(config_file => $config_file);
137 my $bweb = new Bweb(info => $conf);
139 my $b = $bweb->get_bconsole();
140 $b->{timeout} = $timeout;
142 CGI::param(-name=> 'client',-value => \@client);
143 CGI::param(-name=> 'client_group', -value => \@group);
144 CGI::param(-name=> 'level', -value => $level);
146 my ($where, undef) = $bweb->get_param(qw/clients client_groups level/);
152 $c_filter = " JOIN Client USING (ClientId) ";
156 $g_filter = " JOIN client_group_member USING (ClientId) " .
157 " JOIN client_group USING (client_group_id) ";
160 ################################################################
161 # check if more than X jobs are running or just created
162 # for too long (more than 2 hours) since Y ago
166 SELECT count(1) AS nb
167 FROM Job $c_filter $g_filter
169 WHERE JobStatus IN ('R', 'C')
171 AND JobTDate > $since
176 $res = $bweb->dbh_selectrow_hashref($query);
180 push @msg, "$nb jobs are running";
182 } elsif ($nb >= $warn) {
183 push @msg, "$nb jobs are running";
184 $ret = ($ret>1)?$ret:1;
189 ################################################################
190 # check failed jobs (more than X) since x time ago
194 SELECT count(1) AS nb
195 FROM Job $c_filter $g_filter
197 WHERE JobStatus IN ('E','e','f','A')
199 AND JobTDate > $since
203 $res = $bweb->dbh_selectrow_hashref($query);
207 push @msg, "$nb jobs are in error";
209 } elsif ($nb >= $warn) {
210 push @msg, "$nb jobs are in error";
211 $ret = ($ret>1)?$ret:1;
216 ################################################################
217 # check storage status command
219 foreach my $st (@storage) {
221 my $out = $b->send_cmd("status storage=\"$st\"");
222 if (!$out || $out !~ /Attr spooling|JobId/) {
223 push @msg, "timeout ($timeout s) or bad response on status storage $st";
228 ################################################################
229 # check for Scratch volume
233 SELECT MediaType AS mediatype, count(MediaId) AS nb
234 FROM Media JOIN Pool USING (PoolId)
235 WHERE Pool.Name = 'Scratch'
236 AND Media.MediaType LIKE '$mediatype'
241 $res = $bweb->dbh_selectall_hashref($query, 'mediatype');
242 if ($res && keys %$res) {
243 foreach my $k (keys %$res) {
244 if ($res->{$k}->{nb} < $nb_scratch) {
245 push @msg, "no more scratch for $k ($res->{$k}->{nb})";
249 } else { # query doesn't report anything...
250 push @msg, "no more scratch for $mediatype";
255 ################################################################
259 print "OK - All checks ok\n";
260 } elsif ($ret == 1) {
261 print "WARNING - ", join(", ", @msg), "\n";
263 print "CRITICAL - ", join(", ", @msg), "\n";