zoukankan      html  css  js  c++  java
  • 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这个关键词

    图五

  • 相关阅读:
    check2
    LYF模板连接.txt
    mvc中的表现和数据分离怎么理解?
    node中websocket的使用
    vue随笔
    python安装Django常见错误
    node中的session的使用
    为什么很多IT公司不喜欢进过培训机构的人呢
    vue数据交互
    vuecli的服务代理
  • 原文地址:https://www.cnblogs.com/xuziyu/p/12190347.html
Copyright © 2011-2022 走看看