這是我第一次使用SNMP,但在閱讀SNMP pages後,我仍然無法在接收陷阱時運行簡單的shell腳本。SNMP Traphandle不起作用
我/etc/snmp/snmptrapd.conf文件看起來像這樣:
# Example configuration file for snmptrapd
#
# No traps are handled by default, you must edit this file!
#
disableAuthorization yes
authCommunity log,execute,net public
# the generic traps
traphandle default /usr/local/bin/snmptrapd.sh
的snmptrapd.sh腳本只是說 「你好」。
> /usr/local/bin/snmptrapd.sh
hello
的snmptrapd運行作爲後臺進程:
> ps -ef | grep snmp
root 29477 1 0 14:49 ? 00:00:00 /usr/sbin/snmptrapd -Lsd -p /var/run/snmptrapd.pid -Cc /etc/snmp/snmptrapd.conf
可是當我發送一個陷阱本地使用SNMPTRAP當獨立執行
#!/bin/sh
echo "hello"
腳本是可執行文件並運行沒有任何反應:
> snmptrap -v 2c -c public localhost "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 123456
>
目前看來,陷阱不會記錄到日誌中,因爲系統日誌文件(在/ var/log/messages中)具有以下條目:
Aug 8 15:46:10 <server_name> snmptrapd[29477]: 2017-08-08 15:46:10 localhost
[UDP: [127.0.0.1]:44928->[127.0.0.1]]:#012DISMAN-EVENT-MIB::sysUpTimeInstance =
Timeticks: (1338382434) 154 days, 21:43:44.34#011SNMPv2-MIB::snmpTrapOID.0 =
OID: NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification#011NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatRate
= INTEGER: 123456
據我所看到的一切設置正確。如果是這樣,爲什麼陷阱處理不起作用,以及如何檢查陷阱爲什麼不觸發腳本?
在此先感謝。
編輯:當我加入的-C選項我得到了以下錯誤snmptrapd命令行選項:
No log handling enabled - turning on stderr logging
: Unknown Object Identifier (Sub-id not found: (top) ->)