随手记录snmptrap

参考:https://blog.csdn.net/gui_ya/article/details/5774713

# 安装snmp
yum install net-snmp*
# 获取mib 文件对应目录
net-snmp-config  --default-mibdirs
# 将mib文件放到对应目录下

# 引入配置
# 例如 mib文件内容开头为: MTA-MIB DEFINITIONS ::= BEGIN  则引入方式如下
echo 'mibs +MTA-MIB' >> /etc/snmp/snmp.conf
# 调整snmptrapd service文件
cat /usr/lib/systemd/system/snmptrapd.service
[Unit]
Description=Simple Network Management Protocol (SNMP) Trap Daemon.
After=syslog.target network-online.target

[Service]
Type=notify
ExecStart=/usr/sbin/snmptrapd -C -c /etc/sysconfig/snmptrapd  -df -Lo
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
# 修改snmptrapd 配置文件
cat /etc/sysconfig/snmptrapd
traphandle default /bin/snmptrap.sh
authcommunity execute,log,net public
# 脚本内容
#!/bin/bash
read host
read ip
vars=
while read oid val
do
  if [ "$vars" = "" ]
  then
    vars="$oid = $val"
  else
    vars="$vars, $oid = $val"
  fi


done
ip=`echo $ip|awk -F'[' '{print $2}'|awk -F']' '{print $1}'`
echo trap: $ip $vars

# 启动服务
systemctl restart snmpd snmptrapd
# 查看日志
tail -f /var/log/messages
posted @ 2021-07-18 20:22  La0jin  阅读(87)  评论(0编辑  收藏  举报