当前位置: 首页 > Linux

Nginx日志警告(疑似攻击请求)通过钉钉机器人

时间:2023-04-06 21:22:48 Linux

1.首先,在钉钉上创建一个群聊。直接替换下面curl请求中的xxxxxx。3、直接运行脚本,开始监控告警信息。以下是脚本代码while:doformatDate=`date"+%d/%b/%Y:%H:%M"|cat`;formatDate=`echo${formatDate%?}`agoformatDate=`date-d"10分钟前""+%d/%b/%Y:%H:%M"|cat`;agoformatDate=`echo${agoformatDate%?}`#echo${formatDate}\|${agoformatDate}log=`tail-1000access.log|grep-E${formatDate}\|${agoformatDate}|grep-v"/logrule"`#echo$loglogLength=`exprlength"$log"`;#echo$logLength;if[$logLength-gt50];thenecho"日志长度大于50,表示有为疑似攻击请求,发送钉钉警告信息";curl-i-k-H"Content-type:application/json"-XPOST-d'{"msgtype":"text","text":{"content":"疑似攻击请求,请处理"}}'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxfisleep600;done