服务监控报警
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了服务监控报警相关的知识,希望对你有一定的参考价值。
#!/bin/sh#auto service monitor
#by zkg 2019-07-15
echo -e "\033[32m \033[1m"
EMAIL=email.txt
DATE=date
M_IPADDR=ifconfig eth0|grep "Bcast"|awk ‘print $2‘|awk -F: ‘print $2‘
br/>MYEMAIL=allen.zhang@dbappsecurity.com.cn
cat << EOF
--------------服务监控报警----------------
EOF
echo -e "\033[32m \033[0m"
sleep 2
if [ -z $1 ];then
echo -e "\033[32musage: sh $0 nginx | mysql | list.txt \033[0m"
echo
exit
fi
if [ -f $1 -a "$1" == list.txt ];then
for i in cat list.txt
do
COUNT=ps -ef|grep $i|grep -v service|grep -v grep|wc -l
if [ "$COUNT" -eq 0 ];then
cat >$EMAIL <<EOF
*SERVICE MONITOR*****
通知类型:告警
服务:$i
主机:$M_IPADDR
状态:告警
日期/时间:$DATE
额外信息:
CRITICAL - SERVICE MONITOR:$i IS NOT RUN,PLEASE CHECK..
EOF
dos2unix $EMAIL >>/dev/null 2>&1
echo -e "\033[32mthe $i IS NOT RUN,PLEASE CHECK..\033[0m"
mail -s "$M_IPADDR $i warning" $MYEMAIL <$EMAIL >>/dev/null 2>&1
else
echo "the $i is server 200 ok"
fi
done
else
COUNT=ps -ef|grep $1|grep -v service|grep -v grep|wc -l
if [ "$COUNT" -eq 0 ];then
cat >$EMAIL <<EOF
*SERVICE MONITOR*****
通知类型:告警
服务:$1
主机:$M_IPADDR
状态:告警
日期/时间:$DATE
额外信息:
CRITICAL - SERVICE MONITOR:$1 IS NOT RUN,PLEASE CHECK..
EOF
dos2unix $EMAIL >>/dev/null 2>&1
echo -e "\033[32mthe $1 IS NOT RUN,PLEASE CHECK..\033[0m"
mail -s "$M_IPADDR $1 warning" $MYEMAIL <$EMAIL >>/dev/null 2>&1
else
echo "the $1 is server 200 ok"
fi
fi
以上是关于服务监控报警的主要内容,如果未能解决你的问题,请参考以下文章