2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/other/omreport_pwrmon_current

106 lines
3.0 KiB
Plaintext
Raw Normal View History

2009-02-05 16:15:19 +01:00
#!/usr/bin/perl
#
# Copyright (C) 2009 Andrew Chadwick, University of Oxford <andrew.chadwick@ceu.ox.ac.uk>
# Based on work by Rackspace US, Inc. <http://www.rackspace.com>, (C) 2008.
#
# 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, see http://www.gnu.org/licenses/gpl.txt
#
#
# This plugin will graph the per-PSU current draw of a Dell PowerEdge Server
# via the omreport tool. It has been tested on the following chassis:
#
# PowerEdge R905
#
# To enable, create a link in your plugins directory to wherever you
# installed this file, e.g.:
#
# cd /etc/munin/plugins
# ln -s /usr/share/munin/plugins/omreport_pwrmon_current
#
# Configuration parameters for /etc/munin/plugin-conf.d/munin-node
#
# [omreport_*]
# user - User that has permissions to run the omreport binary
# env.omreport - Path to the omreport binary
#
# Parameters:
#
# config
# autoconf
#
# Author: Andrew Chadwick <andrew.chadwick@ceu.ox.ac.uk>
# Revision: 0.1 2008-01-28
#
#%# family=auto
#%# capabilities=autoconf
use strict;
my $omreport = $ENV{"omreport"} || "/usr/bin/omreport";
if ($ARGV[0] && $ARGV[0] eq "autoconf") {
if (-f $omreport) {
print "yes\n";
}
else {
print "no ($omreport does not exist)\n";
exit(1);
}
}
else {
my @cmd = ($omreport, qw{chassis pwrmonitoring});
my ($index, %val);
my $pid = open(my $cmd_out, '-|', @cmd) or die "@cmd: $!\n";
defined $pid or die "fork() failed: $!\n";
my $amperage_idx = 0;
while (<$cmd_out>) {
s/\s+/\040/g;
s/\s+$//;
s/^\s+//;
/^Amperage\b/ .. /^Power\s+Tracking\b/ or next;
my ($field, $value) = split(/\s+\:\s+/, $_);
if ($field eq 'Location') {
$index = "current_${amperage_idx}";
++$amperage_idx;
$val{$index} = {
label => $value,
};
}
elsif ($field eq 'Reading') {
$value =~ s{\s+A$}{};
$value =~ s{\[N/A\]}{}g;
$val{$index}{value} = $value;
}
}
close $cmd_out;
if ($ARGV[0] && $ARGV[0] eq "config") {
print "graph_title OpenManage - Power Monitoring - Current\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel Amps\n";
print "graph_category Sensors\n";
foreach my $j (sort keys %val) {
print "$j.label $val{$j}{label}\n";
}
}
else {
foreach my $j (sort keys %val) {
print "$j.value $val{$j}{value}\n";
}
}
}
exit(0);