Git commit notifications via post-receive hook
[monitoring-plugins.git] / contrib / checkciscotemp.pl
blob8fdc4294d1e274751eedf52c29ac4e3214198c9b
1 #!/usr/bin/perl -wT
2 # check_ciscotemp.pl
3 #
4 # Copyright (C) 2000 Leland E. Vandervort <leland@mmania.com>
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.
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.
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 ####################################
33 use Net::SNMP;
34 use Getopt::Long;
35 &Getopt::Long::config('auto_abbrev');
37 my $status;
38 my $response = "";
39 my $timeout = 10;
40 my $community = "public";
41 my $port = 161;
42 my $INTAKE_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.1";
43 my $OUTLET_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.3";
44 my $in_temp;
45 my $out_temp;
46 my $inlet_thresh = 30;
47 my $outlet_thresh = 40;
49 my %STATUSCODE = ( 'UNKNOWN' => '-1',
50 'OK' => '0',
51 'WARNING' => '1',
52 'CRITICAL' => '2');
54 my $state = "UNKNOWN";
57 $SIG{'ALRM'} = sub {
58 print "ERROR: No snmp response from $hostname (sigALRM)\n";
59 exit($STATUSCODE{"UNKNOWN"});
62 Getopt::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);
75 if($status == 0) {
76 &show_help;
79 unless (defined($hostname)) {
80 $hostname = shift || &show_help;
83 if (defined($critical_vals)) {
84 if ($critical_vals =~ m/^([0-9]+)[,:]([0-9]+)$/) {
85 ($inlet_thresh,$outlet_thresh) = ($1, $2);
86 } else {
87 die "Cannot Parse Critical Thresholds\n";
91 if (defined($warning_vals)) {
92 if ($warning_vals =~ m/^([0-9]+)[:,]([0-9]+)$/) {
93 ($inlet_warn,$outlet_warn) = ($1, $2);
94 } else {
95 die "Cannot Parse Warning Thresholds\n";
97 }else{
98 $inlet_warn=$inlet_thresh;
99 $outlet_warn=$outlet_thresh;
102 alarm($timeout);
104 $in_temp = &SNMPGET($INTAKE_TEMP);
105 $out_temp = &SNMPGET($OUTLET_TEMP);
107 if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) {
108 $state = "OK";
110 elsif (($in_temp == $inlet_thresh) || ($out_temp == $outlet_thresh)) {
111 if(($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
112 $state = "CRITICAL";
114 else {
115 $state = "WARNING";
118 elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {
119 $state = "CRITICAL";
121 else {
122 $state = "WARNING";
125 print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n";
126 exit($STATUSCODE{$state});
128 sub show_help {
129 printf("\nPerl envmon temperature plugin for Nagios\n");
130 printf("Usage:\n");
131 printf("
132 check_ciscotemp [options] <hostname>
133 Options:
134 -C snmp-community
135 -p snmp-port
136 -i input temperature threshold
137 -o output temperature threshold
140 printf("Copyright (C)2000 Leland E. Vandervort\n");
141 printf("check_ciscotemp comes with absolutely NO WARRANTY either implied or explicit\n");
142 printf("This program is licensed under the terms of the\n");
143 printf("GNU General Public License\n(check source code for details)\n\n\n");
144 exit($STATUSCODE{"UNKNOWN"});
147 sub SNMPGET {
148 $OID = shift;
149 ($session,$error) = Net::SNMP->session(
150 Hostname => $hostname,
151 Community => $community,
152 Port => $port
154 if(!defined($session)) {
155 printf("$state %s\n", $error);
156 exit($STATUSCODE{$state});
158 if(!defined($response = $session->get_request($OID))) {
159 printf("$state %s\n", $session->error());
160 $session->close();
161 exit($STATUSCODE{$state});
163 $session->close();
164 return($response->{$OID});