【问题标题】:Send trap with Perl (net-snmp)使用 Perl (net-snmp) 发送陷阱
【发布时间】:2015-03-06 00:20:08
【问题描述】:

我运行 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"]]);

怎么了?

【问题讨论】:

  • 我不熟悉 SNMP 陷阱,但是您的 snmptrap 看起来与您的 perl 等效项不同 - RemotePort 在哪里,.1.3.6.1.4.1.20211.3.3.3.3.3.3.3 1.2.2.2.2.2.2 的关系如何?
  • 在第一个 snmptrap 的默认目标端口是 162 所以不要认为这个问题,并且提问者说第一个好的。此外,不同的 OID .1.3.6.1.4.1.2021 与 1.3.3.3.3.3.3.3 1.2.2.2.2.2.2 应该(!)无关紧要,而且似乎存在更基本的通信问题。
  • 使用Wireshark或tcpdump之类的工具,检查出接口的流量,看数据包是否真的发送。如果是,检查是否到达接收端。

标签: perl snmp net-snmp snmp-trap


【解决方案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::Session 使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    相关资源
    最近更新 更多