千家信息网

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

发表于:2025-02-06 作者:千家信息网编辑
千家信息网最后更新 2025年02月06日,SNMP Trpe可以主动发信息推送给zabbix-server前提配置条件zabbix server端:1.需要支持SNMP,编译安装时--with-net-snmp2.zabbix server
千家信息网最后更新 2025年02月06日【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.gzcd zabbix-4.2.6cp 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 publicperl do "/usr/bin/zabbix_trap_receiver.pl"重启snmptrap服务systemctl restart snmptrapd.servicesystemctl enable snmptrapd.service更改zabbix server配置vim /etc/zabbix/zabbix_server.confSNMPTrapperFile=/tmp/zabbix_traps.tmpStartSNMPTrapper=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.134PDU 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                      199074524VARBINDS:  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"
已经获取到数据


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

0