3 # queries the event log of an MSA2000 storage array using NSMP and reports
4 # warning and error states.
6 # once an issue has been acknowledged/fixed, change the --startindex option
9 # Copyright (C) 2009 Peter Palfrader <peter@palfrader.org>
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:
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
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.
37 my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--timeout=<timeout>] [--startindex=<idx>] <host> <community>\n";
39 Getopt::Long::config('bundling');
41 '--help' => \$params->{'help'},
42 '--timeout=i' => \$params->{'timeout'},
43 '--startindex=i' => \$params->{'startindex'},
47 if ($params->{'help'}) {
51 die ($usage) unless (scalar @ARGV == 2);
54 my $community = shift;
56 my $timeout = $params->{'timeout'} || 15;
58 my $startindex = $params->{'startindex'} || undef;
64 'Killed partner controller; reason=5 (Other not present)',
80 die "SNMP error: ", $session->error(), "\n";
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',
91 ($session, $error) = Net::SNMP->session(
93 -community => $community,
94 -version => 'snmpv2c',
97 die "SNMP error: $error\n" unless defined ($session);
99 my $octs = $session->max_msg_size(65535);
100 snmp_error() unless defined $octs;
102 #my $debug = $session->debug(2|4|8|16|32);
103 #snmp_error() unless defined $debug;
105 my $r = $session->get_entries(
106 -columns => [ keys %OID ],
107 -maxrepetitions => $maxrep,
108 -startindex => $startindex,
110 snmp_error() unless defined $r;
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};
122 my %num = ('warn' => 0, 'error' => 0, 'info' => 0, 'error-ignored' => 0, 'warn-ignored' => 0);
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};
129 my $msg = $data{'message'}->{$idx};
130 if (grep {$_ eq $msg} @ignores) {
131 $num{$sev.'-ignored'}++;
135 $exit = $sevint > $exit ? $sevint : $exit;
137 $res .= sprintf "%s: [%s]%s %s\n",
140 $data{'timestamp'}->{$idx},
149 printf "Event Log: %d info, %d warnings%s, %d errors%s\n",
152 ($num{'warn-ignored'} ? " (+$num{'warn-ignored'} ignored)" : ""),
154 ($num{'error-ignored'} ? " (+$num{'error-ignored'} ignored)" : "");