Anyevent::SNMP实例
发布时间:2020-12-16 00:10:25 所属栏目:大数据 来源:网络整理
导读:? 之前不知道为什么不成功. ?重新找了新环境.安装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 N
? 之前不知道为什么不成功. ?重新找了新环境.安装Net::SNMP和AnyevenSNMP AnyEvent-SNMP-6.0 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$ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |