釘釘建群
在釘釘對話框右上角點選加号,點選“發起群聊”:

點選“值班群”按紐:
拉群至少需要2個人:
添加群機器人
建群成功後,點選右上角的“群設定”按紐:
點選“智能群助手”:
點選“添加機器人”:
點選加号:“+”
點選“自定義”:
點選“添加”按紐:
勾選“自定義關鍵詞”,設定關鍵詞。
在發送的消息裡,必須帶有設定的關鍵詞,才能發送成功。
“Webhook”後面的位址,要寫進shell腳本:https://oapi.dingtalk.com/robot/send?access_token=76cef610145f21e790973cbbzzzzzzzzzzaea74926c665a476e17998b1425354
測試curl指令
curl 'https://oapi.dingtalk.com/robot/send?access_token=76cef610145f21e790973cbbzzzzzzzzzzaea74926c665a476e17998b1425354' \
-H 'Content-Type: application/json' \
-d '{"msgtype": "text",
"text": {
"content": "運維監控 中考分流贻害無窮"
}
}'
執行腳本結果:
腳本内容
[root@iZ2ze7ajq328l8q1ai15szhZ ~]# cat oldboy-44_5.sh
#!/bin/sh
netstat -an|grep "ESTABLISHED"|awk '{print $5}'|grep ":8848$"|sort|uniq -c >ip.txt
exec <ip.txt
while read line
do
IP_count=`echo $line|awk '{print $1}'`
IP=`echo $line|awk '{print $2}'|awk -F : '{print $1}'`
if [ $IP_count -ge 10 ]
then
curl 'https://oapi.dingtalk.com/robot/send?access_token=76cef610145f21e790973cbbzzzzzzzzzzaea74926c665a476e17998b1425354' \
-H 'Content-Type: application/json' \
-d "{'msgtype': 'text',
'text': {
'content': '運維監控\nIP位址:$IP請求$IP_count次'
}
}"
fi
done
[root@iZ2ze7ajq328l8q1ai15szhZ ~]# sh oldboy-44_5.sh
{"errcode":0,"errmsg":"ok"}{"errcode":0,"errmsg":"ok"}
執行腳本結果: