]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/nagios/nagios.txt
kes Manual updates.
[bacula/bacula] / bacula / examples / nagios / nagios.txt
1 Subject: RE: [Bacula-users] monitoring bacula with Nagios
2 From: "Julian Hein" <jhein@netways.de>
3 To: <bacula-users@lists.sourceforge.net>
4
5 Hi,
6
7 > Anyway: I would really like to write such a check_bacula 
8 > plugin. I just 
9 > don't know what I need to implement to achive a successful 
10 > authentication. And maybe to get some infos out. Like current 
11 > number of 
12 > jobs, runtime or so.
13
14 We are checking bacula with Nagios in two ways: First we check all servers if the neccessary services are running, like the fd on all bacula clients (windows & linux), directors, sd, etc. And the second check is to look in baculas mysql database if there is a successful job for every host within the last 24 hours:
15
16
17 1. Check if the fd is running
18 =============================
19
20 Services:
21 ---------
22
23 # bacula-fd linux
24 check_command                   check_spezial_procs_by_ssh!2:!1:!bacula-fd
25
26 # bacula-sd
27 check_command                   check_spezial_procs_by_ssh!2:!1:!bacula-sd
28
29 # bacula-dir
30 check_command                   check_spezial_procs_by_ssh!2:!1:!bacula-dir
31
32 # bacula-fd windows
33 check_command                   check_nt_service!bacula
34
35 Commands:
36 ---------
37
38 # check for services by name with ssh
39 define command {
40   command_name  check_spezial_procs_by_ssh
41   command_line  $USER1$/check_by_ssh -t 60 -H $HOSTADDRESS$ -C "/opt/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -C $ARG3$"
42 }
43
44 # check for the bacula-fd on windows with nsclient
45 define command {
46   command_name  check_nt_service
47   command_line  $USER1$/check_nt -H $HOSTADDRESS$ -p portno. -s password -v SERVICESTATE -l $ARG1$
48 }
49
50 2. Is there a successful job in the database
51 ============================================
52
53 Services:
54 ---------
55
56 # bacula jobs
57 check_command    check_bacula_by_ssh!27!1!1
58
59 Commands:
60 ---------
61 The name of our backup jobs have to match the hostname in Nagios. So we can check on the backup server, for a job called $HOSTNAME$:
62
63 define command {
64   command_name    check_bacula_by_ssh
65   command_line    $USER1$/check_by_ssh  -t 60 -H my.backup.server -C "/opt/nagios/libexec/check_bacula.pl -H $ARG1$ -w $
66 ARG2$ -c $ARG3$ -j $HOSTNAME$"
67 }
68
69 check_bacula.pl:
70 ----------------
71
72 #!/usr/bin/perl -w
73 use strict;
74 use POSIX;
75 use File::Basename;
76 use DBI;
77 use Getopt::Long;
78 use vars qw(
79        $opt_help
80            $opt_job
81            $opt_critical
82            $opt_warning
83            $opt_hours
84            $opt_usage
85            $opt_version
86            $out
87            $sql
88            $date_start
89            $date_stop
90            $state
91            $count
92            );
93            
94 sub print_help();
95 sub print_usage();
96 sub get_now();
97 sub get_date;
98
99 my $progname = basename($0);
100
101 my %ERRORS = (  'UNKNOWN'       =>      '-1',
102                 'OK'            =>      '0',
103                 'WARNING'       =>      '1',
104                 'CRITICAL'      =>      '2');
105
106 Getopt::Long::Configure('bundling');
107 GetOptions
108         (
109         "c=s"   =>      \$opt_critical, "critical=s"    =>      \$opt_critical,
110         "w=s"   =>      \$opt_warning,  "warning=s"     =>      \$opt_warning,
111         "H=s"   =>      \$opt_hours,    "hours=s"       =>      \$opt_hours,
112         "j=s"   =>      \$opt_job,      "job=s"         =>      \$opt_job,
113         "h"     =>      \$opt_help,     "help"          =>      \$opt_help,
114                                         "usage"         =>      \$opt_usage,
115         "V"     =>      \$opt_version,  "version"       =>      \$opt_version
116         ) || die "Try '$progname --help' for more information.\n";
117
118 sub print_help() {
119 print "\n";
120 print "PRINT HELP...\n";
121 print "\n";
122 }
123
124 sub print_usage() {
125  print "PRINT USAGE...\n";
126  print "\n";
127 }
128
129 sub get_now() {
130  my $now  = defined $_[0] ? $_[0] : time;
131  my $out = strftime("%Y-%m-%d %X", localtime($now));
132  return($out);
133 }
134
135 sub get_date {
136  my $day = shift;
137  my $now  = defined $_[0] ? $_[0] : time;
138  my $new = $now - ((60*60*1) * $day);
139  my $out = strftime("%Y-%m-%d %X", localtime($new));
140  return ($out);
141 }
142
143 if ($opt_help) {
144  print_help();
145  exit $ERRORS{'UNKNOWN'};
146 }
147
148 if ($opt_usage) {
149  print_usage();
150  exit $ERRORS{'UNKNOWN'};
151 }
152
153 if ($opt_version) {
154  print "$progname 0.0.1\n";
155  exit $ERRORS{'UNKNOWN'};
156 }
157
158
159 if ($opt_job && $opt_warning && $opt_critical) {
160  my $dsn = "DBI:mysql:database=bacula;host=localhost";
161  my $dbh = DBI->connect( $dsn,'root','' ) or die "Error connecting to: '$dsn': $DBI::errstr\n";
162  
163  if ($opt_hours)
164  {
165   $date_stop = get_date($opt_hours);
166  }
167   else
168   {
169    $date_stop = '1970-01-01 01:00:00';
170   }
171  
172  $date_start = get_now();
173  
174  $sql = "SELECT count(*) as 'count' from Job where (Name='$opt_job') and (JobStatus='T') and (EndTime <> '') and ((EndTime <= '$date_start') and (EndTime >= '$date_stop'));";
175
176  my $sth = $dbh->prepare($sql) or die "Error preparing statemment",$dbh->errstr;
177  $sth->execute;
178  
179  while (my @row = $sth->fetchrow_array()) {
180   ($count) = @row;
181  }
182 $state = 'OK';
183 if ($count<$opt_warning) { $state='WARNING' }
184 if ($count<$opt_critical) { $state='CRITICAL' }
185
186 print "Bacula $state: Found $count successfull jobs\n";
187 exit $ERRORS{$state};
188  $dbh->disconnect();
189 }
190  else {
191   print_usage();
192  }
193
194 Well, this script is not really finished, but it works for us. Maybe it is helpful for you. If somebody makes enhancements, I would be happy to recieve a copy.
195
196 cu,
197 Julian
198
199 -- 
200 Julian Hein                   NETWAYS GmbH
201 Managing Director             Deutschherrnstr. 47a
202 Fon.0911/92885-0              D-90429 Nürnberg
203 Fax.0911/92885-31                                        
204 jhein@netways.de              www.netways.de     
205