Projet

Général

Profil

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

root / plugins / router / snmp__cisco_ @ c8c20a46

Historique | Voir | Annoter | Télécharger (7,04 ko)

1
#!/usr/bin/perl -w
2
# -*- perl -*-
3
# vim: ft=perl
4

    
5
=head1 NAME
6

    
7
snmp__cisco_ - Munin plugin to monitor arbitrary SNMP MIBs on Cisco Switches.
8

    
9
This currently only supports the CISCO-ENVMON-MIB (definitions found in
10
ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz).
11

    
12
=head2 EXTENDING THE PLUGIN
13

    
14
This plugin is designed to be extensible, by adding descriptors to the %params
15
hash.
16

    
17
The assumption is that each monitored instance will have at least a Descr and a
18
Value (or a State, as a fallback), and potentially either one Threshold or a
19
range (ThresholdLow:ThresholdHigh).
20

    
21
Each sub-hash in the %params hash must list all those bojects, and the matching
22
OID (or 0 if irrelevant). It should also include the Munin graph details (title,
23
category, info, ...), an optional cdef, and an instancePrefix used when naming
24
the values (by prepending them to the entry OID).
25

    
26
=head1 APPLICABLE SYSTEMS
27

    
28
Cisco Switches with SNMP support; maybe other SNMP devices too, if the %params
29
get extended.
30

    
31
=head1 CONFIGURATION
32

    
33
As a rule SNMP plugins need site specific configuration.  The default
34
configuration (shown here) will only work on insecure sites/devices.
35

    
36
   [snmp_*]
37
        env.version 2
38
        env.community public
39

    
40
In general SNMP is not very secure at all unless you use SNMP version
41
3 which supports authentication and privacy (encryption).  But in any
42
case the community string for your devices should not be "public".
43

    
44
Please see 'perldoc Munin::Plugin::SNMP' for further configuration
45
information
46

    
47
=head1 MAGIC MARKERS
48

    
49
  #%# family=snmpauto
50
  #%# capabilities=snmpconf suggest
51

    
52
=head1 BUGS
53

    
54
EnvMonVoltage hasn't been tested.
55

    
56
snmpconf doesn't actually work, as this wildard plugin targets classe of MIBs,
57
rather than single instances of an object.
58

    
59
=head1 AUTHOR
60

    
61
Copyright (C) 2015 James DeVincentis (snmp__cisco_sbs_cpu)
62
Copyright (C) 2020 Olivier Mehani <shtrom+munin@ssji.net>
63

    
64
=head1 LICENSE
65

    
66
SPDX-License-Identifier: GPL-3.0
67

    
68
=cut
69

    
70
use strict;
71
use Munin::Plugin::SNMP;
72
use Data::Dumper;
73

    
74
my $entPhysicalIndexMib = '1.3.6.1.2.1.47.1.1.1.1.1';
75
my $entPhysicalDescrMib = '1.3.6.1.2.1.47.1.1.1.1.2';
76
my $ciscoEnvMonObjectsMib = '1.3.6.1.4.1.9.9.13.1';
77

    
78
my %params = (
79
	'EnvMonVoltage' => {
80
		'title' => 'Voltages',
81
		'category' => 'sensors',
82
		'vlabel' => 'volts',
83
		'info' => "The table of voltage status maintained by the environmental monitor.",
84
		'cdef' => '1000,*',
85

    
86
		'baseMib' => "$ciscoEnvMonObjectsMib.2.1",
87
		'descrOid' => 2,
88
		'valueOid' => 3,
89
		'thresholdLowOid' => 4,
90
		'thresholdHighOid' => 5,
91
		'thresholdOid' => 0, # n/a
92
		'stateOid' => 6,
93

    
94
		'instancePrefix' => 'voltage',
95
	},
96
	'EnvMonTemperature' => {
97
		'title' => 'Temperatures',
98
		'category' => 'sensors',
99
		'vlabel' => 'Degrees Celsius',
100
		'info' => "The table of ambient temperature status maintained by the environmental monitor.",
101

    
102
		'baseMib' => "$ciscoEnvMonObjectsMib.3.1",
103
		'descrOid' => 2,
104
		'valueOid' => 3,
105
		'thresholdLowOid' => 0, # n/a
106
		'thresholdHighOid' => 0, # n/a
107
		'thresholdOid' => 4,
108
		'stateOid' => 6,
109

    
110
		'instancePrefix' => 'temp',
111
	},
112
	'EnvMonFanStatus' => {
113
		'title' => 'Fans',
114
		'category' => 'sensors',
115
		'vlabel' => 'state',
116
		'info' => "The table of fan status maintained by the environmental monitor (1=normal, 2=warning, 3=critical, 4=shutdown, 5=notPresent, 6=notFunctioning).\n", # CiscoEnvMonState
117

    
118
		'baseMib' => "$ciscoEnvMonObjectsMib.4.1",
119
		'descrOid' => 2,
120
		'valueOid' => 0, # n/a
121
		'thresholdLowOid' => 0, # n/a
122
		'thresholdHighOid' => 0, # n/a
123
		'thresholdOid' => 0, # n/a
124
		'stateOid' => 3,
125

    
126
		'instancePrefix' => 'fan',
127
	},
128
	'EnvMonSupplyStatus' => {
129
		'title' => 'Power supplies',
130
		'category' => 'sensors',
131
		'vlabel' => 'state',
132
		'info' => "The table of power supply status maintained by the environmental monitor card (1=normal, 2=warning, 3=critical, 4=shutdown, 5=notPresent, 6=notFunctioning).\n", # CiscoEnvMonState
133

    
134
		'baseMib' => "$ciscoEnvMonObjectsMib.5.1",
135
		'descrOid' => 2,
136
		'valueOid' => 0, # n/a
137
		'thresholdLowOid' => 0, # n/a
138
		'thresholdHighOid' => 0, # n/a
139
		'thresholdOid' => 0, # n/a
140
		'stateOid' => 3,
141

    
142
		'instancePrefix' => 'supply',
143
	},
144
);
145

    
146

    
147
my ($object) = $0 =~ m/([^_]+)$/;
148
$object ||= 'EnvMonTemperature';
149

    
150
if (defined $ARGV[0] and $ARGV[0] eq 'suggest') {
151
	print join(' ', keys (%params)) . "\n";
152
        exit 0;
153
}
154

    
155
if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
156
        print "index $entPhysicalIndexMib.\n";
