Here is a simple script that test for port 8089 connectivity. It will send email alert (and restart the process if not connection):
/export/home/mhassan/scripts $ cat splunkd-watchdog.sh
!/bin/bash
splunkd-watchdog.sh
Monitor Splunk port 8089. Restart process if no answer
-Mohamad Hassan 2/2/215
timestamp= date
USER= whoami
WHO= who -u
host= uname -n
LOGFILE="/opt/splunk/var/log/splunk-watchdog.log"
PROC="splunkd"
PORT="8089"
ADMINS="
[email protected] [email protected]"
TEST= nc -z -w5 $HOSTNAME $PORT;echo $? < /dev/null
Debugging
let TEST=0
echo $TEST
if [ $TEST -eq 1 ] ;then
/opt/splunk/bin/splunk restart
RESULT=`ps ax | grep -i "$PROC" | grep -v grep|grep -v watchdog`
echo "$timestamp $HOSTNAME: splunk-watchdog ALERT! $PROC process restarted" >> $LOGFILE
echo -e "Splunk watchdog ALERT! Splunk port $PORT is not answering.\n\n Hostname: $HOSTNAME\n Time: $timestamp\n Notifying: $ADMINS\n ACTION: Restarting ($PROC)!\n\nCurrrent logged-in users:\n$WHO\n\nCurrent splunkd status(after restart):\n$RESULT" |mail -s "$PROC watchdog ALERT! [$HOSTNAME]" $ADMINS
echo "$PROC restarted!"
echo "Email sent to: $ADMINS"
fi
... View more