1、首先在钉钉上建设一个群聊
2、群设置 -> 智能群助手 -> 增加机器人 -> 获取Webhook,其中的access_token参数能够间接替换上面curl申请的xxxxxx。
3、间接运行脚本,开始监听预警信息
上面是脚本代码
while :doformatDate=`date "+%d/%b/%Y:%H:%M" | cat`;formatDate=`echo ${formatDate%?}`agoformatDate=`date -d "10 minute ago" "+%d/%b/%Y:%H:%M" | cat`;agoformatDate=`echo ${agoformatDate%?}`#echo ${formatDate}\|${agoformatDate}log=`tail -1000 access.log | grep -E ${formatDate}\|${agoformatDate} | grep -v "/日志规定"`#echo $loglogLength=`expr length "$log"`;#echo $logLength;if [ $logLength -gt 50 ];thenecho "日志长度大于50,代表有疑似攻打申请,发送钉钉预警音讯";curl -i -k -H "Content-type: application/json" -X POST -d '{"msgtype": "text", "text": {"content": "疑似攻打申请,请解决" }}' https://oapi.dingtalk.com/robot/send?access_token=xxxxxxfisleep 600;done