Projet

Général

Profil

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

root / plugins / snmp / snmp__ipoman_ @ 7da1b039

Historique | Voir | Annoter | Télécharger (13,1 ko)

1
#!/usr/bin/perl -w
2
#
3
# What is snmp__ipoman_
4
# ----------------------
5
# snmp__ipoman is a munin plugin written for the Ingrasys IpomanII 1202
6
# Power Distribution Unit. It should work on any PDU conforming to 
7
# the IPOMANII-MIB. 
8
#
9
# How do I use it
10
# ---------------
11
# You can use this plugin on a system with a working munin-node. Here's
12
# how:
13
#
14
# 1. Copy snmp__ipoman_ to the directory where all your munin plugins
15
# reside, for example /usr/share/munin/plugins. 
16
#
17
# 2. Make the following symlinks to snmp__ipoman_ in that same directory
18
#
19
#  snmp__ipoman_inletcurrent_
20
#  snmp__ipoman_inletpower_
21
#  snmp__ipoman_inletvoltage_
22
#  snmp__ipoman_outletpower_
23
#  snmp__ipoman_outletcurrent_
24
#
25
# (If you wonder why. I did not manage to make a plugin which has both
26
# the 'snmpconf' and the 'suggest' capabilities. So either I had to make
27
# separate plugins for all graph types, or I would have to make
28
# assumptions on the number of ports and the address of the ipoman in
29
# the script.)
30
#
31
# 3. Change to the directory where the links to munin plugins reside
32
# that are to be run by munin-node, for example /etc/munin/plugins/
33
#
34
# 4. Run munin-node-configure-snmp:
35
#
36
#  $ munin-node-configure-snmp --snmpversion=1 <hostname>  | sh -x
37
#
38
# where <hostname> is the hostname or ip address of your ipoman. This
39
# will create and print a bunch of symlinks to snmp__ipoman_ which will
40
# output current and power usage for all available outlets of the
41
# ipoman, and current, power usage and voltage/frequency on all inlets
42
# of the ipoman.
43
# 
44
# 5. Restart munin-node
45
#
46
# 6. Make an entry in your munin server's munin.conf:
47
#
48
# [<hostname of ipoman as entered in 4.>]
49
# 	address <address of munin-node>
50
# 	use_node_name no
51
# 
52
# 7. Done.
53
#
54
# Copyright (C) 2009 Rien Broekstra <rien@rename-it.nl>
55
#
56
# This program is free software; you can redistribute it and/or
57
# modify it under the terms of the GNU General Public License
58
# as published by the Free Software Foundation; version 2 dated June,
59
# 1991.
60
#
61
# This program is distributed in the hope that it will be useful,
62
# but WITHOUT ANY WARRANTY; without even the implied warranty of
63
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
64
# GNU General Public License for more details.
65
#
66
# You should have received a copy of the GNU General Public License
67
# along with this program; if not, write to the Free Software
68
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
69
#
70
# Munin plugin to monitor power consumption and current of the sockets of an 
71
# Ingrasys IpomanII 1202 Power Distribution Unit, or any power distribution 
72
# unit that conforms to IPOMANII-MIB via SNMP.
73
#
74
# Parameters:
75
#
76
#       config    
77
#       snmpconf   
78
#
79
# Relevant OID's under .iso.org.dod.internet.private.enterprises.ingrasys.product.pduAgent.iPoManII
80
# .ipmObjects.ipmDevice.ipmDeviceOutlet.ipmDeviceOutletNumber.0
81
# .ipmObjects.ipmDevice.ipmDeviceOutlet.ipmDeviceOutletStatusTable.ipmDeviceOutletStatusEntry.outletStatusIndex.1
82
# .ipmObjects.ipmDevice.ipmDeviceOutlet.ipmDeviceOutletStatusTable.ipmDeviceOutletStatusEntry.outletStatusCurrent.1
83
# .ipmObjects.ipmDevice.ipmDeviceOutlet.ipmDeviceOutletStatusTable.ipmDeviceOutletStatusEntry.outletStatusKwatt.1
84
# .ipmObjects.ipmDevice.ipmDeviceOutlet.ipmDeviceOutletStatusTable.ipmDeviceOutletStatusEntry.outletStatusWH.1 
85
#
86
# Version 0.1, Aug 4, 2009
87
#
88
#
89
#
90
#
91
#
92
#
93
#
94
#
95
#
96
#
97
# MAGIC MARKERS:
98
#
99
#%# family=snmpauto
100
#%# capabilities=snmpconf
101

    
102
use strict;
103
use Net::SNMP;
104

    
105
my $DEBUG = 0;
106

    
107
my $host      = $ENV{host}      || undef;
108
my $port      = $ENV{port}      || 161;
109
my $community = $ENV{community} || "public";
110
my $iface     = $ENV{interface} || undef;
111

    
112
my $socketnumber;
113
my $response;
114
my $graphtype;
115

    
116
#
117
# Infer host, inlet/socketnumber and graphtype from the symlink name to this plugin.
118
#
119
if ($0 =~ /^(?:|.*\/)snmp_([^_]*)_ipoman_([^_]*)_(.*)$/)
120
{
121
    $host  = $1;
122
    $graphtype = $2;
123
    $socketnumber = $3;
124
    if ($host =~ /^([^:]+):(\d+)$/) {
125
	$host = $1;
126
	$port = $2;
127
    }
128
}
129

    
130
if (!defined($graphtype)) {
131
    die "# Error: couldn't understand what quantity I'm supposed to monitor.";
132
}
133

    
134
#
135
# The relevant OID's on the IPOMAN
136
#
137
my $oid_inletnumber =       ".1.3.6.1.4.1.2468.1.4.2.1.3.1.1.0"; 
138
my $oid_inletindextable =   ".1.3.6.1.4.1.2468.1.4.2.1.3.1.2.1.1."; 
139
my $oid_inletvoltage   =    ".1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.2.";
140
my $oid_inletcurrent   =    ".1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.3.";
141
my $oid_inletfrequency =    ".1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.4.";
142
my $oid_inletenergy    =    ".1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.5.";
143

    
144
my $oid_outletnumber =      ".1.3.6.1.4.1.2468.1.4.2.1.3.2.1.0"; 
145
my $oid_outletindextable =  ".1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.1."; 
146
my $oid_outletdescription = ".1.3.6.1.4.1.2468.1.4.2.1.3.2.2.1.2.";
147
my $oid_outletcurrent =     ".1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.3.";
148
my $oid_outletenergy =      ".1.3.6.1.4.1.2468.1.4.2.1.3.2.3.1.4.";
149
# FIXME: The voltage is not defined per outlet. For now we just assume that all sockets have the voltage on inlet 1.
150
my $oid_outletvoltage =     ".1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.2.1";
151

    
152
#
153
# The snmpconf section prints out what oid's we need for the quantity we want to monitor, and where we find out how many ports the device has.
154
#
155
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
156
    if ($graphtype eq "inletvoltage") {
157
	print "number $oid_inletnumber\n";
158
	print "index $oid_inletindextable\n";
159
	print "require $oid_inletvoltage [0-9]+\n";
160
	print "require $oid_inletfrequency [0-9]+\n";
161
    }
