Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / disk / snmp__hp_temp @ 64089240

Historique | Voir | Annoter | Télécharger (3,39 ko)

1 6427133f Lars Strand
#!/usr/bin/perl -w
2
#
3
# Copyright (C) 2006 Lars Strand
4
#
5
# Munin-plugin to monitor temperature on HP-servers.
6
# Uses SNMP, and needs hpasmd.
7 17f78427 Lars Kruse
#
8 6427133f Lars Strand
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License
10
# as published by the Free Software Foundation; version 2 dated June,
11
# 1991.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
#
22
#
23
# $Log$
24
#
25
#
26
#
27
#%# family=snmpauto
28
#%# capabilities=snmpconf
29
30
use strict;
31
use Net::SNMP;
32
33
my $DEBUG = 0;
34
my $MAXLABEL = 20;
35
36
my $host      = $ENV{host}      || undef;
37
my $port      = $ENV{port}      || 161;
38
my $community = $ENV{community} || "public";
39
40
# Taken from CPQHLTH-MIB.mib
41
my %locations = (
42
		 1 => "other",
43
		 2 => "unknown",
44
		 3 => "system",
45
		 4 => "systemBoard",
46
		 5 => "ioBoard",
47
		 6 => "cpu",
48
		 7 => "memory",
49
		 8 => "storage",
50
		 9 => "removableMedia",
51
		 10 => "powerSupply",
52
		 11 => "ambient",
53
		 12 => "chassis",
54
		 13 => "bridgeCard"
55
		 );
56
57
#my $response;
58
59
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
60
{
61
	print "index  1.3.6.1.4.1.232.6.2.6.8.1.\n";
62
	print "require 1.3.6.1.4.1.232.6.2.6.8.1.4.1.1. [1-4]\n";
63
	exit 0;
64
}
65
66
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_HP_temp$/)
67
{
68
	$host  = $1;
69
	if ($host =~ /^([^:]+):(\d+)$/)
70
	{
71
		$host = $1;
72
		$port = $2;
73
	}
74
}
75
elsif (!defined($host))
76
{
77
	print "# Debug: $0 -- $1\n" if $DEBUG;
78
	die "# Error: couldn't understand what I'm supposed to monitor.";
79
}
80
81
# Sensor locations
82
my $cpqHeTemperatureLocale = "1.3.6.1.4.1.232.6.2.6.8.1.3.1.";
83
84
# Temperatures
85
my $cpqHeTemperatureCelsius = "1.3.6.1.4.1.232.6.2.6.8.1.4.1.";
86
87
# Temperatures thresholds
88
my $cpqHeTemperatureThreshold = "1.3.6.1.4.1.232.6.2.6.8.1.5.1.";
89
90
91
my ($session, $error) = Net::SNMP->session(
92
		-hostname  => $host,
93
		-community => $community,
94
		-port      => $port
95
	);
96
97
if (!defined ($session)) {
98
	die "Croaking: $error";
99
}
100
101
# Fetch the values.
102
my $temp_locales   = $session->get_table($cpqHeTemperatureLocale);
103
104
if (!defined ($temp_locales)) {
105
    die "Croaking: $error";
106
}
107
108
my @i = ();
109
110
if (defined $ARGV[0] and $ARGV[0] eq "config") {
111
    #print "host_name $host\n";
112
    print "graph_title Temperature (in C)\n";
113
    print "graph_category sensors\n";
114
    print "graph_args --upper-limit 100 -l 0\n";
115
    print "graph_vlabel C\n";
116
    print "graph_info This graph shows the temperatures on a HP server.\n";
117
118
    while (my ($oid, $loc_id) = each (%$temp_locales)) {
119
	@i = split(/\./, $oid);
120
	my $t = $session->get_request($cpqHeTemperatureThreshold . $i[-1]);
121
        while (my ($ooid, $threshold) = each(%$t)) {
122
	    print "$locations{$loc_id}$i[-1].label $locations{$loc_id}\n";
123
	    print "$locations{$loc_id}$i[-1].info Temperature sensor on $locations{$loc_id}\n";
124
	    print "$locations{$loc_id}$i[-1].critical $threshold\n";
125
	}
126
    }
127
    exit 0;
128
}
129
130
# Fetch values
131
while (my ($oid, $loc_id) = each (%$temp_locales)) {
132
    @i = split(/\./, $oid);
133
    my $t = $session->get_request($cpqHeTemperatureCelsius . $i[-1]);
134
    while (my ($ooid, $temperature) = each(%$t)) {
135
	print "$locations{$loc_id}$i[-1].value $temperature\n";
136
    }
137
}