美文网首页
shell通过钉钉报警

shell通过钉钉报警

作者: 随意人生_1b90 | 来源:发表于2019-03-13 16:21 被阅读0次

    # 内存使用率

    mem_total=`mcsadmin getSystemMemory | awk '{print $2}' | sed -n '$p'`

    mem_usage=`mcsadmin getSystemMemory | awk '{print $3}' | sed -n '$p'`

    usage_int=`expr $mem_usage \* 100 / $mem_total`;

    if [ 90 -lt $usage_int ]; then

        function SendMessageToDingding(){

            url="https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

            UA="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"

            res=`curl -XPOST -s -L -H "Content-Type:application/json" -H "charset:utf-8" $url -d "

            {

            \"msgtype\": \"text\",

            \"text\": {

                    \"content\": \"$1\n$2\n$3\"

                    }

        }"`

            echo $res

    }

    subject="xxx.xxx.xxx.xxx"

    boy="MemUsage大于90%"

    mem_total=`mcsadmin getSystemMemory | awk '{print $2}' | sed -n '$p'`

    mem_usage=`mcsadmin getSystemMemory | awk '{print $3}' | sed -n '$p'`

    usage_int=`expr $mem_usage \* 100 / $mem_total`;

    usage_float=`echo "scale=2;$mem_usage * 100 / $mem_total" | bc`

    SendMessageToDingding "Server:"$subject "警告:"$boy "Mem Usage:"$usage_float"%"

    fi

    脚本运行结果:

    相关文章

      网友评论

          本文标题:shell通过钉钉报警

          本文链接:https://www.haomeiwen.com/subject/svktmqtx.html