告警邮件系统,以及告警系统运行
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了告警邮件系统,以及告警系统运行相关的知识,希望对你有一定的参考价值。
告警邮件系统
1.把之前做的mail.py复制过来:
[[email protected] shares]# cp /usr/lib/zabbix/alertscripts/mail.py ../mail/mail.py
2.创建mail.sh
log=$1
t_s=`date +%s`
t_s2=`date -d "2 hours ago" +%s`
if [ ! -f /tmp/$log ]
then
echo $t_s2 > /tmp/$log
fi
t_s2=`tail -1 /tmp/$log|awk ‘{print $1}‘`
echo $t_s>>/tmp/$log
v=$[$t_s-$t_s2]
echo $v
if [ $v -gt 3600 ]
then
./mail.py $1 $2 $3
echo "0" > /tmp/$log.txt
else
if [ ! -f /tmp/$log.txt ]
then
echo "0" > /tmp/$log.txt
fi
nu=`cat /tmp/$log.txt`
nu2=$[$nu+1]
echo $nu2>/tmp/$log.txt
if [ $nu2 -gt 10 ]
then
./mail.py $1 "trouble continue 10 min $2" "$3"
echo "0" > /tmp/$log.txt
fi
fi??
2.运行告警系统
[[email protected] mail]# cd /usr/local/sbin/mon/bin/
[[email protected] bin]# sh -x main.sh
+ export send=1
+ send=1
++ /sbin/ifconfig
++ grep -A1 ‘ens33: ‘
++ awk ‘/inet/ {print $2}‘
+ export addr=192.168.188.130
+ addr=192.168.188.130
++ pwd
+ dir=/usr/local/sbin/mon/bin
++ echo /usr/local/sbin/mon/bin
++ awk -F/ ‘{print $NF}‘
+ last_dir=bin
+ ‘[‘ bin == bin ‘]‘
+ conf_file=../conf/mon.conf
+ exec
3.查看错误日志:由于并没有502文件,所以报错
[[email protected] bin]# cat ../log/err.log
++ date ‘+%F %T‘
+ echo ‘2018-04-24 21:57:34 load average‘
+ /bin/bash ../shares/load.sh
+ grep -q to_mon_502=1 ../conf/mon.conf
++ awk -F = ‘{print $2}‘
++ sed ‘s/ //g‘
++ grep logfile= ../conf/mon.conf
+ export log=/data/log/xxx.xxx.com/access.log
+ log=/data/log/xxx.xxx.com/access.log
+ $‘/bin/bash\302\240\302\240../shares/502.sh‘
main.sh:行23: /bin/bash??../shares/502.sh: 没有那个文件或目录
4.关闭检测502后执行:
[[email protected] bin]# sh -x main.sh
+ export send=1
+ send=1
++ grep -A1 ‘ens33: ‘
++ awk ‘/inet/ {print $2}‘
++ /sbin/ifconfig
+ export addr=192.168.188.130
+ addr=192.168.188.130
++ pwd
+ dir=/usr/local/sbin/mon/bin
++ echo /usr/local/sbin/mon/bin
++ awk -F/ ‘{print $NF}‘
+ last_dir=bin
+ ‘[‘ bin == bin ‘]‘
+ conf_file=../conf/mon.conf
++ date ‘+%F %T‘
+ echo ‘2018-04-24 22:00:53 load average‘
2018-04-24 22:00:53 load average
+ /bin/bash ../shares/load.sh
22:00:53 load is 0
+ grep -q to_mon_502=1 ../conf/mon.conf
以上是关于告警邮件系统,以及告警系统运行的主要内容,如果未能解决你的问题,请参考以下文章