-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_extreme_fans.pl
executable file
·129 lines (111 loc) · 3.35 KB
/
check_extreme_fans.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl -w
#
# Copyright 2009-2017 Martin Scharm
#
# This file is part of bf-monitoring.
# <https://binfalse.de/software/nagios/>
# <https://github.com/binfalse/monitoring>
#
# bf-monitoring is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# bf-monitoring is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# bf-monitoring If not, see <http://www.gnu.org/licenses/>.
#
#################################################
#
# Monitor FANS of an extreme networks device
# written by Martin Scharm
# see http://binfalse.de
#
#################################################
use strict;
use Net::SNMP;
use Getopt::Long;
use lib "/usr/lib/nagios/plugins/";
use utils qw($TIMEOUT %ERRORS);
my $FANTABLE = '1.3.6.1.4.1.1916.1.1.1.9.1';
my $FAN_DEV = '1';
my $FAN_STATE = '2';
my $FAN_SPEED = '4';
my $returnvalue = $ERRORS{"OK"};
my $returnstring = "";
my $returnsupp = "";
my $switch = undef;
my $community = undef;
my $help = undef;
Getopt::Long::Configure ("bundling");
GetOptions(
'h' => \$help,
'help' => \$help,
's:s' => \$switch,
'switch:s' => \$switch,
'C:s' => \$community,
'community:s' => \$community,
'T:s' => \$TIMEOUT,
'timeout:s' => \$TIMEOUT
);
sub print_usage
{
print "Usage: $0 -s <SWITCH> -C <COMMUNITY-STRING> [-T <TIMEOUT>]\n\n";
print " <SWITCH> the switch's hostname or ip address\n";
print " <COMMUNITY-STRING> the community string as configured on the switch\n";
print " <TIMEOUT> max time to wait for an answer, defaults to ".$TIMEOUT."\n"
}
# CHECKS
if ( defined($help) )
{
print_usage();
exit $ERRORS{"UNKNOWN"};
}
if ( !defined($switch) )
{
print "Need Switch-Address!\n";
print_usage();
exit $ERRORS{"UNKNOWN"};
}
if ( !defined($community) )
{
print "Need Community-String!\n";
print_usage();
exit $ERRORS{"UNKNOWN"};
}
my ($session, $error) = Net::SNMP->session( -hostname => $switch, -version => 2, -community => $community, -timeout => $TIMEOUT);
if (!defined($session)) {
printf("ERROR opening session: %s.\n", $error);
exit $ERRORS{"CRITICAL"};
}
my $fan_table = $session->get_table(-baseoid => $FANTABLE);
if (!defined($fan_table))
{
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"CRITICAL"};
}
# building the hash with information on all the fans
my %fans = ();
foreach my $k (keys %$fan_table)
{
my ($type,$id) = ((split(/\./, $k)) [-2,-1]);
$fans{$id}{$type} = $$fan_table{$k};
}
# evaluating the fans
my $ok = 0;
my $nonok = 0;
foreach my $k (sort keys %fans)
{
$returnsupp .= $fans{$k}{$FAN_DEV} . ": " . (($fans{$k}{$FAN_STATE} == 1) ? "OK" : "FAILED") . ($fans{$k}{$FAN_SPEED} ? " (" . $fans{$k}{$FAN_SPEED} . "RPM)" : "") . "; ";
$ok++ if $fans{$k}{2} == 1;
$nonok++ if $fans{$k}{2} != 1;
}
# generating the output
print "detected " . ($ok + $nonok) . " fans: " . $nonok . " are bad.";
print "|" . $returnsupp;
exit $ERRORS{"OK"} unless $nonok > 0;
exit $ERRORS{"CRITICAL"};