#!/bin/bash
source ~/.bash_profile
logfile=/tmp/rsync_dags.log
time=$(date “+%Y-%m-%d %H:%M:%S”)
webhook=’https://oapi.dingtalk.com/robot/send?access_token=4e13850af53becaa396694e4dq076d7feeecd7161c1ae3fec73036f263eb394c’
###webhook这个就是图五中要求复制下来的url
host=’spark001′
报警函数:
function SendMsgToDingding() {
curl $webhook -H ‘Content-Type: application/json’ -d ”
{
‘msgtype’: ‘text’,
‘text’: {
‘content’: ‘
时间:$time
服务器:$host
告警信息:rsync error报错$errorcount次
报错日志路径:[/tmp/rsync_dags.log]
报错脚本:[/home/admin/program/airflow/rsync_dags.sh]
请马上处理!!!’
#####content里的内容根据自己的报警内容编辑
},
‘at’: {
‘isAtAll’: true ###实现效果 @所有人
}
}”
}
errorcount=`egrep -i “rsync error” $logfile|wc -l`
if [ $errorcount -gt 0 ];
then
SendMsgToDingding
###如果符合报警条件就调用报警函数
fi
echo “$time rsync dags done.”
服务器租用托管,机房租用托管,主机租用托管,https://www.e1idc.com