shell腳本設置釘釘告警模板


 

shell腳本模板

#!/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."

 

 

 

運行效果如下圖:

圖一

下面是創建釘釘機器人的步驟:

圖二

圖三

圖四

注解:比如我的自定義關鍵詞是error,那么在我的content內容中,一定要包含error這個關鍵詞

圖五


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM