一:本文目的

 通过计划任务每分钟执行一次检测脚本,把符合要求的内容发送至钉钉告警群。实际场景是,当常驻任务非running状态时,需及时发现,避免造成业务上的损失。

二:结果展示

运维自动化【把常驻列表里失败的任务发送至钉钉告警群】_sed

三:过程概述

当常驻列表存在stop和FATAL状态时,触发告警阈值,把相应的任务列表发送出来。

四:过程细节

1.脚本内容

#!/bin/bash
nodename=`hostname`
nodeip=`hostname -i`
time=`date '+%Y-%m-%d-%H:%M:%S'`
scriptname=$0
echo $scriptname

dingSendFunc(){
  echo $1 $2 $3 $4 $5 
  #cupli调试dignding告警群,关键字去群里看,发送时带上即可。
  url="https://oapi.dingtalk.com/robot/send?access_token=6b3b1cc5276ssss544e9053317b81d5a5d234xxxx57af971c20db2b4057ec279da2b5a3f51"
  curl $url \
   -H 'Content-Type: application/json' \
   -d '{
     "msgtype": "markdown",
     "markdown":
    {"title":"常驻任务失败告警",
    "text":"![screenshot](https://images.cnblogs.com/cnblogs_com/blogs/718800/galleries/2294157/o_230330085502_1.png) \n  
**报警时间**: <font color=\"#00100FF\">'${1}' '${times}'</font>\n
**监控ip**: <font color=\"#0100FF\">'${2}-${3}'  </font>\n
**失败任务列表:** <font color=\"#F30000\">'${4}' </font> \n
> 来自脚本的监控--'${5}'
"
         },
   }'
}
#钉钉发送告警函数 end .

num=`supervisorctl  status |grep FATAL |wc -l`
list=`supervisorctl  status |grep FATAL |awk '{print $1}' | tr '\n' ' ' |sed 's/ /-----/g'`
if [ $num -ne 0 ];then
    dingSendFunc $time  $nodename  $nodeip $list $scriptname
else
    echo "it is ok"
fi

2.执行方式

#crontab -l
#清理xxl-job日志
* * * * *  cd /opt/yunwei/script/ && /bin/bash checkout_superversion_list.sh

完!20240729