diff options
Diffstat (limited to 'contrib/checkciscotemp.pl')
-rw-r--r-- | contrib/checkciscotemp.pl | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/contrib/checkciscotemp.pl b/contrib/checkciscotemp.pl new file mode 100644 index 00000000..a702a89e --- /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 | |||
33 | use Net::SNMP; | ||
34 | use Getopt::Long; | ||
35 | &Getopt::Long::config('auto_abbrev'); | ||
36 | |||
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; | ||
48 | |||
49 | my %STATUSCODE = ( 'UNKNOWN' => '-1', | ||
50 | 'OK' => '0', | ||
51 | 'WARNING' => '1', | ||
52 | 'CRITICAL' => '2'); | ||
53 | |||
54 | my $state = "UNKNOWN"; | ||
55 | |||
56 | |||
57 | $SIG{'ALRM'} = sub { | ||
58 | print "ERROR: No snmp response from $hostname (sigALRM)\n"; | ||
59 | exit($STATUSCODE{"UNKNOWN"}); | ||
60 | }; | ||
61 | |||
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); | ||
74 | |||
75 | if($status == 0) { | ||
76 | &show_help; | ||
77 | } | ||
78 | |||
79 | unless (defined($hostname)) { | ||
80 | $hostname = shift || &show_help; | ||
81 | } | ||
82 | |||
83 | if (defined($critical_vals)) { | ||
84 | die "Cannot Parse Critical Thresholds\n" | ||
85 | unless (split(/:/,$critical_vals)>=2); | ||
86 | ($inlet_thresh,$outlet_thresh) = @_ | ||
87 | } | ||
88 | die unless(defined($inlet_thresh) && defined($outlet_thresh)); | ||
89 | |||
90 | if (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 | |||
99 | alarm($timeout); | ||
100 | |||
101 | $in_temp = &SNMPGET($INTAKE_TEMP); | ||
102 | $out_temp = &SNMPGET($OUTLET_TEMP); | ||
103 | |||
104 | if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) { | ||
105 | $state = "OK"; | ||
106 | } | ||
107 | elsif (($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 | } | ||
115 | elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) { | ||
116 | $state = "CRITICAL"; | ||
117 | } | ||
118 | else { | ||
119 | $state = "WARNING"; | ||
120 | } | ||
121 | |||
122 | print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n"; | ||
123 | exit($STATUSCODE{$state}); | ||
124 | |||
125 | sub 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 | |||
144 | sub 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 | |||