基于AnolisOS 8.6安装SNMPTT

SNMPTT简介

SNMPTT是用perl写的SNMP trap处理器,它需要使用Net-SNMP/UCD-SNMP snmptrapd程序。使用SNMPTT的变量替换功能,消息可以变的更友好。SNMPTT可以将输出记录到日志,或者通过外部程序传给ZABBIX等监控系统。

测试环境

AnolisOS 8.6

安装SNMP

dnf install -y net-snmp net-snmp-utils net-snmp-perl

修改 snmptrapd.conf 配置文件,在末尾增加下面2行

vi /etc/snmp/snmptrapd.conf

disableAuthorization yes

traphandle default /usr/sbin/snmptthandler

启动服务

systemctl start snmptrapd

systemctl enable snmptrapd

安装依赖

dnf install -y net-snmp-perl

dnf install -y perl-Text-ParseWords perl-Config-IniFiles

dnf install -y perl-Time-HiRes perl-Text-Balanced perl-Net-IP

dnf install -y perl-Sys-Syslog perl-DBI perl-DBD-MySQL

dnf install -y perl-DBD-Pg perl-threads perl-Digest-MD5

安装SNMPTT

tar -xf snmptt_1.5.tgz

cd snmptt_1.5

cp snmptt /usr/sbin

cp snmptthandler /usr/sbin

mkdir /etc/snmptt

cp snmptt.ini /etc/snmptt/

cp snmptt.service /usr/lib/systemd/system/snmptt.service

cp examples/snmptt.conf.generic /etc/snmptt/snmptt.conf

chmod 755 /usr/sbin/snmptt

chmod 755 /usr/sbin/snmptthandler

mkdir /var/log/snmptt

vi /etc/snmptt/snmptt.ini

mibs_environment = ALL

log_system_enable=1

log_file= /var/log/snmptt/snmptt.log

date_time_format = %H:%M:%S %Y/%m/%d

net_snmp_perl_enable=1

adduser -s /sbin/nologin snmptt

chown -R snmptt.snmptt /etc/snmptt

chmod 750 /etc/snmptt

chown -R snmptt.snmptt /var/log/snmptt

chmod -R 750 /var/log/snmptt

mkdir /var/spool/snmptt/

chown -R snmptt.snmptt /var/spool/snmptt

chmod -R 750 /var/spool/snmptt

systemctl enable snmptt.service

systemctl start snmptt.service

测试1

执行cp,观察messages和snmptt.log的输出

cp examples/'#sample-trap.generic.daemon' /var/spool/snmptt/

tail -f /var/log/messages

Oct 11 07:24:12 node snmptt[837]: .1.3.6.1.6.3.1.1.5.3 Normal "Status Events" router01 - Link down on interface 3. Admin state: down. Operational state: testing

tail -f /var/log/snmptt/snmptt.log

22:06:35 2004/08/16 .1.3.6.1.6.3.1.1.5.3 Normal "Status Events" router01 - Link down on interface 3. Admin state: down. Operational state: testing

测试2

执行snmptrap,观察messages和snmptt.log的输出

snmptrap -v 2c -c public localhost "" .1.3.6.1.6.3.1.1.5.3 ifIndex i 2 ifAdminStatus i 1 ifOperStatus i 2

tail -f /var/log/messages

Oct 11 08:00:29 node snmptrapd[804]: 2024-10-11 08:00:29 localhost [UDP: [127.0.0.1]:45331->[127.0.0.1]:162]:#012DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (277560) 0:46:15.60#011SNMPv2-MIB::snmpTrapOID.0 = OID: IF-MIB::linkDown#011IF-MIB::ifIndex = INTEGER: 2#011IF-MIB::ifAdminStatus = INTEGER: up(1)#011IF-MIB::ifOperStatus = INTEGER: down(2)

Oct 11 08:00:29 node snmptt[1006]: .1.3.6.1.6.3.1.1.5.3 Normal "Status Events" localhost - Link down on interface 2. Admin state: up. Operational state: down

tail -f /var/log/snmptt/snmptt.log

08:00:29 2024/10/11 .1.3.6.1.6.3.1.1.5.3 Normal "Status Events" localhost - Link down on interface 2. Admin state: up. Operational state: down

补充

SNMPTT执行转换的配置,需要配置到下面这个文件

cat /etc/snmptt/snmptt.conf

EVENT linkDown .1.3.6.1.6.3.1.1.5.3 "Status Events" Normal

FORMAT Link down on interface 1. Admin state: 2. Operational state: $3

相关推荐
JuiceFS16 小时前
从 MLPerf Storage v2.0 看 AI 训练中的存储性能与扩展能力
运维·后端
chen9451 天前
mysql 3节点mgr集群部署
运维·后端
LH_R1 天前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler1 天前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
少妇的美梦2 天前
logstash教程
运维
chen9452 天前
k8s集群部署vector日志采集器
运维
chen9452 天前
aws ec2部署harbor,使用s3存储
运维
東雪蓮☆2 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_264220892 天前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
乌萨奇也要立志学C++2 天前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器