Skip to content

Instantly share code, notes, and snippets.

@balbinus
Created September 25, 2014 13:24
Show Gist options
  • Save balbinus/f57588ee2ef995137dc1 to your computer and use it in GitHub Desktop.
Save balbinus/f57588ee2ef995137dc1 to your computer and use it in GitHub Desktop.
Edited version of "ups2" munin plugin to handle some custom MIBS for MGE UPS (EATON 1500i in my case). Source of MIBS: http://soft.apc.com/emb/66244/mgeupsmib17_ac.mib
#!/usr/bin/perl -w
#
# Jean-Samuel Reynaud <[email protected]>
# base on snmp__if_ from Jimmy Olsen, 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.
#
#
# Usage:
# ln -s /usr/share/munin/node/plugins-auto/snmp__ups2_ /etc/munin/node.d/snmp_ups.address.loc_mode
# with mode : batteryVoltage, batteryTemperature,inputVoltage,inputCurrent,inputFrequency,outputVoltage,outputCurrent,outputPower,outputPercentLoad,ChargeRemaining
#
#%# family=snmpauto
#%# capabilities=snmpconf
use strict;
use Net::SNMP;
my $DEBUG = 0;
my $host = $ENV{host} || undef;
my $port = $ENV{port} || 161;
my $community = $ENV{community} || "public";
my $mode = $ENV{mode} || undef;
my $response;
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
print "require .1.3.6.1.2.1.33.1.2.7 [0-9]\n"; # Bat temp
exit 0;
}
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_apc_ups2_(.+)$/)
{
$host = $1;
$mode = $2;
if ($host =~ /^([^:]+):(\d+)$/)
{
$host = $1;
$port = $2;
}
}
elsif (!defined($host))
{
print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor.";
}
my $graphs = {
#### BATTERY
'batteryVoltage' => { 'title' => 'Battery Voltage',
'category' => 'battery',
'unit' => 'V',
'value' => '.1.3.6.1.2.1.33.1.2.5'},
'batteryCurrent' => { 'title' => 'Battery Current',
'category' => 'battery',
'unit' => 'kVA', 'value' =>
'.1.3.6.1.4.1.705.1.6.1.0'},
'batteryTemperature' => { 'title' => 'Battery Temperature',
'category' => 'battery',
'unit' => 'DegC',
'value' => '.1.3.6.1.2.1.33.1.2.7'},
'batteryRemainingTime' => { 'title' => 'Battery Remaining Time',
'category' => 'battery',
'unit' => 's',
'value' => '.1.3.6.1.4.1.705.1.5.1.0'},
'ChargeRemaining' => { 'title' => 'Charge remaining',
'unit' => '%',
'category' => 'battery',
'value' => '.1.3.6.1.2.1.33.1.2.4'},
#### INPUT
'inputVoltage' => { 'title' => 'Input Voltage',
'category' => 'input',
'unit' => 'V',
# 'list' => '.1.3.6.1.4.1.705.1.6.1.0',
'value' => '.1.3.6.1.4.1.705.1.6.2.1.2.1.0'},
'inputCurrent' => { 'title' => 'Input Current',
'category' => 'input',
'unit' => 'W',
'list' => '.1.3.6.1.2.1.33.1.3.2',
'value' => '.1.3.6.1.2.1.33.1.3.3.1.4'},
'inputFrequency' => { 'title' => 'Input Frequency',
'category' => 'input',
'unit' => 'Hz',
# 'list' => '.1.3.6.1.4.1.705.1.6.1.0',
'value' => '.1.3.6.1.4.1.705.1.6.2.1.3.1.0'},
#### OUTPUT
'outputVoltage' => { 'title' => 'Output Voltage',
'category' => 'output',
'list' => '.1.3.6.1.4.1.705.1.7.1.0',
'unit' => 'Hz',
'value' => '.1.3.6.1.4.1.705.1.7.2.1.2'},
'outputCurrent' => { 'title' => 'Output Current',
'category' => 'output',
'unit' => 'A',
'list' => '.1.3.6.1.4.1.705.1.7.1.0',
'value' => '.1.3.6.1.4.1.705.1.7.2.1.5'},
'outputFrequency' => { 'title' => 'Output Frequency',
'category' => 'output',
'list' => '.1.3.6.1.4.1.705.1.7.1.0',
'unit' => 'Hz',
'value' => '.1.3.6.1.4.1.705.1.7.2.1.3'},
'outputPercentLoad' => { 'title' => 'Output PercentLoad',
'category' => 'output',
'list' => '.1.3.6.1.2.1.33.1.4.3',
'unit' => '%',
'value' => '.1.3.6.1.2.1.33.1.4.4.1.5'},
'outputOnBattery' => { 'title' => 'Output On Battery',
'category' => 'output',
'unit' => '(1 = yes, 2 = no)',
'value' => '.1.3.6.1.4.1.705.1.7.3.0'},
};
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-port => $port
);
if (!defined ($session))
{
die "Croaking: $error";
}
my $count_data = 1;
if (defined $graphs->{$mode}->{'list'} &&
defined ($response = $session->get_request($graphs->{$mode}->{'list'} . ".0"))) {
$count_data = $response->{$graphs->{$mode}->{'list'} . ".0"};
}
if ($ARGV[0] and $ARGV[0] eq "config")
{
print "host_name $host\n";
printf "graph_title %s \n",$graphs->{$mode}->{'title'};
# print "graph_args --base 1000\n";
print "graph_category sensors\n";
for(my $i=0;$i<$count_data;$i++) {
printf "line%u.label Line %u\n",$i+1,$i+1;
printf "line%u.type GAUGE\n",$i+1;
printf "line%u.info %s\n",$i+1,$graphs->{$mode}->{'unit'};
}
exit 0;
}
for(my $i=0;$i<$count_data;$i++) {
my $l_current = $i+1;
# if ($count_data == 1) {
# $l_current = 0;
# }
my $key = $graphs->{$mode}->{'value'};
if (defined ($graphs->{$mode}->{'list'})) {
$key = $key . sprintf(".%u",$l_current);
}
if (defined ($response = $session->get_request($key))) {
printf "line%u.value %u\n",$i+1,$response->{$key};
} else {
printf "line%u.value U\n",$i+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment