Last active
July 24, 2022 20:17
-
-
Save mgeeky/5b6aaefe59dba83eee5221f3b115ca6c to your computer and use it in GitHub Desktop.
WebApplication heartbeat script intended to poll remote web application whether it responds correctly (HTTP 200 OK) or not - thus resulting in Linux GNOME alert being generated. Useful when dealing with unstable webservers or appications behind VPN connection.
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 | |
# | |
# Simple script intended to poll remote web application to check whether it is available | |
# and returns 200 OK. If it is not, then Linux GNOME-related alert will be generated. | |
# | |
# Mariusz B., 2016 | |
# | |
REMOTE_HOST="http://<webapplication>" | |
TIMEOUT=5 | |
USER_AGENT='Mozilla/5.0 (X11; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0' | |
RESTORE=$(echo -en '\033[0m') | |
RED=$(echo -en '\033[00;31m') | |
GREEN=$(echo -en '\033[00;32m') | |
LIGHTGRAY=$(echo -en '\033[00;37m') | |
red() { | |
echo $RED$1$RESTORE | |
} | |
green() { | |
echo $GREEN$1$RESTORE | |
} | |
lightgray() { | |
echo $LIGHTGRAY$1$RESTORE | |
} | |
alert() { | |
notify-send "$1" | |
aplay /usr/share/sounds/speech-dispatcher/test.wav 2> /dev/null | |
} | |
echo "Polling $REMOTE_HOST ..." | |
CNT=0 | |
while true | |
do | |
date | |
RESP=`curl -sD- -A '$USER_AGENT' --connect-timeout 5 "$REMOTE_HOST" -o /dev/null ` | |
if echo "$RESP" | grep -q "200" ; then | |
green "Responding" | |
if [ $CNT -gt 0 ]; then | |
CNT=0 | |
fi | |
else | |
red "Not responding" | |
CNT=$((CNT+1)) | |
if [ $CNT -gt 1 ]; then | |
alert "Remote host $REMOTE_HOST is not responding" | |
echo "$RESP" | |
fi | |
fi | |
sleep $TIMEOUT | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment