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,2012 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>] [--verbose] <host> <community>\n";
39 $params->{'verbosity'} = 0;
40 Getopt::Long::config('bundling');
42 '--help' => \$params->{'help'},
43 '--timeout=i' => \$params->{'timeout'},
44 '--startindex=i' => \$params->{'startindex'},
45 '-verbose' => \$params->{'verbosity'},
49 if ($params->{'help'}) {
53 die ($usage) unless (scalar @ARGV == 2);
56 my $community = shift;
58 my $timeout = $params->{'timeout'} || 15;
60 my $startindex = $params->{'startindex'} || undef;
66 'Killed partner controller; reason=5 (Other not present)',
82 die "SNMP error: ", $session->error(), "\n";
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',
93 ($session, $error) = Net::SNMP->session(
95 -community => $community,
96 -version => 'snmpv2c',
99 die "SNMP error: $error\n" unless defined ($session);
101 my $octs = $session->max_msg_size(65535);
102 snmp_error() unless defined $octs;
104 #my $debug = $session->debug(2|4|8|16|32);
105 #snmp_error() unless defined $debug;
107 my $r = $session->get_entries(
108 -columns => [ keys %OID ],
109 -maxrepetitions => $maxrep,
110 -startindex => $startindex,
112 snmp_error() unless defined $r;
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};
124 my %num = ('warn' => 0, 'error' => 0, 'info' => 0, 'error-ignored' => 0, 'warn-ignored' => 0);
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'}++;
137 $exit = $sevint > $exit ? $sevint : $exit;
139 $res .= sprintf "%s: [%s]%s %s\n",
142 $data{'timestamp'}->{$idx},
151 printf "Event Log: %d info, %d warnings%s, %d errors%s\n",
154 ($num{'warn-ignored'} ? " (+$num{'warn-ignored'} ignored)" : ""),
156 ($num{'error-ignored'} ? " (+$num{'error-ignored'} ignored)" : "");