天天看點

windows 下怎樣利用NET-SNMP 發送和接收trap

NET-SNMP 提供了兩個工具來發送和接收trap,

* 用NET-SNMP如何發送trap?

snmptrap 發送trap,具體用法:

snmptrap -v 1 -c public -d localhost enterprise-oid agent trap-type specific-type uptime [OID TYPE VALUE]

agnet : 發送方位址

trap-type : 0 , coldstart; 1, warstart;2, linkdown; 3, linkup; 4,authentication failure;5,neighbor loss,6,enterprise specific.

具體例子:

snmptrap -v 1 -c public -d localhost DAP-2590-v111:dap2590 192.168.0.25 1 0 DAP-2590-v111:wirelessLanIfDesc

 s mytest

* 用NET-SNMP如何捕捉trap?

 ** 怎樣讓net-snmp收到trap?

  C:/Program Files/Net-SNMP/usr/bin>snmptrapd -f -Le -d

 執行之後NET-SNMP開始接收trap,注意這是debug模式,會将收到的trap包内容列印出。

 ** 碰到錯誤couldn't open udp:162 -- errno 2 ("No such file or directory")?

  碰到此錯誤很可能是有程式占用了windows的SNMP接受端口(162)。用下面指令來找出占用此端口的程序。

  netstat -ano|find "162"

  如果有輸出則最後一個數字是程序号。從微軟免費下一個Process Explorer,找出占用該端口的程序,決定是否停掉。

  ** 碰到錯誤 Warning: no access control information configured. This receiver will *NOT* accept any incoming notifications.

  沒有設定通路控制的情況下NET-SNMP對所有的進入trap都丢掉。因為一個snmp manager可能收到大量的trap而其中隻有一小部分是真正需要處理的。具體設定可以通過net-snmp安裝目錄下的bin/snmpconf.bat來實作(用此方法需要保證計算機上已安裝ActivePerl);或者參照docs/Net-SNMP.chm->configuratoin->snmptrapd.conf->Access Control中的描述來手工修改。

 **舉例,最簡單的設定的步驟(對所有的都不丢):

 1.建一個snmptrapd.conf并在此檔案中加入下面這行配置。

  disableAuthorization yes

  2. 在運作snmptrapd的時候加入讀取配置檔案的參數。e.g.

  C:/Program Files/Net-SNMP/usr/bin>snmptrapd -c "C:/Program Files/Net-SNMP/usr/bin/snmptrapd.conf" -f -Le -d

 現在收到trap之後,會發現消息已經被盡可能地解開。

* 如何調用其他windows程式來處理net-snmp捕捉到的trap?

  1.在上面生成的檔案中,加入下面配置

 traphandle  default <program>

**舉例: