Gunner Posted April 18, 2012 Posted April 18, 2012 Не могу понять почему не работает может глаз замылился. Вот кусок кода sub snmpPort { my $ipcomm = $_[0]; my $port = $_[1]; print $ipcomm,"-",$port,"\n"; my ( $session, $error ) = Net::SNMP->session ( Hostname => $ipcomm,Community => "private",version => 2); die "session error: $error" unless ( $session ); my( @list); push( @list, ("1.3.6.1.2.1.2.2.1.7.".$port, INTEGER, 2)); print Dumper(\@list); my $result = $session->set_request( -varbindlist => [@list]); print "request error: ".$session->error unless (defined $result),"\n"; } Вот результат исполнения 10.10.250.66-12 $VAR1 = [ '1.3.6.1.2.1.2.2.1.7.12', 'INTEGER', 2 ]; root@billing:/scripts# snmpget -v2c -c private 10.10.250.66 1.3.6.1.2.1.2.2.1.7.12 iso.3.6.1.2.1.2.2.1.7.12 = INTEGER: 1 root@billing:/scripts# snmpset -v2c -c private 10.10.250.66 1.3.6.1.2.1.2.2.1.7.12 i 2 iso.3.6.1.2.1.2.2.1.7.12 = INTEGER: 2 root@billing:/scripts# snmpget -v2c -c private 10.10.250.66 1.3.6.1.2.1.2.2.1.7.12 iso.3.6.1.2.1.2.2.1.7.12 = INTEGER: 2 Почему порт не ушел в даун ? Вставить ник Quote
gibbon Posted April 18, 2012 Posted April 18, 2012 У меня этот код работает [igor@second ~]$ snmpget -v2c -c gfcfltyf 192.168.3.65 1.3.6.1.2.1.2.2.1.7.12 IF-MIB::ifAdminStatus.12 = INTEGER: up(1) [igor@second ~]$ perl test.pl 192.168.3.65-12 $VAR1 = [ '1.3.6.1.2.1.2.2.1.7.12', 2, 2 ]; [igor@second ~]$ snmpget -v2c -c gfcfltyf 192.168.3.65 1.3.6.1.2.1.2.2.1.7.12 IF-MIB::ifAdminStatus.12 = INTEGER: down(2) Вставить ник Quote
Gunner Posted April 18, 2012 Author Posted April 18, 2012 use Net::SNMP qw(:snmp); так объявляли ? Вставить ник Quote
agr Posted April 18, 2012 Posted April 18, 2012 у вас ,"\n" обессмысливает unless, т.к. в этом случае его аргумент выполняется true. Поэтому ошибки у вас не отображаются в независимости от их наличия. Сделайте лучше так defined $result ? print "\n" : print "request error: ".$session->error."\n"; Вставить ник Quote
st_re Posted April 18, 2012 Posted April 18, 2012 ну дык $ perl -e 'use Net::SNMP ; printf "-%s-\n", INTEGER' -2- $ perl -e 'use Net::SNMP qw(:snmp); printf "-%s-\n", INTEGER'- -INTEGER- константы то оно откуда возьмет ? Вставить ник Quote
Gunner Posted April 19, 2012 Author Posted April 19, 2012 Все заработало.Действительно не видело константы. Вставить ник Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.