我的 Perl 脚本如何从托管系统接收 SNMP 陷阱?

发布于 2024-10-08 09:12:47 字数 766 浏览 0 评论 0原文

我想执行以下操作,但我不确定我是否使用最好的方法:

在 Sparc/Solaris 10 计算机上运行的 perl 脚本应该等待传入的 SNMP 陷阱数据包(例如在端口 162 上)。当它收到陷阱时,应该对其进行解码并进行一些处理,然后继续等待下一个陷阱。

我研究过 David M. Town 的 Net::SNMP,但我认为它只允许发送请求和接收响应。我在本文档中找不到等待自发陷阱消息的方法: http://search.cpan.org/dist/Net-SNMP /lib/Net/SNMP.pm

另一方面,Net-SNMP 包似乎是一个非常强大且使用良好的库,但即使在那里,文档也没有为我提供清晰的路径。 SNMP::TrapSession 允许我发送陷阱,但不能接收它们(?)。

一些谷歌搜索让我建议我应该使用“snmptrapd”二进制文件并使用它的嵌入式 perl 函数,以便在 snmptrapd 收到消息时调用我的脚本。这可以工作,但不切实际,因为嵌入式 perl 选项需要编译没有大文件支持的 perl 二进制文件。我不拥有目标系统,因此无法替换编译器/解释器。我可以使用专门编译的 perl 来发布我的软件,但这会给我带来我希望避免的跨平台问题。

我使用 Perl 而不是使用 SNMP4J 或类似的 Java 的原因是,我有旧的 Perl 代码,这些代码以前依赖于 HP NNM 的 Perl API,并且我需要迁移到免费软件后端以消除许可成本。

I would like to do the following, but I'm not sure I'm using the best method:

A perl script, running on a Sparc/Solaris 10 machine, should wait for incoming SNMP trap packets (on port 162 for instance). When it receives a trap, it should decode it and do some processing on it, and then resume waiting for the next trap.

I've looked into Net::SNMP by David M. Town, but I think it only allows sending requests and receiving responses. I can't find a method to wait for spontaneous trap messages in this documentation:
http://search.cpan.org/dist/Net-SNMP/lib/Net/SNMP.pm

The Net-SNMP package, on the other hand, seems like a very robust and well-used library, but even there the documentation does not provide me with a clear path. SNMP::TrapSession allows me to send traps, but not receive them (?).

Some googling leads me to suggestiongs that I should use the "snmptrapd" binary and use the embedded perl functions of it, to call my script when snmptrapd receives a message. This could work, but would be impractical since the embedded perl option requires a perl binary compiled without large file support. I do not own the target system and hence cannot replace the compiler/interpreter. I could ship my software with a specially-compiled perl, but that would give me cross-platform issues I was hoping to avoid.

The reason I'm using Perl and not Java with SNMP4J or similar, is that I have legacy perl code which has previously depended on HP NNM's perl API, and I need to move to a free software back-end to eliminate the license cost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月无声 2024-10-15 09:12:47

使用 Perl 库 SNMP_Session.pm 解析 SNMP 陷阱的简单示例:基本 SNMP - 第 194 页

A simple example of using Perl library SNMP_Session.pm for parsing SNMP traps: Essential SNMP - page 194.

只是在用心讲痛 2024-10-15 09:12:47

您是否正在寻找一个库例程来接收和解析数据包?您可以自己侦听 UDP 数据包,然后将收到的任何数据包传递给 snmp 库来解析它们吗?这就是我正在做的事情,尽管我使用的是 python 而不是 perl。

Are you looking for a library routine to receive and parse the packet? Can you listen for UDP packets yourself and then pass any packets you receive to the snmp library to parse them? That's what I'm doing, though I am using python rather than perl.

李白 2024-10-15 09:12:47

如果您获得 SNMP_Session 库(顺便说一句,它完全是 Perl),您可以执行以下操作:

my $trap_session = SNMPv1_Session->open_trap_session ();
my ($trap, $sender_addr, $sender_port) = $trap_session->receive_trap ();
my @blah = $trap_session->decode_trap_request ($trap)

If you get the SNMP_Session library (which is entirely Perl btw) you can do things like this:

my $trap_session = SNMPv1_Session->open_trap_session ();
my ($trap, $sender_addr, $sender_port) = $trap_session->receive_trap ();
my @blah = $trap_session->decode_trap_request ($trap)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文