DEV Community

Alfredcl
Alfredcl

Posted on

端口监控电话告警脚本

先说说需求。
针对于某个应用集群,集群中有3台机器,任一台上的服务端口死掉(这里拿zabbix服务作为示例)都要立即电话告警出来.
这里用到的电话告警媒介是国内的喵提醒。

#!/bin/sh
IP="10.161.11.x 10.161.11.xx 10.161.11.xxx"
LOCK_FILE="/root/lockfile.txt"
rm -f /root/zabbix_status.txt
for target in $IP
do
    nmap -p 10050 $target|grep open|awk '{print $2}' >> zabbix_status.txt
done

if [ `cat zabbix_status.txt|grep open|wc -l` == 3  ]; then
    echo "All zabbix_agent are ok!"
    rm -f $LOCK_FILE
else
    if [ -f "$LOCK_FILE" ]; then
        echo "zabbix is still down,won't make call again"
        exit 0
    else
        curl http://miaotixing.com/trigger?id=xxxxxxx
        touch $LOCK_FILE
    fi
fi
Enter fullscreen mode Exit fullscreen mode

Top comments (0)