File: snmp__sensors_fsc_temp.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (181 lines) | stat: -rwxr-xr-x 4,982 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!@@PERL@@ -w
#
# Copyright (C) 2004 Dagfinn Ilmari Mannsaaker
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#
# Plugin to fetch temperature data from the ServerView SNMP agent on
# Fujitsu Simens servers
#
# $Log$
# Revision 1.5  2004/11/23 16:59:38  jimmyo
# Include SNMP.pm in the files. We don't want any perl modules in the node for the 1.2 series.
#
# Revision 1.4  2004/11/16 20:08:26  jimmyo
# License cleanups.
#
# Revision 1.3  2004/11/12 20:28:03  ilmari
# No debugging info by default
#
# Revision 1.2  2004/11/12 20:23:57  ilmari
# Rename Munin::Node::SNMP to Munin::Plugin::SNMP
#
# Revision 1.1  2004/10/27 18:58:26  ilmari
# Added SNMP plugins for Fujitsu Siemens ServerView temperature and fan sensors
#
#
#%# family=snmpauto
#%# capabilities=snmpconf

package Munin::Plugin::SNMP;

use Net::SNMP;
@ISA = qw(Net::SNMP);

sub session {
    my $class = shift;
    my $host      = $ENV{host}      || undef;
    my $port      = $ENV{port}      || 161;
    my $community = $ENV{community} || 'public';
    my $version   = $ENV{version}   || undef;

    if ($0 =~ /^(?:.*\/)?snmp_([^_]+)_/) {
	$host = $1;
	if ($host =~ /^([^:]+):(\d+)$/) {
	    $host = $1;
	    $port = $2;
	}
    } elsif (!defined($host)) {
	return unless wantarray; # Scalar or void context
	return (undef, 'Couldn not find monitoring target.'); # Array context
    }

    return $class->SUPER::session(-hostname  => $host,
				  -community => $community,
				  -port      => $port,
				  ($version ? (-version => $version) : ()));
}

sub get_hash {
    my $self = shift;
    my %args = @_;
    my %ret;
    
    my $base = $args{'-baseoid'};
    my $cols = delete $args{'-cols'} or return;

    my $table = $self->get_table(%args)
      or return;

    my $subtabs = join '|', keys %$cols;
    my $re = qr/^\Q$base.\E($subtabs)\.(.*)/;
    for my $key (keys %$table) {
	$key =~ $re;
	next unless defined($1 && $2);
	$ret{$2}{$cols->{$1}} = $table->{$key};
    }
    return \%ret;
}

package main;

use strict;
use Net::SNMP qw(oid_lex_sort);



# The OIDs we're after
my $tempBase = '1.3.6.1.4.1.231.2.10.2.2.5.2.1.1';

# Subtables
my $tempCabinetId          = 1;
my $tempSensorNumber       = 2;
my $tempSensorStatus       = 3;
my $tempSensorPurpose      = 4;
my $tempUpperWarningLevel  = 6;
my $tempUpperCriticalLevel = 8;
my $tempCurrentValue       = 11;
my $tempSensorDesignation  = 13;

# Magic values
my $tempSensorUnknown = 1;
my $tempSensorDisabled = 2;
my $tempSensorUnavailable = 99;

if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
    print "index   $tempBase.\n";
    # Require known, enabled and available sensors
    print "require $tempBase.$tempSensorStatus. ^[3-9]|[1-8][0-9]|9[0-8]\$\n";

    exit 0;
}

my $DEBUG = 0;

my ($session, $error) = Munin::Plugin::SNMP->session();

if ($error) {
    die "# Error: $error\n";
}

my $temps =  $session->get_hash(-baseoid => $tempBase,
				-cols    => { $tempCabinetId          => 'cabinet',
					      $tempSensorNumber       => 'number',
					      $tempSensorStatus       => 'status',
					      $tempSensorPurpose      => 'purpose',
					      $tempUpperWarningLevel  => 'warning',
					      $tempUpperCriticalLevel => 'critical',
					      $tempCurrentValue       => 'value',
					      $tempSensorDesignation  => 'label',
					    },
			       ) or die $session->error();

for my $key (keys %$temps) {
    my $temp = $temps->{$key};
    $temp->{info} = "Cabinet $temp->{cabinet} sensor $temp->{number}";
    # Delete sensors with status unknown, disabled or unavailable
    delete $temps->{$key}
      if $temp->{status} == $tempSensorUnknown ||
	$temp->{status} == $tempSensorDisabled ||
	$temp->{status} == $tempSensorUnavailable;
}

if (defined $ARGV[0] and $ARGV[0] eq 'config') {
    print <<EOM;
graph_title Temperatures
graph_args -l 0
graph_vlabel degrees Celcius
graph_category sensors
EOM
    print 'graph_order ', join(' ', map { get_id($_) } oid_lex_sort keys %$temps), "\n";
    print 'host_name ', $session->hostname(), "\n";
      
    for my $sensor (keys %$temps) {
	my $id = get_id($sensor);
	for my $key (qw(label warning critical info)) {
	    print "$id.$key $temps->{$sensor}->{$key}\n";
	}
	print "$id.type GAUGE\n";
    }
} else {
    print get_id($_), '.value ', $temps->{$_}{value}, "\n"
      for keys %$temps;
}

sub get_id {
    (my $id = shift) =~ tr/\./_/;
    return 'temp'.$id;
}