#! /usr/bin/perl use strict ; use warnings ; package Probe::Snmp ; use base 'Probe' ; use constant SNMPS => { trun => [ 'Run Time Remaining' , '.1.3.6.1.4.1.318.1.1.1.2.2.3.0' ] , tbat => [ 'Time on Battery' , '.1.3.6.1.4.1.318.1.1.1.2.1.2.0' ] , inpv => [ 'input voltage' , '.1.3.6.1.4.1.318.1.1.1.3.2.1.0' ] , lout => [ 'Output Load [%]' , '.1.3.6.1.4.1.318.1.1.1.4.2.3.0' ] , load => [ 'Load Current (Amps)' , '.1.3.6.1.4.1.318.1.1.1.4.2.4.0' ] , stat => [ 'Battery Status' , '.1.3.6.1.4.1.318.1.1.1.2.1.1.0' ] , temp => [ 'Battery Temperature' , '.1.3.6.1.4.1.318.1.1.1.2.2.2.0' ] , repl => [ 'Replace Battery Indicator' , '.1.3.6.1.4.1.318.1.1.1.2.2.4.0' ] , capa => [ 'Battery Capacity [%]' , '.1.3.6.1.4.1.318.1.1.1.2.2.1.0' ] } ; # ups_trun real snmp trun # ups_tbat real snmp tbat # ups_inpv volt snmp inpv # ups_lout perc snmp lout # ups_load real snmp load # ups_stat real snmp stat # ups_temp temp snmp temp # ups_repl real snmp repl # ups_capa perc snmp capa sub ITEMS { [ { name => 'ups_trun' , kind => 'real' , args => [ qw(trun) ] } , { name => 'ups_tbat' , kind => 'real' , args => [ qw(tbat) ] } , { name => 'ups_inpv' , kind => 'volt' , args => [ qw(inpv) ] } , { name => 'ups_lout' , kind => 'perc' , args => [ qw(lout) ] } , { name => 'ups_load' , kind => 'real' , args => [ qw(load) ] } , { name => 'ups_stat' , kind => 'real' , args => [ qw(stat) ] } , { name => 'ups_temp' , kind => 'temp' , args => [ qw(temp) ] } , { name => 'ups_repl' , kind => 'real' , args => [ qw(repl) ] } , { name => 'ups_capa' , kind => 'perc' , args => [ qw(capa) ] } ] ; } ; # snmpget -v1 -c public local-ups01.science.uu.nl .1.3.6.1.4.1.318.1.1.1.2.2.2.0 sub main { my $self = shift ; my $itms = shift ; # items to probe : [ item, ... ] my $clnt = shift ; # main::CLIENT my $hnam = $itms -> [ 0 ] -> hnam ; my $tget = Util -> hostname eq $hnam ? 'localhost' : $hnam ; my $prog = Util::find_bin ( 'snmpget' ) ; my @args = map { SNMPS -> { $_ -> args -> [ 0 ] } [ 1 ] ; } @$itms ; my @prog = ( $prog , qw(-v1 -c public) , $hnam , @args ) ; my ( $err, $xit, $sig, @lines ) = Probe::Util::run_prog ( @prog ) ; if ( $err ) { $_ -> perr ( $err ) for @$itms ; } elsif ( @lines != @$itms ) { $_ -> perr ( "bad #lines from $prog" ) for @$itms ; } else { chomp @lines ; for ( my $i = 0 ; $i < @lines ; $i ++ ) { my $line = $lines [ $i ] ; my $item = $itms -> [ $i ] ; chomp $line ; my $val = ( split /\s+=\s+/, $line ) [ 1 ] ; $val =~ s/Gauge32: // ; $val =~ s/INTEGER: // ; $val = $1 / 100 if $val =~ /Timeticks:\s+\((\d+)\)/ ; $item -> set_val ( $val ) ; } } } 1 ;