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

发布时间:2020-05-29 04:24:45 作者:airya
来源:网络 阅读:764

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监控项

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

在被监控端写入信息到服务端
[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"
最新数据已获取到数据

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

在被监控端,写入正则表达式所匹配的信息
[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"
已经获取到数据

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

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

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

推荐阅读:
  1. net-snmp 支持ipv6
  2. SNMP协议开发概念理解-1

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

zabbix nm nmp

上一篇:Nginx服务的rewrite模块(理论详解)

下一篇:大数据--流量埋点基础(一)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》