简单日志监控告警小脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单日志监控告警小脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#monitor tomcat_log
LOG_DIR=/root/catalina.out
IP=`ifconfig  | grep "inet addr" | grep Bcast | awk -F ‘[  :]+‘ ‘{print $4}‘`

tail -Fn0 $LOG_DIR| while read line;do
	echo $line | grep  -i  -f /root/errorword.txt >/dev/null
	if [ $? -eq 0 ];then
		echo -e "IP: $IP \n Datetime: $(date) \n Problem: $line" | mail -s "Warning:$IP Log Error " [email protected] 
		echo "$IP,$(date),$line" >>/var/log/error_report.log
		
	fi	
done

errorword.txt文件里可以存放常见错误关键词如:Out of memory,Error

日志监控工具可参考logstash或zabbix

本文出自 “Just be myself” 博客,请务必保留此出处http://liubin0505star.blog.51cto.com/5550456/1775110

以上是关于简单日志监控告警小脚本的主要内容,如果未能解决你的问题,请参考以下文章