~ubuntu-branches/ubuntu/dapper/mon/dapper-security

« back to all changes in this revision

Viewing changes to mon.d/foundry-chassis.monitor

  • Committer: Bazaar Package Importer
  • Author(s): Roderick Schertler
  • Date: 2001-09-15 08:46:38 UTC
  • Revision ID: james.westby@ubuntu.com-20010915084638-cm3jl93lnhp6cdwg
Tags: upstream-0.99.2
ImportĀ upstreamĀ versionĀ 0.99.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# "mon" monitor to detect chassis-related failures for Foundry switches
 
4
#
 
5
# arguments are "[-c community] host [host...]"
 
6
 
7
#
 
8
# Jim Trocki
 
9
#
 
10
# $Id: foundry-chassis.monitor 1.6 Sat, 30 Jun 2001 14:44:29 -0400 trockij $
 
11
#
 
12
#    Copyright (C) 2000, Jim Trocki
 
13
#
 
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.
 
18
#
 
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.
 
23
#
 
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
 
27
#
 
28
use SNMP;
 
29
use Getopt::Std;
 
30
use strict;
 
31
 
 
32
sub get_status;
 
33
sub get_table;
 
34
sub get_vars;
 
35
 
 
36
$ENV{"MIBS"} = "FOUNDRY-SN-AGENT-MIB:RFC1213-MIB";
 
37
 
 
38
my %opt;
 
39
getopts ('c:', \%opt);
 
40
 
 
41
my $COMM = $opt{"c"} || "public";
 
42
 
 
43
my @failures = ();
 
44
my $detail = "";
 
45
my %fans;
 
46
my %PSUs;
 
47
my %modules;
 
48
 
 
49
foreach my $host (@ARGV)
 
50
{
 
51
    my %status = get_status ($host, $COMM);
 
52
 
 
53
    if ($status{"error"} ne "")
 
54
    {
 
55
        push (@failures, $host);
 
56
        $detail .= "could not retrieve status from $host: $status{error}\n\n";
 
57
        next;
 
58
    }
 
59
 
 
60
    elsif ($status{"failure"})
 
61
    {
 
62
        push (@failures, $host);
 
63
        $detail .= $status{"failure_summary"};
 
64
    }
 
65
 
 
66
    $fans{$host} = $status{"fan_table"};
 
67
    $PSUs{$host} = $status{"psu_table"};
 
68
    $modules{$host} = $status{"mod_table"};
 
69
}
 
70
 
 
71
if (@failures != 0)
 
72
{
 
73
    print join (" ", sort @failures), "\n\n$detail\n";
 
74
}
 
75
 
 
76
else
 
77
{
 
78
    print "\n$detail";
 
79
}
 
80
 
 
81
print <<EOF;
 
82
-------------------------------------------------------------------------------
 
83
FANS
 
84
host       index   opstatus               description
 
85
-------------------------------------------------------------------------------
 
86
EOF
 
87
 
 
88
foreach my $host (sort keys %fans)
 
89
{
 
90
    foreach my $r (@{$fans{$host}})
 
91
    {
 
92
        printf ("%-10s %-7s %-22s %s\n",
 
93
                $host,
 
94
                $r->{"iid"},
 
95
                $r->{"snChasFanOperStatus"},
 
96
                $r->{"snChasFanDescription"});
 
97
    }
 
98
 
 
99
    print "\n";
 
100
}
 
101
 
 
102
print <<EOF;
 
103
 
 
104
-------------------------------------------------------------------------------
 
105
POWER SUPPLIES
 
106
host       index   opstatus               description
 
107
-------------------------------------------------------------------------------
 
108
EOF
 
109
 
 
110
foreach my $host (sort keys %PSUs)
 
111
{
 
112
    foreach my $r (@{$PSUs{$host}})
 
113
    {
 
114
        printf ("%-10s %-7s %-22s %s\n",
 
115
                $host,
 
116
                $r->{"iid"},
 
117
                $r->{"snChasPwrSupplyOperStatus"},
 
118
                $r->{"snChasPwrSupplyDescription"});
 
119
    }
 
120
 
 
121
    print "\n";
 
122
}
 
123
 
 
124
print <<EOF;
 
125
 
 
126
-------------------------------------------------------------------------------
 
127
MODULES
 
128
host       index   opstatus               description
 
129
-------------------------------------------------------------------------------
 
130
EOF
 
131
 
 
132
foreach my $host (sort keys %modules)
 
133
{
 
134
    foreach my $r (@{$modules{$host}})
 
135
    {
 
136
        printf ("%-10s %-7s %-22s %s\n",
 
137
                $host,
 
138
                $r->{"iid"},
 
139
                $r->{"snAgentBrdModuleStatus"},
 
140
                $r->{"snAgentBrdMainBrdDescription"});
 
141
    }
 
142
 
 
143
    print "\n";
 
144
}
 
145
 
 
146
 
 
147
if (@failures != 0)
 
148
{
 
149
    exit 1;
 
150
}
 
151
 
 
152
exit 0;
 
153
 
 
154
 
 
155
 
 
156
#
 
157
# params: (hostname, community)
 
158
#
 
159
# returns:
 
160
# (
 
161
#  "error" => "error name, empty string means no error",
 
162
#  "failure" => "nonzero if a failure",
 
163
#  "psu_table" => [],
 
164
#  "fan_table" => [],
 
165
#  "mod_table" => [],
 
166
# )
 
167
#
 
