3
# "mon" monitor to detect chassis-related failures for Foundry switches
5
# arguments are "[-c community] host [host...]"
10
# $Id: foundry-chassis.monitor 1.6 Sat, 30 Jun 2001 14:44:29 -0400 trockij $
12
# Copyright (C) 2000, Jim Trocki
14
# This program is free software; you can redistribute it and/or modify
15
# it under the terms of the GNU General Public License as published by
16
# the Free Software Foundation; either version 2 of the License, or
17
# (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
$ENV{"MIBS"} = "FOUNDRY-SN-AGENT-MIB:RFC1213-MIB";
39
getopts ('c:', \%opt);
41
my $COMM = $opt{"c"} || "public";
49
foreach my $host (@ARGV)
51
my %status = get_status ($host, $COMM);
53
if ($status{"error"} ne "")
55
push (@failures, $host);
56
$detail .= "could not retrieve status from $host: $status{error}\n\n";
60
elsif ($status{"failure"})
62
push (@failures, $host);
63
$detail .= $status{"failure_summary"};
66
$fans{$host} = $status{"fan_table"};
67
$PSUs{$host} = $status{"psu_table"};
68
$modules{$host} = $status{"mod_table"};
73
print join (" ", sort @failures), "\n\n$detail\n";
82
-------------------------------------------------------------------------------
84
host index opstatus description
85
-------------------------------------------------------------------------------
88
foreach my $host (sort keys %fans)
90
foreach my $r (@{$fans{$host}})
92
printf ("%-10s %-7s %-22s %s\n",
95
$r->{"snChasFanOperStatus"},
96
$r->{"snChasFanDescription"});
104
-------------------------------------------------------------------------------
106
host index opstatus description
107
-------------------------------------------------------------------------------
110
foreach my $host (sort keys %PSUs)
112
foreach my $r (@{$PSUs{$host}})
114
printf ("%-10s %-7s %-22s %s\n",
117
$r->{"snChasPwrSupplyOperStatus"},
118
$r->{"snChasPwrSupplyDescription"});
126
-------------------------------------------------------------------------------
128
host index opstatus description
129
-------------------------------------------------------------------------------
132
foreach my $host (sort keys %modules)
134
foreach my $r (@{$modules{$host}})
136
printf ("%-10s %-7s %-22s %s\n",
139
$r->{"snAgentBrdModuleStatus"},
140
$r->{"snAgentBrdMainBrdDescription"});
157
# params: (hostname, community)
161
# "error" => "error name, empty string means no error",
162
# "failure" => "nonzero if a failure",
170
my ($host, $comm) = @_;
173
if (!defined ($s = new SNMP::Session (
175
"Community" => $comm,
179
return ("error" => "cannot create session");
183
my $failure_detected = 0;
184
my $failure_summary = "";
190
# is this really a foundry box?
192
my $sys_oid = $s->get (["sysObjectID", 0]);
194
return ("error" => $s->{"ErrorStr"}) if ($s->{"ErrorStr"} ne "");
196
return ("error" => "not Foundry device")
197
if ($sys_oid !~ /^\.1\.3\.6\.1\.4\.1\.1991\./);
200
# this is indeed foundry equipment, so
201
# get power supply table
203
($error, $psu_table) = get_table ($s,
204
["snChasPwrSupplyDescription"],
205
["snChasPwrSupplyOperStatus"],
208
return ("error" => $error) if ($error ne "");
210
foreach my $r (@{$psu_table})
212
next if ($r->{"snChasPwrSupplyOperStatus"} eq "normal");
213
$failure_detected = 1;
214
$failure_summary .= "$host PSU failure: $r->{snChasPwrSupplyDescription}\n";
221
($error, $fan_table) = get_table ($s,
222
["snChasFanDescription"],
223
["snChasFanOperStatus"],
226
return ("error" => $error) if ($error ne "");
228
foreach my $r (@{$fan_table})
230
next if ($r->{"snChasFanOperStatus"} eq "normal");
231
$failure_detected = 1;
232
$failure_summary .= "$host fan failure: $r->{snChasFanDescription}\n";
239
($error, $mod_table) = get_table ($s,
240
["snAgentBrdMainBrdDescription"],
241
["snAgentBrdModuleStatus"],
244
return ("error" => $error) if ($error ne "");
246
foreach my $r (@{$mod_table})
248
next if ($r->{"snAgentBrdModuleStatus"} eq "moduleRunning");
249
$failure_detected = 1;
250
$failure_summary .= "$host module failure: $r->{snAgentBrdMainBrdDescription}\n";
256
"failure" => $failure_detected,
257
"failure_summary" => $failure_summary,
258
"psu_table" => $psu_table,
259
"fan_table" => $fan_table,
260
"mod_table" => $mod_table,
270
my $tblid = $tbl[0]->[0];
273
my $row = new SNMP::VarList (@tbl);
275
return ("MIB problem") if (!defined $row);
277
while (defined ($s->getnext ($row)))
279
last if ($s->{"ErrorStr"} ne "");
281
my $r = $row->[0]->[0];
283
last if ($r ne $tblid);
285
foreach my $col (@{$row})
287
$table->[$i]->{"iid"} = $col->[1];
288
$table->[$i]->{$col->[0]} = $col->[2];
294
return ($s->{"ErrorStr"}) if ($s->{"ErrorStr"} ne "");
307
my $r = new SNMP::VarList ( @vars );
309
return ("MIB problem") if (!defined $r);
311
return ($s->ErrorStr) if (!defined ($s->get ($r)));
315
foreach my $element (@{$r})
317
$v->{$element->[0]} = $element->[2];