162
    elsif ($graphtype eq "inletcurrent") {
163
	print "number $oid_inletnumber\n";
164
	print "index $oid_inletindextable\n";
165
	print "require $oid_inletcurrent [0-9]+\n";
166
    }
167
    elsif ($graphtype eq "inletpower") {
168
	print "number $oid_inletnumber\n";
169
	print "index $oid_inletindextable\n";
170
	print "require $oid_inletvoltage [0-9]+\n";
171
	print "require $oid_inletcurrent [0-9]+\n";
172
    }
173
    elsif ($graphtype eq "outletcurrent") {
174
	print "number $oid_outletnumber\n";
175
	print "index $oid_outletindextable\n";
176
	print "require $oid_outletcurrent [0-9]+\n";
177
    }
178
    elsif ($graphtype eq "outletpower") {
179
	print "number $oid_outletnumber\n";
180
	print "index $oid_outletindextable\n";
181
	print "require $oid_outletvoltage [0-9]+\n";
182
	print "require $oid_outletcurrent [0-9]+\n";
183
    }
184
    else {
185
	print "require dont.graph.anything [0-9]+\n"
186
    }
187
    exit 0;
188
}
189

    
190
#
191
# For all other options we need to connect to the host in our $0. if we cannot, bail out.
192
#
193
if (!defined($host))
194
{
195
    print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
196
    die "# Error: couldn't understand what I'm supposed to monitor.";
197
}
198

    
199
my ($session, $error) = Net::SNMP->session(
200
                -hostname  => $host,
201
                -community => $community,
202
                -port      => $port
203
					   );
