Anyevent::SNMP实例

前端之家收集整理的这篇文章主要介绍了Anyevent::SNMP实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

  之前不知道为什么不成功.

 重新找了新环境.安装Net::SNMP和AnyevenSNMP

AnyEvent-SNMP-6.0
Net-SNMP-5.2.0
Net-SNMP-v6.0.1

Net-SNMP5.2的版本获取有问题,不过不影响使用.

use strict;

 use AnyEvent::SNMP;
 use Net::SNMP;
 use Data::Dumper;


 # just use Net::SNMP and AnyEvent as you like:

 # use a condvar to transfer results,this is
 # just an example,you can use a naked callback as well.
 my $cv = AnyEvent->condvar;
$oid=".1.3.6.1.2.1.1.1.0";
 # ... start non-blocking snmp request(s)...
 Net::SNMP->session (-hostname => "192.168.6.25",-community => "public",-nonblocking => 1)
                     
         ->get_request (
             -varbindlist => [ $oid ],-callback => sub { $cv->send (@_) }
          );

 # ... do something else until the result is required
 my @result = $cv->wait;
 
  my ($session) = @result;
 my $result = $session->var_bind_list();

      if (!defined $result) {
         printf "ERROR: Get request Failed for host '%s': %s.\n",$session->hostname(),$session->error();
                
      }

      printf "The sysDescr for host '%s' is %s.\n",$result->{$oid};
#-bash-3.2$ perl aesnmp.pl
#The sysUpTime for host '192.168.6.25' is SunOS T51401OQ 5.10 Generic_138888-07 sun4v.
#-bash-3.2$

猜你在找的Perl相关文章