SNMPTRAP is only working when I execute the command in the instance where the telegraph is located.
Config:
[[inputs.snmp_trap]]
service_address = "udp://:162"
## Path to mib files
path = ["/usr/share/snmp/mibs"]
## Snmp version
version = "3"
sec_name = "telegraf_trap"
auth_protocol = "MD5"
auth_password = "123$42256"
sec_level = "authNoPriv"
Test:
[root@hci-mtl2-collector01 telegraf]# telegraf --config /root/snmp_trap.conf --test-wait 600
2024-05-10T18:39:29Z I! Loading config: /root/snmp_trap.conf
2024-05-10T18:39:29Z W! DeprecationWarning: Option “timeout” of plugin “inputs.snmp_trap” deprecated since version 1.20.0 and will be removed in 2.0.0: unused option
2024-05-10T18:39:29Z I! Starting Telegraf 1.28.5 brought to you by InfluxData the makers of InfluxDB
2024-05-10T18:39:29Z I! Available plugins: 240 inputs, 9 aggregators, 29 processors, 24 parsers, 59 outputs, 5 secret-stores
2024-05-10T18:39:29Z I! Loaded inputs: snmp_trap
2024-05-10T18:39:29Z I! Loaded aggregators:
2024-05-10T18:39:29Z I! Loaded processors:
2024-05-10T18:39:29Z I! Loaded secretstores:
2024-05-10T18:39:29Z W! Outputs are not used in testing mode!
2024-05-10T18:39:29Z I! Tags enabled: host=hci-mtl2-collector01
2024-05-10T18:39:29Z W! Deprecated inputs: 0 and 1 options
2024-05-10T18:39:29Z I! [inputs.snmp_trap] Listening on udp://:162
Command:
snmptrap -v3 -l authnoPriv -u telegraf_trap -A '123$42256' -a MD5 -n "" udp:172.27.0.52:162 '' 1.3.6.1.4.1.1234.1 1.3.6.1.4.1.1234.1.1 s "test trap"
tcpdump:
[root@hci-mtl2-collector01 telegraf.d]# tcpdump -vvvv -i eth0 udp port 162
dropped privs to tcpdump
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
14:44:31.209020 IP (tos 0x0, ttl 63, id 44599, offset 0, flags [DF], proto UDP (17), length 218)
172.27.2.91.40400 > hci-mtl2-collector01.snmptrap: [udp sum ok] { SNMPv3 { F=a } { USM B=1 T=0 U=“telegraf_trap” } { ScopedPDU E=_80_00_1f_88_80_31_3c_17_6d_0f_6b_3e_66_00_00_00_00 C=“” { V2Trap(80) R=2128788058 system.sysUpTime.0=734344033 S:1.1.4.1.0=E:1234.1 E:1234.1.1=“test trap” } } }
No information is received by the snmp trap.
below a local test.
Test running on the server where telegraf is located:
Result:
> snmp_trap,engine_id=80001f88808f0d391f85223d6600000000,host=hci-mtl2-collector01,mib=SNMPv2-SMI,name=enterprises.1234.1,oid=.1.3.6.1.4.1.1234.1,source=172.27.0.52,version=3 enterprises.1234.1.1="test trap",sysUpTimeInstance=2870519942i 1715366897175785967