Nagios Script for Varnish Server

#!/bin/bash
# Varnish Process Monitor
# Written By: Manoj Chauhan
# Email ID: mchauhan75@gmail.com
# Dated: 31-07-2009
# Restart Varnish Server When It Goes Down
LOG=/usr/bin/logger
RESTART=”/usr/bin/sudo /etc/init.d/varnishncsa restart”
STATUS=”/etc/init.d/varnishncsa status”
# Path to pgrep command
PGREP=”/usr/bin/pgrep”
VARNISHPID=”varnishncsa”
Hostname=`hostname`
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
FLAG=0
/etc/init.d/varnishncsa status >/dev/null 2>&1
if [ $? -ne "0" ];then
{
#Nagios restart varnish service
$LOG “Critical:- $Hostname – Varnish service is down, restarted by nagios”
$RESTART >/dev/null 2>&1
}
fi
# Find varnish pid
PID=`$PGREP ${VARNISHPID} | wc -l`
if [ $PID -eq 0 ];then
{
#Nagios restart varnish service
$LOG “Critical:- $Hostname – Varnish PID is down, restarted by nagios”
$RESTART >/dev/null 2>&1
}
fi
/etc/init.d/varnishncsa status >/dev/null 2>&1
if [ $? -ne "0" ];then
{
$LOG “Critical:- $Hostname – Varnish service is down, please check…”
echo “CRITICAL – $Hostname -  Varnish service is down or not restarting, please check”
exit $STATE_CRITICAL;
}
else
{
FLAG=1
echo “OK – $Hostname -  Varnish service is running”
}
fi
if [ $FLAG -eq 0 ];then
{
# Find varnish pid
PID=`$PGREP ${VARNISHPID} | wc -l`
if [ $PID -eq 0 ];then
{
$LOG “Critical:- Varnish service is down, please check…”
echo “CRITICAL – $Hostname -  Varnish service is down or not restarting, please check”
exit $STATE_CRITICAL;
}
else
{
echo “OK – $Hostname -  Varnish service is running”
}
fi
}
fi

This entry was posted on Saturday, October 31st, 2009 at 6:09 am and is filed under Scripts. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply