Created
February 1, 2012 22:06
-
-
Save evan4498/1719772 to your computer and use it in GitHub Desktop.
Script for monitoring graylog2 log file and restarting service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# File: logmon.sh | |
# Description: Restart graylog2 if the error message is found in the current log file. | |
# | |
# History: | |
# Date Author Comment | |
# 2012-02-01 Evan Ochs initial version | |
# | |
#Log file to monitor | |
LOGFILE="/service/graylog2/log/main/current" | |
#Error message to watch for | |
ERRORMSG="WARN : org.graylog2.periodical.MessageCountWriterThread - Error in MessageCountWriterThread: null" | |
#Server hostname | |
HOSTSERVER=$(hostname) | |
#Tail the log file, following inode changes for log rotation | |
#Only check the last line, so we don't restart off of earlier errors | |
tail -n1 -F $LOGFILE |while read LINE | |
do | |
#If the line contains the error, restart graylog2 and wait 30 seconds | |
echo $LINE | |
if [[ "$LINE" =~ "$ERRORMSG" ]] | |
then | |
echo "graylog2 is stopped. Restarting..." | |
logger "graylog2 exception error found. Restarting graylog2." | |
CURDATE=$(date) | |
# sv restart graylog2 | |
sleep 30 | |
GRAYSTATUS=$(sv status graylog2) | |
mail -s "graylog2 restart in $HOSTSERVER" [email protected] <<EOF | |
graylog2 on Scribe server $HOSTSERVER had an exception error: | |
$LINE | |
The service was restared by the monitoring script at $CURDATE. | |
The output of a "sv status gralog2" is: | |
$GRAYSTATUS | |
EOF | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment