码迷,mamicode.com
首页 > 其他好文 > 详细

服务监控报警

时间:2019-08-01 09:17:51      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:critical   server   null   bin   gre   monitor   ica   mail   moni   

#!/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

服务监控报警

标签:critical   server   null   bin   gre   monitor   ica   mail   moni   

原文地址:https://blog.51cto.com/1009516/2425466

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!