204

    
205
if (!defined ($session))
206
{
207
    die "Croaking: $error";
208
}
209

    
210
#
211
# Output graph configuration depending on what quantity we want to plot
212
#
213
if (defined $ARGV[0] and $ARGV[0] eq "config") {
214
    print "host_name $host\n";
215
    if ($graphtype eq "inletvoltage") {
216

    
217
	print "graph_title Inlet $socketnumber voltage/frequency\n";
218

    
219
	print "graph_args --base 1000 -l 0\n";
220
	print "graph_category system\n";
221
	print "graph_info This graph shows the tension and frequency to inlet $socketnumber on the Power Distribution Unit\n";
222
    
223
	print "voltage.label Tension (V)\n";
224
	print "voltage.draw LINE2\n";
225
	print "voltage.type GAUGE\n";
226

    
227
	print "frequency.label Frequency (Hz)\n";
228
	print "frequency.draw LINE2\n";
229
	print "frequency.type GAUGE\n";
230

    
231
    }
232
    elsif ($graphtype eq "inletcurrent") {
233
	print "graph_title Inlet $socketnumber current\n";
234

    
235
	print "graph_args --base 1000 -l 0\n";
236
	print "graph_category system\n";
237
	print "graph_info This graph shows the delivered current to inlet $socketnumber on the Power Distribution Unit\n";
238
    
239
	print "current.label Current (A)\n";
240
	print "current.draw AREA\n";
241
	print "current.type GAUGE\n";
242

    
243
    }
244
    elsif ($graphtype eq "inletpower") {
245
	print "graph_title Inlet $socketnumber power\n";
246

    
247
	print "graph_args --base 1000 -l 0\n";
248
	print "graph_category system\n";
249
	print "graph_info This graph shows the delivered apparent and real power to inlet $socketnumber of the Power Distribution Unit\n";
250
	
251
	print "apparentpower.label Apparent power (kVA)\n";
252
	print "apparentpower.draw LINE3\n";
253
	print "apparentpower.type GAUGE\n";
254
	
255
	print "realpower.label Real power (kW)\n";
256
	print "realpower.draw AREA\n";
257
	print "realpower.type COUNTER\n";
258
	
259
	exit 0;
260
    }
261
    elsif ($graphtype eq "outletcurrent") {
262
	print "graph_title Outlet $socketnumber current\n";
263
	
264
	print "graph_args --base 1000 -l 0\n";
265
	print "graph_category system\n";
266
	print "graph_info This graph shows the delivered current to outlet $socketnumber of the Power Distribution Unit\n";
267
    
268
	print "current.label Delivered current (A)\n";
269
	print "current.draw AREA\n";
270
	print "current.type GAUGE\n";
271
    }
272
    elsif ($graphtype eq "outletpower") {
273
	print "graph_title Outlet $socketnumber power\n";
274
	
275
	print "graph_args --base 1000 -l 0\n";
276
	print "graph_category system\n";
277
	print "graph_info This graph shows the delivered apparent and real power to outlet $socketnumber of the Power Distribution Unit\n";
278
	
279
	print "apparentpower.label Apparent power (kVA)\n";
280
	print "apparentpower.draw LINE3\n";
281
	print "apparentpower.type GAUGE\n";
282
	
283
	print "realpower.label Real power (kW)\n";
284
	print "realpower.draw AREA\n";
285
	print "realpower.type COUNTER\n";
286
	
287
	exit 0;
288
    }
289
    exit 0;
290
}
291

    
292
if ($graphtype eq "inletvoltage") {
293
    my ($voltage, $frequency);
294

    
295
    if (defined ($response = $session->get_request($oid_inletvoltage.$socketnumber))) {
296
	$voltage = $response->{$oid_inletvoltage.$socketnumber};
297
    }
298
    else {
299
	$voltage = 'U';
300
    }
301

    
302
    if (defined ($response = $session->get_request($oid_inletfrequency.$socketnumber))) {
303
	$frequency = $response->{$oid_inletfrequency.$socketnumber};
304
    }
305
    else {
306
	$frequency = 'U';
307
    }
308

    
309
    # The IPOMAN returns tension in 0.1V units.
310
    # Convert to V
311
    if ($voltage ne 'U') {
312
	$voltage = $voltage/10;
313
    }
314

    
315
    # The IPOMAN returns frequency in 0.1Hz units.
316
    # Convert to Hz
317
    if ($frequency ne 'U') {
318
	$frequency = $frequency/10;
319
    }
320

    
321
    print "voltage.value ", $voltage, "\n";
322
    print "frequency.value ", $frequency, "\n";
323
}
324
elsif ($graphtype eq "inletcurrent") {
325
    my $current;
326

    
327
    if (defined ($response = $session->get_request($oid_inletcurrent.$socketnumber))) {
328
	$current = $response->{$oid_inletcurrent.$socketnumber};
329
    }
330
    else {
331
	$current = 'U';
332
    }
333

    
334
    # The IPOMAN returns power in mA.
335
    # Convert to A:
336
    #
337
    if ($current ne 'U') {
338
	$current = $current/1000;
339
    }
340

    
341
    print "current.value ", $current, "\n";
342
}
343
elsif ($graphtype eq "inletpower") {
344
    my ($current, $energy, $voltage, $apparentpower);
345
    
346
    if (defined ($response = $session->get_request($oid_inletcurrent.$socketnumber))) {
347
	$current = $response->{$oid_inletcurrent.$socketnumber};
348
    }
349
    else {
350
	$current = 'U';
351
    }
352

    
353
    if (defined ($response = $session->get_request($oid_inletenergy.$socketnumber))) {
354
	$energy = $response->{$oid_inletenergy.$socketnumber};
355
    }
356
    else {
357
	$energy = 'U';
358
    }
359

    
360
    if (defined ($response = $session->get_request($oid_inletvoltage.$socketnumber))) {
361
	$voltage = $response->{$oid_inletvoltage.$socketnumber};
362
    }
363
    else {
364
	$voltage = 'U';
365
    }
366

    
367
    # Calculate results
368
    # Apparent power (VA)= Voltage (V)* Current(A).
369
    # IPOMAN delivers voltage in units of 0.1V. and current in units of mA:
370
    if ($current ne 'U' && $voltage ne 'U') {
371
	$apparentpower = ($current/1000)*($voltage/10);
372
    }
373

    
374
    #
375
    # The IPOMAN returns consumed energy in Wh. We want it in J (= Ws), in order for munin to graph in W.
376
    #
377
    if ($energy ne 'U') {
378
	$energy = $energy*3600;
379
    }
380

    
381
    print "realpower.value ", $energy, "\n";
382
    print "apparentpower.value ", $apparentpower, "\n";
383
}
384
elsif ($graphtype eq "outletcurrent") {
385
    my $current;
386

    
387
    if (defined ($response = $session->get_request($oid_outletcurrent.$socketnumber))) {
388
	$current = $response->{$oid_outletcurrent.$socketnumber};
389
    }
390
    else {
391
	$current = 'U';
392
    }
393

    
394
    # The IPOMAN returns power in mA.
395
    # Convert to A:
396
    #
397
    if ($current ne 'U') {
398
	$current = $current/1000;
399
    }
400

    
401
    print "current.value ", $current, "\n";
402
}
403
elsif ($graphtype eq "outletpower") {
404
    my ($current, $energy, $voltage, $apparentpower);
405
    
406
    if (defined ($response = $session->get_request($oid_outletcurrent.$socketnumber))) {
407
	$current = $response->{$oid_outletcurrent.$socketnumber};
408
    }
409
    else {
410
	$current = 'U';
411
    }
412

    
413
    if (defined ($response = $session->get_request($oid_outletenergy.$socketnumber))) {
414
	$energy = $response->{$oid_outletenergy.$socketnumber};
415
    }
416
    else {
417
	$energy = 'U';
418
    }
419

    
420
    if (defined ($response = $session->get_request($oid_outletvoltage))) {
421
	$voltage = $response->{$oid_outletvoltage};
422
    }
423
    else {
424
	$voltage = 'U';
425
    }
426

    
427
    #
428
    # Calculate results
429
    # Apparent power (VA)= Voltage (V)* Current(A).
430
    # IPOMAN delivers voltage in units of 0.1V. and current in units of mA:
431
    if ($current ne 'U' && $voltage ne 'U') {
432
	$apparentpower = ($current/1000)*($voltage/10);
433
    }
434

    
435
    #
436
    # The IPOMAN returns consumed energy in Wh. We want it in J (= Ws), in order for munin to graph in W.
437
    #
438
    if ($energy ne 'U') {
439
	$energy = $energy*3600;
440
    }
441

    
442
    print "realpower.value ", $energy, "\n";
443
    print "apparentpower.value ", $apparentpower, "\n";
444
}
445
exit 0;