需求
我们需要监控交换机warn以上级别的日志,只要有warn及以上级别的日志输入,就需要发送报警给运维,我们使用的监控平台是zabbix,所以监控就需要使用zabbix来实现,下面是配置方法,供各位参考。
交换机配置
交换机启动日志收集,配置日志信息发送到日志主机
1
2
3
4
|
info-center
enable
info-center
source
default channel 2 log state on
trap
state off debug state off
info-center loghost 10.1.13.70 channel 2
save
|
我用的交换机是h3c交换机,配置含义参考文档:http://www.h3c.com/cn/d_201803/1074113_30005_0.htm#_Toc509600226
其他厂商的交换机需要自己查询交换机文档进行配置。
zabbix服务器配置
服务器上启动rsyslog
1
|
yum -y
install
rsyslog
|
编辑配置文件:
/etc/rsyslogd.conf,添加以下内容
1
2
|
#switch warnings
local7.*
/var/log/h3c/information
|
重启rsyslog服务
1
|
service rsyslog restart
|
zabbix 配置文件设置
1
2
|
[root@zabbix zabbix_agentd.d]
# cat /etc/zabbix/zabbix_agentd.d/userparameter_sw_log.conf
UserParameter=switch_syslog,
/etc/zabbix/scripts/h3c/checklog
.sh
|
日志监控脚本设置
1
2
3
4
5
6
7
8
9
|
[root@zabbix zabbix_agentd.d]
# cat /etc/zabbix/scripts/h3c/checklog.sh
#!/bin/sh
key=`
cat
/var/log/h3c/information
|
grep
"warn"
|
grep
"TEMPERATUR"
|
awk
'{print $5"\t"$6}'
`
echo
$key
if
[ -s
/var/log/h3c/information
] ;
then
cat
/var/log/h3c/information
>>
/var/log/h3c/information_backup
echo
""
>
/var/log/h3c/information
fi
|
zabbix web配置
zabbix item设置
zabbix触发器设置
报警内容示例