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