【Zabbix4.2学习笔记】6、数据收集-SNMP Trap

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"
已经获取到数据

在这里插入图片描述
在这里插入图片描述

欢迎关注公众号。一起交流,学习

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章