#!c:/perl/perl.exe
use Net::SNMP;
use Data::Dumper;
my $on_battery = "5"; #Indicates that the UPS in on battery power
my $on_commercial = "3"; #Indicates that the UPS in on commercial power
# requires a hostname and a community string as its arguments
($session,$error) = Net::SNMP->session(Hostname => "test_ups", Community
=> "public");
die "session error: $error" unless ($session);
#.1.3.6.1.2.1.33.1.4.1 is the OID the battery status of the UPS
my $result = $session->get_table (".1.3.6.1.2.1.33.1.4.1");
die "request error: ".$session->error unless (defined $result);
print Dumper( $result );
my @values = values (%$result);
foreach my $key (@values) {
print "$key\n";
my $status = $key;
print "$status\n";
}
if ( $status = $on_commercial )
{
print "The ups is normal\n";
}
if ( my $status = $on_battery )
{
print "The ups is on battery\n";
}
$session->close;
####
C:\>snmp.pl
$VAR1 = {
'.1.3.6.1.2.1.33.1.4.1.0' => 3
};
3
3
The ups is normal
The ups is on battery
####
$VAR1 = {
'.1.3.6.1.2.1.33.1.4.1.0' => 3
};
3
3
Use of uninitialized value in numeric eq (==) at C:\SNMP.p
l line 25.
Use of uninitialized value in numeric eq (==) at C:\SNMP.p
l line 29.