168
sub get_status
 
169
{
 
170
    my ($host, $comm) = @_;
 
171
 
 
172
    my $s;
 
173
    if (!defined ($s = new SNMP::Session (
 
174
        "DestHost" => $host,
 
175
        "Community" => $comm,
 
176
        "UseEnums" => 1,
 
177
        )))
 
178
    {
 
179
        return ("error" => "cannot create session");
 
180
    }
 
181
 
 
182
    my $error;
 
183
    my $failure_detected = 0;
 
184
    my $failure_summary = "";
 
185
    my $psu_table;
 
186
    my $fan_table;
 
187
    my $mod_table;
 
188
 
 
189
    #
 
190
    # is this really a foundry box?
 
191
    #
 
192
    my $sys_oid = $s->get (["sysObjectID", 0]);
 
193
    
 
194
    return ("error" => $s->{"ErrorStr"}) if ($s->{"ErrorStr"} ne "");
 
195
 
 
196
    return ("error" => "not Foundry device")
 
197
        if ($sys_oid !~ /^\.1\.3\.6\.1\.4\.1\.1991\./);
 
198
 
 
199
    #
 
200
    # this is indeed foundry equipment, so
 
201
    # get power supply table
 
202
    #
 
203
    ($error, $psu_table) = get_table ($s,
 
204
        ["snChasPwrSupplyDescription"],
 
205
        ["snChasPwrSupplyOperStatus"],
 
206
    );
 
207
 
 
208
    return ("error" => $error) if ($error ne "");
 
209
 
 
210
    foreach my $r (@{$psu_table})
 
211
    {
 
212
        next if ($r->{"snChasPwrSupplyOperStatus"} eq "normal");
 
213
        $failure_detected = 1;
 
214
        $failure_summary .= "$host PSU failure: $r->{snChasPwrSupplyDescription}\n";
 
215
        last;
 
216
    }
 
217
 
 
218
    #
 
219
    # get fan table
 
220
    #
 
221
    ($error, $fan_table) = get_table ($s,
 
222
        ["snChasFanDescription"],
 
223
        ["snChasFanOperStatus"],
 
224
    );
 
225
 
 
226
    return ("error" => $error) if ($error ne "");
 
227
 
 
228
    foreach my $r (@{$fan_table})
 
229
    {
 
230
        next if ($r->{"snChasFanOperStatus"} eq "normal");
 
231
        $failure_detected = 1;
 
232
        $failure_summary .= "$host fan failure: $r->{snChasFanDescription}\n";
 
233
        last;
 
234
    }
 
235
 
 
236
    #
 
237
    # get module status
 
238
    #
 
239
    ($error, $mod_table) = get_table ($s,
 
240
        ["snAgentBrdMainBrdDescription"],
 
241
        ["snAgentBrdModuleStatus"],
 
242
    );
 
243
 
 
244
    return ("error" => $error) if ($error ne "");
 
245
 
 
246
    foreach my $r (@{$mod_table})
 
247
    {
 
248
        next if ($r->{"snAgentBrdModuleStatus"} eq "moduleRunning");
 
249
        $failure_detected = 1;
 
250
        $failure_summary .= "$host module failure: $r->{snAgentBrdMainBrdDescription}\n";
 
251
        last;
 
252
    }
 
253
 
 
254
    (
 
255
        "error"                 => "",
 
256
        "failure"               => $failure_detected,
 
257
        "failure_summary"       => $failure_summary,
 
258
        "psu_table"             => $psu_table,
 
259
        "fan_table"             => $fan_table,
 
260
        "mod_table"             => $mod_table,
 
261
    );
 
262
}
 
263
 
 
264
 
 
265
sub get_table
 
266
{
 
267
    my ($s, @tbl) = @_;
 
268
 
 
269
    my $table = [];
 
270
    my $tblid = $tbl[0]->[0];
 
271
    my $i = 0;
 
272
 
 
273
    my $row = new SNMP::VarList (@tbl);
 
274
 
 
275
    return ("MIB problem") if (!defined $row);
 
276
 
 
277
    while (defined ($s->getnext ($row)))
 
278
    {
 
279
        last if ($s->{"ErrorStr"} ne "");
 
280
 
 
281
        my $r = $row->[0]->[0];
 
282
 
 
283
        last if ($r ne $tblid);
 
284
 
 
285
        foreach my $col (@{$row})
 
286
        {
 
287
            $table->[$i]->{"iid"} = $col->[1];
 
288
            $table->[$i]->{$col->[0]} = $col->[2];
 
289
        }
 
290
 
 
291
        $i++;
 
292
    }
 
293
 
 
294
    return ($s->{"ErrorStr"}) if ($s->{"ErrorStr"} ne "");
 
295
 
 
296
    (
 
297
        "",
 
298
        $table,
 
299
    );
 
300
}
 
301
 
 
302
 
 
303
sub get_vars
 
304
{
 
305
    my ($s, @vars) = @_;
 
306
 
 
307
    my $r = new SNMP::VarList ( @vars );
 
308
 
 
309
    return ("MIB problem") if (!defined $r);
 
310
 
 
311
    return ($s->ErrorStr) if (!defined ($s->get ($r)));
 
312
 
 
313
    my $v;
 
314
 
 
315
    foreach my $element (@{$r})
 
316
    {
 
317
        $v->{$element->[0]} = $element->[2];
 
318
    }
 
319
 
 
320
    ("", $v);
 
321
}