]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/nagios.txt
Implement Device Spool directory and sizes
[bacula/bacula] / bacula / examples / nagios.txt
1 From bacula-users-admin@lists.sourceforge.net Wed Mar  3 22:08:24 2004
2 Return-Path: <bacula-users-admin@lists.sourceforge.net>
3 Received: from sc8-sf-list2.sourceforge.net (lists.sourceforge.net
4         [66.35.250.206]) by matou.sibbald.com (8.12.10/8.12.10) with ESMTP id
5         i23L8Nb7003158 for <kern@sibbald.com>; Wed, 3 Mar 2004 22:08:24 +0100
6 Received: from localhost ([127.0.0.1] helo=projects.sourceforge.net) by
7         sc8-sf-list2.sourceforge.net with esmtp (Exim 4.30) id 1Ayddz-0005F7-EZ;
8         Wed, 03 Mar 2004 13:11:07 -0800
9 Received: from sc8-sf-mx1-b.sourceforge.net ([10.3.1.11]
10         helo=sc8-sf-mx1.sourceforge.net) by sc8-sf-list2.sourceforge.net with esmtp
11         (Exim 4.30) id 1AyddU-00058Y-25 for bacula-users@lists.sourceforge.net;
12         Wed, 03 Mar 2004 13:10:36 -0800
13 Received: from zola.netways.de ([213.95.25.82]
14         helo=net-sql2.int.netways.de) by sc8-sf-mx1.sourceforge.net with esmtp
15         (Exim 4.30) id 1AydXy-0008Im-KW for bacula-users@lists.sourceforge.net;
16         Wed, 03 Mar 2004 13:04:54 -0800
17 Content-class: urn:content-classes:message
18 MIME-Version: 1.0
19 Content-Type: text/plain; charset="iso-8859-1"
20 Subject: RE: [Bacula-users] monitoring bacula with Nagios
21 X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0
22 Message-ID: <2F6750F2110CAD41BE0BC33BB428B568FB9F@net-sql2.int.netways.de>
23 X-MS-Has-Attach: 
24 X-MS-TNEF-Correlator: 
25 Thread-Topic: [Bacula-users] monitoring bacula with Nagios
26 Thread-Index: AcPflloclgso3C9CREycI4VSOMnJBghyXnSwAACsf0A=
27 From: "Julian Hein" <jhein@netways.de>
28 To: <bacula-users@lists.sourceforge.net>
29 X-Spam-Score: 0.0 (/)
30 X-Spam-Report: Spam Filtering performed by sourceforge.net. See
31         http://spamassassin.org/tag/ for more details. Report problems to
32         http://sf.net/tracker/?func=add&group_id=1&atid=200001
33 Sender: bacula-users-admin@lists.sourceforge.net
34 Errors-To: bacula-users-admin@lists.sourceforge.net
35 X-BeenThere: bacula-users@lists.sourceforge.net
36 X-Mailman-Version: 2.0.9-sf.net
37 Precedence: bulk
38 List-Unsubscribe:
39         <https://lists.sourceforge.net/lists/listinfo/bacula-users>,
40         <mailto:bacula-users-request@lists.sourceforge.net?subject=unsubscribe>
41 List-Id: Bacula user's email list for support and discussions
42         <bacula-users.lists.sourceforge.net>
43 List-Post: <mailto:bacula-users@lists.sourceforge.net>
44 List-Help: <mailto:bacula-users-request@lists.sourceforge.net?subject=help>
45 List-Subscribe:
46         <https://lists.sourceforge.net/lists/listinfo/bacula-users>,
47         <mailto:bacula-users-request@lists.sourceforge.net?subject=subscribe>
48 List-Archive:
49         <http://sourceforge.net/mailarchive/forum.php?forum=bacula-users>
50 Date: Wed, 3 Mar 2004 22:04:49 +0100
51 X-MIME-Autoconverted: from quoted-printable to 8bit by matou.sibbald.com id
52         i23L8Nb7003158
53 Content-Transfer-Encoding: 8bit
54
55 Hi,
56
57 > Anyway: I would really like to write such a check_bacula 
58 > plugin. I just 
59 > don't know what I need to implement to achive a successful 
60 > authentication. And maybe to get some infos out. Like current 
61 > number of 
62 > jobs, runtime or so.
63
64 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:
65
66
67 1. Check if the fd is running
68 =============================
69
70 Services:
71 ---------
72
73 # bacula-fd linux
74 check_command                   check_spezial_procs_by_ssh!2:!1:!bacula-fd
75
76 # bacula-sd
77 check_command                   check_spezial_procs_by_ssh!2:!1:!bacula-sd
78
79 # bacula-dir
80 check_command                   check_spezial_procs_by_ssh!2:!1:!bacula-dir
81
82 # bacula-fd windows
83 check_command                   check_nt_service!bacula
84
85 Commands:
86 ---------
87
88 # check for services by name with ssh
89 define command {
90   command_name  check_spezial_procs_by_ssh
91   command_line  $USER1$/check_by_ssh -t 60 -H $HOSTADDRESS$ -C "/opt/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -C $ARG3$"
92 }
93
94 # check for the bacula-fd on windows with nsclient
95 define command {
96   command_name  check_nt_service
97   command_line  $USER1$/check_nt -H $HOSTADDRESS$ -p portno. -s password -v SERVICESTATE -l $ARG1$
98 }
99
100 2. Is there a successful job in the database
101 ============================================
102
103 Services:
104 ---------
105
106 # bacula jobs
107 check_command    check_bacula_by_ssh!27!1!1
108
109 Commands:
110 ---------
111 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$:
112
113 define command {
114   command_name    check_bacula_by_ssh
115   command_line    $USER1$/check_by_ssh  -t 60 -H my.backup.server -C "/opt/nagios/libexec/check_bacula.pl -H $ARG1$ -w $
116 ARG2$ -c $ARG3$ -j $HOSTNAME$"
117 }
118
119 check_bacula.pl:
120 ----------------
121
122 #!/usr/bin/perl -w
123 use strict;
124 use POSIX;
125 use File::Basename;
126 use DBI;
127 use Getopt::Long;
128 use vars qw(
129        $opt_help
130            $opt_job
131            $opt_critical
132            $opt_warning
133            $opt_hours
134            $opt_usage
135            $opt_version
136            $out
137            $sql
138            $date_start
139            $date_stop
140            $state
141            $count
142            );
143            
144 sub print_help();
145 sub print_usage();
146 sub get_now();
147 sub get_date;
148
149 my $progname = basename($0);
150
151 my %ERRORS = (  'UNKNOWN'       =>      '-1',
152                 'OK'            =>      '0',
153                 'WARNING'       =>      '1',
154                 'CRITICAL'      =>      '2');
155
156 Getopt::Long::Configure('bundling');
157 GetOptions
158         (
159         "c=s"   =>      \$opt_critical, "critical=s"    =>      \$opt_critical,
160         "w=s"   =>      \$opt_warning,  "warning=s"     =>      \$opt_warning,
161         "H=s"   =>      \$opt_hours,    "hours=s"       =>      \$opt_hours,
162         "j=s"   =>      \$opt_job,      "job=s"         =>      \$opt_job,
163         "h"     =>      \$opt_help,     "help"          =>      \$opt_help,
164                                         "usage"         =>      \$opt_usage,
165         "V"     =>      \$opt_version,  "version"       =>      \$opt_version
166         ) || die "Try '$progname --help' for more information.\n";
167
168 sub print_help() {
169 print "\n";
170 print "PRINT HELP...\n";
171 print "\n";
172 }
173
174 sub print_usage() {
175  print "PRINT USAGE...\n";
176  print "\n";
177 }
178
179 sub get_now() {
180  my $now  = defined $_[0] ? $_[0] : time;
181  my $out = strftime("%Y-%m-%d %X", localtime($now));
182  return($out);
183 }
184
185 sub get_date {
186  my $day = shift;
187  my $now  = defined $_[0] ? $_[0] : time;
188  my $new = $now - ((60*60*1) * $day);
189  my $out = strftime("%Y-%m-%d %X", localtime($new));
190  return ($out);
191 }
192
193 if ($opt_help) {
194  print_help();
195  exit $ERRORS{'UNKNOWN'};
196 }
197
198 if ($opt_usage) {
199  print_usage();
200  exit $ERRORS{'UNKNOWN'};
201 }
202
203 if ($opt_version) {
204  print "$progname 0.0.1\n";
205  exit $ERRORS{'UNKNOWN'};
206 }
207
208
209 if ($opt_job && $opt_warning && $opt_critical) {
210  my $dsn = "DBI:mysql:database=bacula;host=localhost";
211  my $dbh = DBI->connect( $dsn,'root','' ) or die "Error connecting to: '$dsn': $DBI::errstr\n";
212  
213  if ($opt_hours)
214  {
215   $date_stop = get_date($opt_hours);
216  }
217   else
218   {
219    $date_stop = '1970-01-01 01:00:00';
220   }
221  
222  $date_start = get_now();
223  
224  $sql = "SELECT count(*) as 'count' from Job where (Name='$opt_job') and (JobStatus='T') and (EndTime <> '') and ((EndTime <= '$date_start') and (EndTime >= '$date_stop'));";
225
226  my $sth = $dbh->prepare($sql) or die "Error preparing statemment",$dbh->errstr;
227  $sth->execute;
228  
229  while (my @row = $sth->fetchrow_array()) {
230   ($count) = @row;
231  }
232 $state = 'OK';
233 if ($count<$opt_warning) { $state='WARNING' }
234 if ($count<$opt_critical) { $state='CRITICAL' }
235
236 print "Bacula $state: Found $count successfull jobs\n";
237 exit $ERRORS{$state};
238  $dbh->disconnect();
239 }
240  else {
241   print_usage();
242  }
243
244 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.
245
246 cu,
247 Julian
248
249 -- 
250 Julian Hein                   NETWAYS GmbH
251 Managing Director             Deutschherrnstr. 47a
252 Fon.0911/92885-0              D-90429 Nürnberg
253 Fax.0911/92885-31                                        
254 jhein@netways.de              www.netways.de     
255
256
257
258
259 -------------------------------------------------------
260 This SF.Net email is sponsored by: IBM Linux Tutorials
261 Free Linux tutorial presented by Daniel Robbins, President and CEO of
262 GenToo technologies. Learn everything from fundamentals to system
263 administration.http://ads.osdn.com/?ad_id\1470&alloc_id638&opÌk
264 _______________________________________________
265 Bacula-users mailing list
266 Bacula-users@lists.sourceforge.net
267 https://lists.sourceforge.net/lists/listinfo/bacula-users