使用Perl发送陷阱(net-snmp)

时间:2015-03-06 00:20:08

标签: perl snmp net-snmp snmp-trap

我运行snmptrapd并在通过snmptrap

发送陷阱时可以看到传入的陷阱
snmptrap -c public -v 2c localhost "" 1.3.3.3.3.3.3.3 1.2.2.2.2.2.2 s "Aliens here"

但是当我通过Perl脚本发送

时,我没有陷阱
use SNMP;

$sess = new SNMP::Session(DestHost => '127.0.0.1', RemotePort => "162" );

$sess->trap(enterprise=>'.1.3.6.1.4.1.2021', # or 'ucdavis' [default]
                agent => '127.0.0.1', # or 'localhost',[dflt 1st intf on host]
                generic => specific,  # can be omitted if 'specific' supplied
                specific => 5,        # can be omitted if 'generic' supplied
                uptime => 1234,       # dflt to localhost uptime (0 on win32)
                [[ifIndex, 1, 1],[sysLocation, 0, "here"]]);

怎么了?

1 个答案:

答案 0 :(得分:1)

您的第二个版本,即perl版本未指定社区或版本,与第一个版本不同。尝试添加它们

$sess = new SNMP::Session(DestHost => '127.0.0.1', 
                                      RemotePort => "162",
                                      Community => "public,
                                      Version => 2);

另见http://www.remothelast.altervista.org/SNMP_Perl.htmlhttp://www.net-snmp.org/docs/perl-SNMP-README.html用于SNMP ::会话使用。