retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-msa-eventlog
1 #!/usr/bin/perl
2
3 # queries the event log of an MSA2000 storage array using NSMP and reports
4 # warning and error states.
5 #
6 # once an issue has been acknowledged/fixed, change the --startindex option
7
8
9 # Copyright (C) 2009,2012 Peter Palfrader <peter@palfrader.org>
10 #
11 # Permission is hereby granted, free of charge, to any person obtaining
12 # a copy of this software and associated documentation files (the
13 # "Software"), to deal in the Software without restriction, including
14 # without limitation the rights to use, copy, modify, merge, publish,
15 # distribute, sublicense, and/or sell copies of the Software, and to
16 # permit persons to whom the Software is furnished to do so, subject to
17 # the following conditions:
18 #
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
21 #
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 use strict;
31 use warnings;
32 use English;
33 use Net::SNMP;
34 use Getopt::Long;
35
36
37 my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--timeout=<timeout>] [--startindex=<idx>] [--verbose] <host> <community>\n";
38 my $params;
39 $params->{'verbosity'} = 0;
40 Getopt::Long::config('bundling');
41 if (!GetOptions (
42         '--help'         => \$params->{'help'},
43         '--timeout=i'    => \$params->{'timeout'},
44         '--startindex=i' => \$params->{'startindex'},
45         '-verbose'       => \$params->{'verbosity'},
46         )) {
47         die ($usage);
48 };
49 if ($params->{'help'}) {
50         print $usage;
51         exit (0);
52 };
53 die ($usage) unless (scalar @ARGV == 2);
54
55 my $host = shift;
56 my $community = shift;
57
58 my $timeout = $params->{'timeout'} || 15;
59 my $maxrep = 10;
60 my $startindex = $params->{'startindex'} || undef;
61
62
63
64
65 my @ignores = (
66         'Killed partner controller; reason=5 (Other not present)',
67 );
68
69 my %snmp_severity = (
70         5 => 'warn',
71         6 => 'error',
72         8 => 'info',
73 );
74 my %severity_int = (
75         'info' => 0,
76         'warn' => 1,
77         'error' => 2,
78 );
79
80 my $session;
81 sub snmp_error() {
82         die "SNMP error: ", $session->error(), "\n";
83 };
84
85 my %OID = (
86         '1.3.6.1.3.94.1.11.1.4.32.112.0.192.255.213.236.218.0.0.0.0.0.0.0.0' => 'timestamp',
87         '1.3.6.1.3.94.1.11.1.6.32.112.0.192.255.213.236.218.0.0.0.0.0.0.0.0' => 'severity',
88         '1.3.6.1.3.94.1.11.1.9.32.112.0.192.255.213.236.218.0.0.0.0.0.0.0.0' => 'message',
89 );
90
91
92 my $error;
93 ($session, $error) = Net::SNMP->session(
94         -hostname  => $host,
95         -community => $community,
96         -version   => 'snmpv2c',
97         -timeout   => $timeout
98 );
99 die "SNMP error: $error\n" unless defined ($session);
100
101 my $octs = $session->max_msg_size(65535);
102 snmp_error() unless defined $octs;
103
104 #my $debug = $session->debug(2|4|8|16|32);
105 #snmp_error() unless defined $debug;
106
107 my $r = $session->get_entries(
108         -columns => [ keys %OID ],
109         -maxrepetitions => $maxrep,
110         -startindex => $startindex,
111 );
112 snmp_error() unless defined $r;
113
114 my %data;
115 for my $key (keys %$r) {
116         my ($col, $idx) = $key =~ /(.*)\.([0-9]+)/;
117         my $type = $OID{$col};
118         die ("Unexpected oid $key\n") unless defined $type;
119         $data{$type}{$idx} = $r->{$key};
120 };
121
122 my $exit = 0;
123 my $res = '';
124 my %num = ('warn' => 0, 'error' => 0, 'info' => 0, 'error-ignored' => 0, 'warn-ignored' => 0);
125
126 for my $idx (sort {$a <=> $b} keys %{$data{'severity'}}) {
127         my $sev = $snmp_severity{$data{'severity'}->{$idx}};
128         die("Unexpected severity $data{'severity'}->{$idx}\n") unless $sev;
129         my $sevint = $severity_int{$sev};
130         if ($sevint > -$params->{'verbosity'}) {
131                 my $msg = $data{'message'}->{$idx};
132                 if (grep {$_ eq $msg} @ignores) {
133                         $num{$sev.'-ignored'}++;
134                         next;
135                 };
136
137                 $exit = $sevint > $exit ? $sevint : $exit;
138
139                 $res .= sprintf "%s: [%s]%s %s\n",
140                         $sev,
141                         $idx,
142                         $data{'timestamp'}->{$idx},
143                         $msg;
144
145                 $num{$sev}++;
146         } else {
147                 $num{$sev}++;
148         };
149 };
150
151 printf "Event Log: %d info, %d warnings%s, %d errors%s\n",
152         $num{'info'},
153         $num{'warn'},
154         ($num{'warn-ignored'} ? " (+$num{'warn-ignored'} ignored)" : ""),
155         $num{'error'},
156         ($num{'error-ignored'} ? " (+$num{'error-ignored'} ignored)" : "");
157 print $res;
158 exit $exit;
159
160 # vim:ts=4
161 # vim:sw=4