mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
snmp__apc: rewrite to make use of get_entries and get_hash.
This should simplify quite a bit the handling of 3-phase PDUs, among other things.
This commit is contained in:
parent
f570516416
commit
d6f29a6b52
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
# -*- cperl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
@ -49,57 +49,67 @@ use strict;
|
||||
use Munin::Plugin;
|
||||
use Munin::Plugin::SNMP;
|
||||
|
||||
# This is the data we care about:
|
||||
# PowerNet-MIB::rPDUIdentModelNumber.0 -> .1.3.6.1.4.1.318.1.1.12.1.5.0
|
||||
# PowerNet-MIB::rPDUIdentSerialNumber.0 -> .1.3.6.1.4.1.318.1.1.12.1.6.0
|
||||
# PowerNet-MIB::rPDULoadDevNumPhases.0 -> .1.3.6.1.4.1.318.1.1.12.2.1.2.0
|
||||
# PowerNet-MIB::rPDULoadPhaseConfigNearOverloadThreshold.phase1 -> .1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.1
|
||||
# PowerNet-MIB::rPDULoadPhaseConfigOverloadThreshold.phase1 -> .1.3.6.1.4.1.318.1.1.12.2.2.1.1.4.1
|
||||
# PowerNet-MIB::rPDULoadStatusLoad.1 -> .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1
|
||||
# This corresponds to PowerNet-MIB::rPDU
|
||||
my $oidBase = '1.3.6.1.4.1.318.1.1.12';
|
||||
|
||||
# PowerNet-MIB::rPDUIdentModelNumber
|
||||
my $oidModelNo = "$oidBase.1.5";
|
||||
# PowerNet-MIB::rPDUIdentSerialNumber
|
||||
my $oidSerialNo = "$oidBase.1.6";
|
||||
# PowerNet-MIB::rPDULoadDevNumPhases
|
||||
my $oidNumPhases = "$oidBase.2.1.2";
|
||||
# PowerNet-MIB::rPDULoadPhaseConfigEntry
|
||||
# .3 -> PowerNet-MIB::rPDULoadPhaseConfigNearOverloadThreshold
|
||||
# .4 -> PowerNet-MIB::rPDULoadPhaseConfigOverloadThreshold
|
||||
my $oidConfigBase = "$oidBase.2.2.1.1";
|
||||
# PowerNet-MIB::rPDULoadStatusLoad (+)
|
||||
my $oidPhaseLoad = "$oidBase.2.3.1.1.2";
|
||||
|
||||
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
|
||||
print "index 1.3.6.1.4.1.318.1.1.12.2.2.1.1.1.\n";
|
||||
print "require 1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.[1-9]"; # Load
|
||||
print "require $oidBase.2.3.1.1.2.[1-9]";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $oidModelNo = '1.3.6.1.4.1.318.1.1.12.1.5.0';
|
||||
my $oidSerialNo = '1.3.6.1.4.1.318.1.1.12.1.6.0';
|
||||
my $oidNumPhases = '1.3.6.1.4.1.318.1.1.12.2.1.2.0';
|
||||
my $oidNearOverloadThreshold = '1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.';
|
||||
my $oidOverloadThreshold = '1.3.6.1.4.1.318.1.1.12.2.2.1.1.4.';
|
||||
my $oidPhaseLoad = '1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.';
|
||||
|
||||
# SNMP needed for both config and fetch.
|
||||
my $session = Munin::Plugin::SNMP->session();
|
||||
my $numPhases = $session->get_single($oidNumPhases);
|
||||
my $data = $session->get_entries(-columns => [$oidNumPhases,
|
||||
$oidModelNo,
|
||||
$oidSerialNo]);
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "config") {
|
||||
my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();
|
||||
my ($host) = Munin::Plugin::SNMP->config_session();
|
||||
|
||||
print "host_name $host\n" unless $host eq 'localhost';
|
||||
print <<END;
|
||||
host_name $host
|
||||
|
||||
my $modelNo = $session->get_single($oidModelNo);
|
||||
my $serialNo = $session->get_single($oidSerialNo);
|
||||
graph_title PDU Current Drain
|
||||
graph_vlabel Ampere
|
||||
graph_category sensors
|
||||
graph_info This graph if for $data->{"$oidModelNo.0"} serial $data->{"$oidSerialNo.0"}
|
||||
END
|
||||
|
||||
print "graph_title PDU Current Drain\n";
|
||||
print "graph_vlabel Ampere\n";
|
||||
print "graph_category Sensors\n";
|
||||
print "graph_info This graph is for $modelNo PDU serial $serialNo\n"
|
||||
|
||||
for( my $phaseIndex = 1; $phaseIndex <= $numPhases; $phaseIndex++ ) {
|
||||
my $nearOverloadThreshold = $session->get_single($oidNearOverloadThreshold . $phaseIndex);
|
||||
my $overloadThreshold = $session->get_single($oidOverloadThreshold . $phaseIndex);
|
||||
print "phase$phaseIndex.label Phase $phaseIndex load\n";
|
||||
print "phase$phaseIndex.warning $nearOverloadThreshold\n";
|
||||
print "phase$phaseIndex.critical $overloadThreshold\n";
|
||||
print "phase$phaseIndex.min 0\n";
|
||||
my $phaseData = $session->get_hash(-baseoid => "$oidConfigBase",
|
||||
-cols => { 3 => 'nearOverloadThreshold',
|
||||
4 => 'overloadThreshold' }
|
||||
);
|
||||
my $phaseIndex;
|
||||
for( $phaseIndex = 1; $phaseIndex <= $data->{"$oidNumPhases.0"}; $phaseIndex++ ) {
|
||||
print <<END;
|
||||
phase$phaseIndex.label Phase $phaseIndex load
|
||||
phase$phaseIndex.min 0
|
||||
phase$phaseIndex.warning $phaseData->{$phaseIndex}->{'nearOverloadThreshold'}
|
||||
phase$phaseIndex.critical $phaseData->{$phaseIndex}->{'overloadThreshold'}
|
||||
END
|
||||
}
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
for( my $phaseIndex = 1; $phaseIndex <= $numPhases; $phaseIndex++ ) {
|
||||
my $phasesLoad = $session->get_entries(-columns => [$oidPhaseLoad]);
|
||||
|
||||
my $phaseIndex;
|
||||
for( $phaseIndex = 1; $phaseIndex <= $data->{"$oidNumPhases.0"}; $phaseIndex++ ) {
|
||||
# the phaseLoad value is defined in dA — we might as well convert to full Amperes
|
||||
my $phaseLoad = $session->get_single($oidPhaseLoad . $phaseIndex) / 10.0;
|
||||
my $phaseLoad = $phasesLoad->{"$oidPhaseLoad.$phaseIndex"} / 10.0;
|
||||
print "phase$phaseIndex.value $phaseLoad\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user