Alert email system, and alert system operation

Alert Mail System

Alert email system, and alert system operation
1. Copy the mail.py made before:

[root@weixing01 shares]# cp /usr/lib/zabbix/alertscripts/mail.py  ../mail/mail.py

2. Create 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. Run the alarm system

[root@weixing01 mail]# cd /usr/local/sbin/mon/bin/
[root@weixing01 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. Check the error log: Since there is no 502 file, an error is reported

[root@weixing01 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. After closing the detection 502, execute:

[root@weixing01 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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324793262&siteId=291194637