summaryrefslogtreecommitdiffstats
path: root/contrib/checkciscotemp.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/checkciscotemp.pl')
-rw-r--r--contrib/checkciscotemp.pl163
1 files changed, 163 insertions, 0 deletions
diff --git a/contrib/checkciscotemp.pl b/contrib/checkciscotemp.pl
new file mode 100644
index 0000000..a702a89
--- /dev/null
+++ b/contrib/checkciscotemp.pl
@@ -0,0 +1,163 @@
1#!/usr/bin/perl -wT
2# check_ciscotemp.pl
3#
4# Copyright (C) 2000 Leland E. Vandervort <leland@mmania.com>
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License
8# as published by the Free Software Foundation; either version 2
9# of the License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty
13# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# you should have received a copy of the GNU General Public License
17# along with this program (or with Nagios); if not, write to the
18# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19# Boston, MA 02111-1307, USA
20####################################
21# Nagios pluging to check inlet and outlet temperatures on
22# Cisco router platforms which support environmental monitoring
23# (7200, 7500, GSR12000...)
24####################################
25# default temperature thresholds are 30C for inlet, 40C outlet.
26# if input or output is less than thresholds, returns OK
27# if equal to (the temps don't change that rapidly) returns WARNING
28# if greater than threshold, returns CRITICAL
29# if undetermined, or cannot access environmental, returns UNKNOWN
30# (in accordance with the plugin coding guidelines)
31####################################
32
33use Net::SNMP;
34use Getopt::Long;
35&Getopt::Long::config('auto_abbrev');
36
37my $status;
38my $response = "";
39my $timeout = 10;
40my $community = "public";
41my $port = 161;
42my $INTAKE_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.1";
43my $OUTLET_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.3";
44my $in_temp;
45my $out_temp;
46my $inlet_thresh = 30;
47my $outlet_thresh = 40;
48
49my %STATUSCODE = ( 'UNKNOWN' => '-1',
50 'OK' => '0',
51 'WARNING' => '1',
52 'CRITICAL' => '2');
53
54my $state = "UNKNOWN";
55
56
57$SIG{'ALRM'} = sub {
58 print "ERROR: No snmp response from $hostname (sigALRM)\n";
59 exit($STATUSCODE{"UNKNOWN"});
60};
61
62Getopt::Long::Configure('bundling');
63$status = GetOptions
64 ("community=s", \$community,
65 "C=s", \$community,
66 "H=s", \$hostname,
67 "hostname=s", \$hostname,
68 "port=i", \$port,
69 "timeout=i", \$timeout,
70 "c=s", \$critical_vals,
71 "w=s", \$warning_vals,
72 "ithresh=i", \$inlet_thresh,
73 "othresh=i", \$outlet_thresh);
74
75if($status == 0) {
76 &show_help;
77}
78
79unless (defined($hostname)) {
80 $hostname = shift || &show_help;
81}
82
83if (defined($critical_vals)) {
84 die "Cannot Parse Critical Thresholds\n"
85 unless (split(/:/,$critical_vals)>=2);
86 ($inlet_thresh,$outlet_thresh) = @_
87}
88die unless(defined($inlet_thresh) && defined($outlet_thresh));
89
90if (defined($warning_vals)) {
91 die "Cannot Parse Critical Thresholds\n"
92 unless (split(/:/,$warning_vals)>=2);
93 ($inlet_warn,$outlet_warn) = @_;
94}else{
95 $inlet_warn=$inlet_thresh;
96 $outlet_warn=$outlet_thresh;
97}
98
99alarm($timeout);
100
101$in_temp = &SNMPGET($INTAKE_TEMP);
102$out_temp = &SNMPGET($OUTLET_TEMP);
103
104if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) {
105 $state = "OK";
106}
107elsif (($in_temp == $inlet_thresh) || ($out_temp == $outlet_thresh)) {
108 if(($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
109 $state = "CRITICAL";
110 }
111 else {
112 $state = "WARNING";
113 }
114}
115elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
116 $state = "CRITICAL";
117}
118else {
119 $state = "WARNING";
120}
121
122print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n";
123exit($STATUSCODE{$state});
124
125sub show_help {
126 printf("\nPerl envmon temperature plugin for Nagios\n");
127 printf("Usage:\n");
128 printf("
129 check_ciscotemp [options] <hostname>
130 Options:
131 -C snmp-community
132 -p snmp-port
133 -i input temperature threshold
134 -o output temperature threshold
135
136");
137 printf("Copyright (C)2000 Leland E. Vandervort\n");
138 printf("check_ciscotemp comes with absolutely NO WARRANTY either implied or explicit\n");
139 printf("This program is licensed under the terms of the\n");
140 printf("GNU General Public License\n(check source code for details)\n\n\n");
141 exit($STATUSCODE{"UNKNOWN"});
142}
143
144sub SNMPGET {
145 $OID = shift;
146 ($session,$error) = Net::SNMP->session(
147 Hostname => $hostname,
148 Community => $community,
149 Port => $port
150 );
151 if(!defined($session)) {
152 printf("$state %s\n", $error);
153 exit($STATUSCODE{$state});
154 }
155 if(!defined($response = $session->get_request($OID))) {
156 printf("$state %s\n", $session->error());
157 $session->close();
158 exit($STATUSCODE{$state});
159 }
160 $session->close();
161 return($response->{$OID});
162}
163