plugin-cisco_temp: cisco_temp

File cisco_temp, 2.9 kB (added by janl, 6 years ago)
Line 
1 #!/usr/bin/perl -w
2
3 # Copyright 2005 - Bjorn Ruberg <bjorn@linpro.no>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #
20 # This plugin supports Cisco switches that supports the ciscoEnvMonMIB MIB.
21 # For a list of supported Cisco units and images, check the URL
22 # http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&step=2&mibName=CISCO-ENVMON-MIB
23 #
24 # Also see http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a0080094b9e.shtml
25 # for another approach on Cisco 6500/7500 units.
26
27 #%# family=contrib
28 #%# capabilities=
29
30 use strict;
31 use Data::Dumper;
32 use Net::SNMP qw ( snmp_event_loop ticks_to_time );
33
34 use vars qw ( $host $community $config $response );
35
36 ($host = $0) =~ s/^.*\_//
37     or die ("You need to include the hostname to be queried as a part of the plugin filename, prefixed with '_'.\nExample: " . $0 . "_127.0.0.1\n\n");
38
39 # community string is defined in the Munin plugin environment file(s).
40 # e.g.: env.community SecretString
41 $community = $ENV{'community'} or die ("No SNMP community string set");
42
43 if ($ARGV[0]) {
44     if ($ARGV[0] eq "config") {
45         $config = 1;
46     }
47 }
48
49 my ($session, $error) = Net::SNMP->session(
50                                            -hostname  => $host,
51                                            -community => $community
52                                            );
53
54 my $baseoid = "1.3.6.1.4.1.9.9.13.1.3.1"; # Net::SNMP doesn't like the prefixed '.'
55
56 # .2 = definitions
57 # .3 = values
58
59 if ($config) {
60     $baseoid .= ".2";
61 } else {
62     $baseoid .= ".3";
63 }
64
65 # Fetch data
66 if (!defined ($response = $session->get_table ($baseoid))) {
67     printf ("ERROR: %s.\n", $session->error());
68     $session->close();
69     exit 2;
70 } else {
71     if ($config) {
72         print "host_name $host\n";
73         print "graph_args --base 1000\n";
74         print "graph_title Cisco switch temperature\n";
75         print "graph_category System\n";
76         while (my ($key, $value) = each %$response) {
77             $key =~ s/^.*\.//;
78             print "temp${key}.label $value\n";
79             print "temp${key}.type GAUGE\n";
80             if ($value =~ /intake/i) {
81                 # Larger Cisco switches have intake and exhaust sensors.
82                 # e.g. the 6500 series
83                 print "temp${key}.warning 30\n";
84                 print "temp${key}.critical 35\n";
85             } else {
86                 print "temp${key}.warning 35\n";
87                 print "temp${key}.critical 40\n";
88             }
89         }
90     } else {
91         # Business as usual
92         while ( my ($key, $value) = each %$response) {
93             $key =~ s/^.*\.//;
94             print "temp${key}.value $value\n";
95         }
96     }
97 }