SNMP Trpe可以主動發信息推送給zabbix-server
前提配置條件
zabbix server端:
1.需要支持SNMP,編譯安裝時--with-net-snmp
2.zabbix server 配置StartSNMPTrapper和SNMPTrapperFile
3.配置SNMPTT服務
4.配置Perl trap receiver
5.允許161,162端口udp通信
被監控設備:
1.配置SNMP Trap信息發送
2.允許zabbix server和被監控設備的161,162端口udp通信
數據收集流程
被監控設備觸發事件 >>>(通過162端口)>>> SNMPTrapd(trap服務) >>> SNMPTT(進行格式化處理)>>>(寫入對應的日誌文件)>>> SNMP Trapper File <<< zabbix server (Trap進程)讀取信息。並和對應的監控設備進行匹配,如果有告警規則就會觸發告警
語法
snmptrap[regexp] 獲取匹配正則表達式指定的trap信息,如果正則沒有指定,就匹配所有Trap信息
snmptrap.fallback 獲取未被上個監控項。所匹配其他所有的Trap信息
zabbix-server 配置
安裝snmp trap 服務
yum -y install net-snmp net-snmp-utils net-snmp-perl
下載zabbix官方提供的zabbix_trap_receiver腳本,並移動到/usr/bin目錄下
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.2.6/zabbix-4.2.6.tar.gz
tar -zxvf zabbix-4.2.6.tar.gz
cd zabbix-4.2.6
cp misc/snmptrap/zabbix_trap_receiver.pl /usr/bin/
chmod a+x /usr/bin/zabbix_trap_receiver.pl
配置snmp trap 服務
vim /etc/snmp/snmptrapd.conf
加入
authCommunity log,execute,net public
perl do "/usr/bin/zabbix_trap_receiver.pl"
重啓snmptrap服務
systemctl restart snmptrapd.service
systemctl enable snmptrapd.service
更改zabbix server配置
vim /etc/zabbix/zabbix_server.conf
SNMPTrapperFile=/tmp/zabbix_traps.tmp
StartSNMPTrapper=1
重啓服務
systemctl restart zabbix-server
被監控端配置
由於沒有網絡設備,在linux端安裝snmp命令演示
yum -y install net-snmp-utils
測試是否能在被監控端發送信息到snmptrap服務端
snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
在服務端查看/tmp/zabbix_traps.tmp文件是否有寫入數據
more /tmp/zabbix_traps.tmp
00:53:36 2019/09/10 ZBXTRAP 192.168.146.134
PDU INFO:
notificationtype TRAP
version 1
receivedfrom UDP: [192.168.146.134]:51439->[192.168.146.133]:162
errorstatus 0
messageid 0
community public
transactionid 1
errorindex 0
requestid 199074524
VARBINDS:
SNMPv2-MIB::snmpTrapOID.0 type=6 value=OID: SNMPv2-SMI::org.4.1.4.1.47
SNMPv2-MIB::sysName.0 type=4 value=STRING: "SNMP Trap Test"
登錄zabbix web界面創建SNMPTrap監控項
在被監控端寫入信息到服務端
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test"
最新數據已獲取到數據
在被監控端,寫入正則表達式所匹配的信息
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test linuxcs"
[root@localhost ~]# snmptrap -v 2c -c public 192.168.146.133 "snmptraptest" '1.3.4.1.4.1.47' SNMPv2-MIB::sysName.0 s "SNMP Trap Test linuxcs"
已經獲取到數據
歡迎關注公衆號。一起交流,學習