Linux SNMP陷阱不工作
这是我第一次使用SNMP,但是在阅读了之后,我仍然无法在收到陷阱时运行一个简单的shell脚本 我的/etc/snmp/snmptrapd.conf文件如下所示:Linux SNMP陷阱不工作,linux,snmp,snmp-trap,Linux,Snmp,Snmp Trap,这是我第一次使用SNMP,但是在阅读了之后,我仍然无法在收到陷阱时运行一个简单的shell脚本 我的/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
# 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在本地发送陷阱时,什么也没有发生:
> 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
好的,我又看了一遍,找到了答案 我们没有看到输出的原因是snmptrapd作为守护进程运行,没有将其标准输出发送到控制台。我们可以用
echo "hello" > $HOME/output.txt
“hello”一词出现在output.txt文件中
另见
和
No log handling enabled - turning on stderr logging
: Unknown Object Identifier (Sub-id not found: (top) -> )
echo "hello" > $HOME/output.txt