snmptrapd+snmptt接收告警并用py脚本发送​

网友投稿 1291 2022-08-30

snmptrapd+snmptt接收告警并用py脚本发送​

snmptrapd+snmptt接收告警并用py脚本发送​

本文是使用snmptrapd+snmptt接收商业软件动环(主动)发来的告警,并用py脚本解析后再自定义发送给项目组成员;​

SNMP trap(SNMP 陷阱):某种入口,到达该入口会使SNMP被管设备主动通知SNMP管理器,而不是等待SNMP管理器的再次轮询。​

SNMP Trap是SNMP的一部分,当被监控段出现特定事件,可能是性能问题,甚至是网络设备接口宕掉等,代理端会给管理站发告警事件。假如在特定事件出现的时刻,不是由 Agent主动通知NMS,那么NMS必须不断地对Agent进行轮询。这是非常浪费计算资源的方法,正如人们用中断通知CPU数据的到达,而不是让CPU进行轮询一样。Trap 通知是更加合理的选择。用一句话来说的话,SNMP Trap就是被管理设备主动发送消息给NMS的一种机制。 ​

]# cat /etc/redhat-release ​

CentOS Linux release 7.9.2009 (Core)​

]# yum install -y net-snmp net-snmp-utils​

]# yum -y install snmptt perl-Sys-Syslog​

]# vim /usr/lib/systemd/system/snmptrapd.service​

ExecStart=/usr/sbin/snmptrapd $OPTIONS -f -O n表示print OIDs numerically​

]# vim /etc/snmp/snmptrapd.conf ​

# authCommunity execute public​

disableAuthorization yes​

traphandle default /sbin/snmptthandler​

systemctl enable snmptrapd|snmptt​

systemctl start snmptrapd|snmptt​

#] netstat -unlp | grep 162

]# vim /etc/snmp/snmptt.ini​

mode = daemon​

date_time_format = %Y-%m-%d %H:%M:%S​

snmptt_conf_files = <

#/etc/snmp/snmptt.conf默认格式化配置​

/etc/snmp/infrastructure.conf # 自定义配置,用于格式化trap日志​

END​

]# vim /etc/snmp/infrastructure.conf​

#​

EVENT general .* "infrastructure_trap" Error​

FORMAT "infrastructure_trap" $ar $+*​

EXEC /usr/bin/python3 /data/app/yto_monitor/zabbix/bin/infra_alarm.py "$ar $+*" >> /tmp/infra_alarm_debug.log​

]# snmptrap -v 2c -c public 127.0.0.1 "" 1.3.6.1.4.1.93450.3.93451.1.1 1.3.6.1.4.1.93450.3.93451.1.1 s "tempOid" 1.3.6.1.4.1.93450.3.93451.1.2 s "uniqueId" 1.3.6.1.4.1.93450.3.93451.1.3 s "eventLevel" 1.3.6.1.4.1.93450.3.93451.1.4 s "startTime"​

]# cat /var/log/snmptt/snmptt.log ​

2021-05-18 13:23:44 .1.3.6.1.4.1.93450.3.93451.1.1 Critical "infrastructure_alarm" localhost - "alarm_content" 127.0.0.1 .1.3.6.1.4.1.93450.3.93451.1.1:tempOid .1.3.6.1.4.1.93450.3.93451.1.2:uniqueId .1.3.6.1.4.1.93450.3.93451.1.3:eventLevel .1.3.6.1.4.1.93450.3.93451.1.4:startTime​

py脚本“/data/app/yto_monitor/zabbix/bin/infra_alarm.py”请留言邮箱地址,有空了会发送的。

该脚本主要解析报文和自定义告警(结合django)

以下是snmp相关的知识

snmpttconvertmib --in=alarm.mib --out=snmptt.conf.infrastructure​

oidview工具:​

查看MIB库;​

确认哪些字段是可写的(蓝底可写);​

SNMP7种武器:​

前5种由manager-->agent发起请求;​

第6种trap,由agent-->manager发数据,单向udp发送,没有确认(有可能丢数据);一般用syslog的trap,另snmptrap;​

第7种InformRequest,trap的升级版,增加了确认;​

所有get(包括单一get|SetRequest|GetNextRequest|GetBulkRequest|InformRequest)都由response响应;​

​​https://bbs.csdn-/topics/391964541?page=1​​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Iptables防火墙iprange模块扩展匹配规则
下一篇:MySQL索引优化(mysql索引优化级别)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~