Add dsa-check-msa-eventlog
[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 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>] <host> <community>\n";
38 my $params;
39 Getopt::Long::config('bundling');
40 if (!GetOptions (
41         '--help'         => \$params->{'help'},
42         '--timeout=i'    => \$params->{'timeout'},
43         '--startindex=i' => \$params->{'startindex'},
44         )) {
45         die ($usage);
46 };
47 if ($params->{'help'}) {
48         print $usage;
49         exit (0);
50 };
51 die ($usage) unless (scalar @ARGV == 2);
52
53 my $host = shift;
54 my $community = shift;
55
56 my $timeout = $params->{'timeout'} || 15;
57 my $maxrep = 10;
58 my $startindex = $params->{'startindex'} || undef;
59
60
61
62
63 my @ignores = (
64         'Killed partner controller; reason=5 (Other not present)',
65 );
66
67 my %snmp_severity = (
68         5 => 'warn',
69         6 => 'error',
70         8 => 'info',
71 );
72 my %severity_int = (
73         'info' => 0,
74         'warn' => 1,
75         'error' => 2,
76 );
77
78 my $session;
79 sub snmp_error() {
80         die "SNMP error: ", $session->error(), "\n";
81 };
82
83 my %OID = (
84         '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',
85         '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',
86         '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',
87 );
88
89
90 my $error;
91 ($session, $error) = Net::SNMP->session(
92         -hostname  => $host,
93         -community => $community,
94         -version   => 'snmpv2c',
95         -timeout   => $timeout
96 );
97 die "SNMP error: $error\n" unless defined ($session);
98
99 my $octs = $session->max_msg_size(65535);
100 snmp_error() unless defined $octs;
101
102 #my $debug = $session->debug(2|4|8|16|32);
103 #snmp_error() unless defined $debug;
104
105 my $r = $session->get_entries(
106         -columns => [ keys %OID ],
107         -maxrepetitions => $maxrep,
108         -startindex => $startindex,
109 );
110 snmp_error() unless defined $r;
111
112 my %data;
113 for my $key (keys %$r) {
114         my ($col, $idx) = $key =~ /(.*)\.([0-9]+)/;
115         my $type = $OID{$col};
116         die ("Unexpected oid $key\n") unless defined $type;
117         $data{$type}{$idx} = $r->{$key};
118 };
119
120 my $exit = 0;
121 my $res = '';
122 my %num = ('warn' => 0, 'error' => 0);
123
124 for my $idx (sort {$a <=> $b} keys %{$data{'severity'}}) {
125         my $sev = $snmp_severity{$data{'severity'}->{$idx}};
126         die("Unexpected severity $data{'severity'}->{$idx}\n") unless $sev;
127         my $sevint = $severity_int{$sev};
128         if ($sevint > 0) {
129                 my $msg = $data{'message'}->{$idx};
130                 next if grep {$_ eq $msg} @ignores;
131
132                 $exit = $sevint > $exit ? $sevint : $exit;
133
134                 $res .= sprintf "%s: [%s]%s %s\n",
135                         $sev,
136                         $idx,
137                         $data{'timestamp'}->{$idx},
138                         $msg;
139
140                 $num{$sev}++;
141         };
142 };
143
144 printf "Event Log: %d warnings, %d errors\n", $num{'warn'}, $num{'error'};
145 print $res;
146 exit $exit;
147
148 # vim:ts=4
149 # vim:sw=4