是否有通用的 Web 应用程序 MIB 允许通过 SNMP 陷阱发送自定义变量?
我正在寻找一个专为 Web 应用程序设计的管理信息库 (MIB)(注意:我正在使用 PHP),我可以通过 SNMP 陷阱将多个变量发送到我的网络管理系统。我是否必须设计一个或者已经有解决方案?
更多详细信息:
基本上,每当我的 Web 应用程序出现错误时,我都想向我的网络管理系统 (Zenoss) 发送陷阱。我想在 PHP 中调用它,如下所示(注意:此语法可能不正确):(
注意:显然,BOSSJONES-NOTIFICATION
不存在;我只是使用它对于这个例子,我想将其替换为我正在寻找的 MIB,或者需要设计的 MIB。)
<?php
const SNMPTRAP = '/usr/bin/snmptrap';
$host = 'zenoss.bossjones.com';
if ( some_random_error() ) {
exec( SNMPTRAP . ' -v 2c -c public -L e ' . $host .
' "" BOSSJONES-NOTIFICATION::snmpErrorNotification' .
' device s "192.168.1.121" errorType s "image upload fail"' .
' errorCode i 340 errorMessage s "Could not upload image at path' .
' /path/to/image/blah.gif" ' );
}
当然,我知道 MIB 可能没有相同的参数,但是我想知道是否有将军我可以“凑合使用”或从中学习,以便我可以创建自己的适合我的目的的解决方案?
另外,是否可以通过陷阱发送信息列表(如数组)而不仅仅是多个字符串?
抱歉问了这么长的问题。希望提供尽可能多的细节。
(PS:在 Ubuntu 11.04 Linux 机器上运行)
I'm looking for a Management Information Base (MIB) designed for web applications (Note: I'm working in PHP) that I can send multiple variables to my Network Management System via an SNMP Trap. Do I have to design one or is there a solution out there already?
More details:
Basically I want to send a trap to my Network Management System (Zenoss) whenever there is an error on my web application. I would like to call it in PHP like the following (note: this syntax might not be correct):
(Note: obviously, BOSSJONES-NOTIFICATION
does not exist; I'm just using it for this example. I'd like to replace it with the MIB I'm looking for, or the one that needs to be designed.)
<?php
const SNMPTRAP = '/usr/bin/snmptrap';
$host = 'zenoss.bossjones.com';
if ( some_random_error() ) {
exec( SNMPTRAP . ' -v 2c -c public -L e ' . $host .
' "" BOSSJONES-NOTIFICATION::snmpErrorNotification' .
' device s "192.168.1.121" errorType s "image upload fail"' .
' errorCode i 340 errorMessage s "Could not upload image at path' .
' /path/to/image/blah.gif" ' );
}
I understand that the MIB might not have the same parameters, of course, but I'm wondering if theres a general solution out there that I can either "make do with" or learn from, so that I can create my own that works for my purposes?
Also, is it possible to send a list of info (like an array) rather than just multiple strings via a trap?
Sorry for the long question. Wanted to provide as much details as possible.
(PS: Running on a Ubuntu 11.04 Linux box)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

此时我不会担心您的应用程序中的 MIB,因为您正在做的事情是轻量级的并且不公开。 MIB 只是一种数据结构/模式,它告诉公众谁使用您的 SNMP 产品、那些陷阱是什么等等。如果您只为自己使用它,我不会担心 MIB。我建议只使用 PHP SNMP 模块来启动您想要对您以前未使用过的任何 OID 执行的任何 SNMP 陷阱,然后确保您的网络管理软件知道这些 OID 的含义。当您的 NMS 获取带有 OID varbind 的 SNMP 陷阱时,您就会知道这些变量是什么,等等。请告诉我它是如何进行的。
PHP SNMP
对于你的第二个问题,你不能发送一组陷阱立刻。不过 SNMP 是如此轻量级,这对您来说应该不重要。如果你有一组陷阱,我会做的就是做一个 foreach 循环或迭代,然后遍历你的数组并一次发送一个陷阱,在那里你给出一个唯一的每个陷阱的 OID,以便您的 NMS 知道哪个陷阱字符串对应哪个 OID,以便在 NMS 端正确解释它。
SNMP是一个非常奇妙的协议,但是非常深奥。祝你一切顺利。
I wouldn't worry about a MIB at this point in your app, since what you're doing is lightweight and not public. A MIB is just a data structure/schema that tells the public who uses your SNMP product, what those Traps are, etc. If you're going to be using it only for yourself, I wouldn't worry about a MIB. I'd suggest just using the PHP SNMP module to kickoff any SNMP Traps you want to do with whatever OIDs aren't previously being used by you and then make sure that your network management software knows what those OIDs mean. When your NMS gets those SNMP traps with the OID varbinds, then you'll know what those variables are, etc. let me know how it goes.
PHP SNMP
For your second question, you can't send an array of traps at once. SNMP is so lightweight though, that this shouldn't matter for you. What I would do if you have an array of traps, is just do a foreach loop or something iterative, and just go through your array and send out the traps one at a time, where you give a unique OID for each trap so that your NMS knows what trap string is for what OID, so that it gets properly interpreted on the NMS side.
SNMP is a very wonderful protocol, but very esoteric. Be well.