I am using Net::SNMP to pull an OID value. I am getting the value, but it is matching both conditions and I am not sure why.
#!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 p +ower # requires a hostname and a community string as its arguments ($session,$error) = Net::SNMP->session(Hostname => "test_ups", Communi +ty => "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;
I am sure that it is some newbie syntax error.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
How is it uninitialized when I defined the variables?$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.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |