[root@aliyun-cloud scripts]# cat web_code.sh #!/bin/bash#WEB状态码监控source /etc/profileurl=http://127.0.0.1:9999/user/getNewPublicKey?loginType=1webhook="https://oapi.dingtalk.com/robot/send?access_token=4d15f6354cdddf9498f90131084c72e32e1bc3e028df8e8ae11201392b672840"Hostname=${hostname}#Host_IP=`hostname -i|awk -F " " '{print $1}'`Host_IP=`/usr/sbin/ip a | grep inet | grep -v inet6 | grep -v '127.0.0.1' | awk '{print $2}' | awk -F / '{print$1}'`Hostname=`hostname`Time=`date '+%F %T'`function SendMsgToDingding() { curl $webhook -H 'Content-Type: application/json' -d " { 'msgtype': 'text', 'text': { 'content': '告警主题:${Name}-WEB状态码监控 \n钉钉关键字: 1 \n告警时间: $Time \n告警主机名: $Hostname \n主机IP列表: ${Host_IP} \n当前监控指标: $Status_Code \n日志: 服务器异常,请尽快排查异常...\n' }, 'at': { 'isAtAll': false } }"}Status_Code=`curl -I -m 3 -o /dev/null -s -w %{http_code} $url`docker_status=`docker ps |grep esl_app_1|wc -l`if [[ "$Status_Code" -ne 200 ]] then SendMsgToDingding if [[ "$docker_status" -ne 1 ]];then echo "Restart esl_app_1" docker restart esl_app_1 else exit -1 fi else echo "正常" >/dev/null 2>&1fi