#!/bin/bash ls /var/run/supervisor/supervisor.sock >/dev/null 2>&1 if [ $? -eq 0 ];then ip=`ifconfig eth0 | grep "netmask" | awk '{ print $2}'` file=/tmp/"$ip" old_file=/tmp/old_"$ip" instance=`cat /tmp/instance` ls $file >/dev/null 2>&1 if [ $? -ne 0 ];then touch "$file" fi \cp $file $old_file #supervisorctl status | grep -v RUNNING | grep -v STARTING | grep -v STOPPED | awk '{print $1"的状态为:"$2}' > "$file" supervisorctl status | grep -v RUNNING | grep -v STARTING| awk '{print $1"的状态为:"$2}' > "$file" new_num=`cat "$file" | wc -l` for a in `seq "$new_num"`;do new_process="$new_process"\\n`cat "$file" | sed -n "$a"p | awk -F'的' '{print $1}'` done num=`cat "$old_file" | wc -l` for i in `seq "$num"`;do process=`cat "$old_file" | sed -n "$i"p | awk -F'的' '{print $1}'` echo -e "$new_process" | grep -w "$process" if [ $? -ne 0 ];then p_sta=`supervisorctl status "$process" | awk '{print $2}'` if [ "$p_sta" = "ERROR" ];then content=""$content"\\n"$process"已被手动下线" else content=""$content"\\n"$process"当前的状态为:"$p_sta"" fi fi done if [ -n "$content" ];then content=`echo "$content" | sed 's/^..//g'` echo $content #以下地址为grafana告警这个群 curl 'https://oapi.dingtalk.com/robot/send?access_token=6d002d3492a42b66134c8d46cfbf49783d6d9d373895c59282ae98573f5fd49c' -H 'Content-Type: application/json' -d '{"msgtype":"text","text":{"content":"恢复 实例: '$ip' | '$instance' 以下supervisor进程已恢复: '$content'"}}' fi if [ -s $file ];then sta=`sed ":a;N;s/\n/\\\\\\\n/g;ta" "$file"` #以下地址为grafana报警这个群 curl 'https://oapi.dingtalk.com/robot/send?access_token=6d002d3492a42b66134c8d46cfbf49783d6d9d373895c59282ae98573f5fd49c' -H 'Content-Type: application/json' -d '{"msgtype":"text","text":{"content":"告警 实例: '$ip' | '$instance' 以下supervisor进程异常: '$sta'"}}' fi fi add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, No-Cache,Access-Control-Allow-Headers, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control,Expires, Content-Type, X-E4M-With, X-CSRF-TOKEN, Accept, Session-Id' always;