157
        print "require $params{$object}{baseMib}.$params{$object}{valueOid}. [0-9]\n";
158
        exit 0;
159
}
160

    
161
my $session = Munin::Plugin::SNMP->session();
162

    
163
my $values = $session->get_hash(
164
	-baseoid => "$params{$object}{baseMib}",
165
	-cols => {
166
		$params{$object}{descrOid} => 'Descr',
167
		$params{$object}{valueOid} => 'Value',
168
		$params{$object}{thresholdHighOid} => 'ThresholdHigh',
169
		$params{$object}{thresholdLowOid} => 'ThresholdLow',
170
		$params{$object}{thresholdOid} => 'Threshold',
171
		$params{$object}{stateOid} => 'State',
172
	}
173
);
174

    
175
# For some reason, some instanceIds are returned with trailing spaces,
176
# sometimes. Flatten them.
177
foreach my $instanceId (keys %{$values}) {
178
	my $instanceIdTrim = $instanceId;
179
	$instanceIdTrim =~ s/\s+$//;
180
	if (!($instanceIdTrim eq $instanceId)) {
181
		foreach my $data (keys %{$values->{$instanceId}}) {
182
			$values->{$instanceIdTrim}->{$data} = $values->{$instanceId}->{$data}
183
		}
184
		delete $values->{$instanceId};
185
	}
186
}
187

    
188
if (defined $ARGV[0] and $ARGV[0] eq "config") {
189
        my ($host) = Munin::Plugin::SNMP->config_session();
190

    
191
        print "host_name $host\n" unless $host eq 'localhost';
192
        print <<"EOF";
193
graph_title $params{$object}{title}
194
graph_args --base 1000
195
graph_vlabel $params{$object}{vlabel}
196
graph_category $params{$object}{category}
197
graph_info $params{$object}{info}
198
EOF
199
	foreach my $instanceId (keys %{$values}) {
200
		print "$params{$object}{instancePrefix}$instanceId.draw LINE1\n";
201
		print "$params{$object}{instancePrefix}$instanceId.label "
202
			. $session->get_single("$entPhysicalDescrMib.$instanceId") . "\n";
203

    
204
		my $descr = $values->{$instanceId}->{'Descr'};
205
		print "$params{$object}{instancePrefix}$instanceId.info $descr\n";
206

    
207
		my $value = $values->{$instanceId}->{'Value'};
208
		if ($value) {
209

    
210
			my $cdef = $params{$object}{'cdef'};
211
			if ($cdef) {
212
				print "$params{$object}{instancePrefix}$instanceId.cdef "
213
				. "$params{$object}{instancePrefix}$instanceId,$cdef\n";
214
			}
215

    
216
			my $threshold = $values->{$instanceId}->{'Threshold'};
217
			my $thresholdHigh = $values->{$instanceId}->{'ThresholdHigh'};
218
			my $thresholdLow = $values->{$instanceId}->{'ThresholdLow'};
219
			if ($thresholdHigh || $thresholdLow) {
220
				print "$params{$object}{instancePrefix}$instanceId.critical $thresholdLow:$thresholdHigh\n";
221
			} elsif ($threshold) {
222
				print "$params{$object}{instancePrefix}$instanceId.critical $threshold\n";
223
			}
224

    
225
		} else {
226
			# assume state rather than value, add limits
227
			print "$params{$object}{instancePrefix}$instanceId.warning 2\n";
228
			print "$params{$object}{instancePrefix}$instanceId.critical 3\n";
229
		}
230
	}
231

    
232
        exit 0;
233
}
234

    
235
foreach my $instanceId (keys %{$values}) {
236
	my $value = $values->{$instanceId}->{'Value'} || 'U';
237
	if ($value eq 'U') {
238
		$value = $values->{$instanceId}->{'State'} || 'U';
239
	}
240
	print "$params{$object}{instancePrefix}$instanceId.value $value\n";
241
}