/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_tivoli
ViewVC logotype

Annotation of /trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_tivoli

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2699 - (hide annotations) (download)
Thu Apr 17 13:53:36 2014 UTC (8 years, 1 month ago) by dennisvd
File size: 3214 byte(s)
Add check_tivoli, for IBM Storage Manager backups

1 dennisvd 2699 #!/usr/bin/perl -w
2     #
3     # Copyright (c) Stichting FOM 2014
4     #
5     # Licensed under the Apache License, Version 2.0 (the "License");
6     # you may not use this file except in compliance with the License.
7     # You may obtain a copy of the License at
8     #
9     # http://www.apache.org/licenses/LICENSE-2.0
10     #
11     # Unless required by applicable law or agreed to in writing, software
12     # distributed under the License is distributed on an "AS IS" BASIS,
13     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14     # See the License for the specific language governing permissions and
15     # limitations under the License.
16    
17     # This Nagios check finds out if IBM Tivoli Storage Manager backups
18     # are alive and active, by perusing the logfile for recent successful
19     # backups. If the latest successful run is more than a day old, a warning
20     # is issued. More than three days is critical.
21    
22     use strict;
23     use Getopt::Long;
24     use Time::Local;
25     use POSIX qw{strftime};
26    
27     my $verbose=0;
28     my $debug;
29     # the logfile to parse
30     my $log = "/var/log/dsmsched.log";
31    
32     my $TIMEOUT = 10;
33    
34     GetOptions("log:s" => \$log,
35     "debug" => \$debug,
36     "verbose" => \$verbose );
37    
38    
39     my %ERRORS=(OK=>0,
40     WARNING=>1,
41     CRITICAL=>2,
42     UNKNOWN=>3,
43     DEPENDENT=>4);
44    
45     my $message = "unk";
46     my $result = $ERRORS{"UNKNOWN"};
47    
48     # Just in case of problems, let's not hang Nagios
49     $SIG{'ALRM'} = sub {
50     print ("ERROR: No timely response (alarm timeout)\n");
51     exit $ERRORS{"UNKNOWN"};
52     };
53    
54     alarm($TIMEOUT);
55    
56    
57     # we're looking for "04/16/14 21:57:03 Scheduled event 'DAILY_NIKHEF' completed successfully."
58     # timestamp in the file is local time.
59    
60     # find the last such entry in /var/log/dsmsched.log
61     my $loghandle;
62     if ( ! open $loghandle, "<$log" ) {
63     $message = "ERROR: cannot open $log";
64     $result = $ERRORS{"CRITICAL"};
65     print "$message\n";
66     exit $result;
67     }
68    
69     my $lastentry;
70    
71     while (<$loghandle>) {
72     next unless m{(\d\d)/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d) Scheduled event .* completed successfully\.};
73     # just like localtime(), months range 0..11
74     my ($month, $day, $year, $hours, $minutes, $seconds) = ($1-1, $2, $3, $4, $5, $6);
75     $lastentry = timelocal($seconds, $minutes, $hours, $day, $month, $year);
76     }
77    
78     close $loghandle;
79    
80     if (!defined $lastentry) {
81     $message = "ERROR: no successful events in $log";
82     $result = $ERRORS{"CRITICAL"};
83     print "$message\n";
84     exit $result;
85     }
86    
87     # compare timestamps; if last entry is too long in the past, raise a
88     # warning or an error
89    
90     my $currenttime = time;
91     print "$lastentry\n" if $debug;
92     print "$currenttime\n" if $debug;
93     # strftime is funky; years are counted from 1900, day of month from 1 and
94     # everything else from 0.
95     my $lasttime = strftime("%F %T", $lastentry, 0, 0, 1, 0, 70);
96    
97     if ($currenttime - $lastentry > 24 * 60 * 60) {
98     $message = "WARNING: last successful event is more than a day old [$lasttime]";
99     $result = $ERRORS{"WARNING"};
100     } else {
101     $message = "OK [$lasttime]";
102     $result = $ERRORS{"OK"};
103     }
104    
105     # more than three days is really critical
106     if ($currenttime - $lastentry > 3 * 24 * 60 * 60) {
107     $message = "ERROR: last successful event is more than three days old [$lasttime]";
108     $result = $ERRORS{"CRITICAL"};
109     }
110    
111     alarm(0);
112    
113     print "$message\n";
114     exit $result;

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28