Wednesday, March 11, 2020

How can I setup a snmptrap receiver server on Ubuntu Server 18.04?

之前有介紹過如何在Ubuntu Server 18.04建立一個SNMP agent讓SNMP Manager可以做get request的動作,請參考此篇: How can I setup a SNMP server on Ubuntu Server 18.04

現在來補足一下如何在Ubuntu Server 18.04實作snmptrap receiver server.

Step1. 安裝snmptrapd
$ sudo apt install snmptrapd
Step2. 配置snmptrpad可以接收agent送過來的event
$ vi /etc/snmp/snmptrapd.conf
authCommunity log,execute,net public
以上,我只開啟IPv4 + snmp version 2c

Step3. 重啟snmptrapd
$ sudo systemctl restart snmptrapd

Step4. 檢查port 162 active (UDP port 162是snmptrap, 161是snmp get,getnext,set)
$ sudo netstat -tupln | grep 162
udp        0      0 0.0.0.0:162             0.0.0.0:*                           2100/snmptrapd 
Step5. 遠端送出一個snmptrap的event
這裡我用CentOS8安裝Net-SNMP的基本工具snmptrap後,送出一個snmptrap example command.
# snmptrap -d -v 2c -c public 192.168.1.151 "" UCD-SNMP-MIB::ucdStart message s "/ disk utilization exceed 90%"
 Step6. 檢查Ubuntu Server 18.04有沒有收到此event?
$ sudo tail -f /var/log/syslog | grep snmptrap
Mar 11 16:07:06 us18 snmptrapd[2100]: 2020-03-11 16:07:06 [UDP: [192.168.1.132]:51067->[192.168.1.151]:162]:#012iso.3.6.1.2.1.1.3.0 = Timeticks: (194731) 0:32:27.31#011iso.3.6.1.6.3.1.1.4.1.0 = OID: iso.3.6.1.4.1.2021.251.1#011iso.3.6.1.4.1.2021.10.1.101 = STRING: "/ disk utilization exceed 90%"
That's all!

No comments: