Skip to content

Instantly share code, notes, and snippets.

@mikejsutherland
Last active February 22, 2020 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejsutherland/3d5572c670484ed19a7f0370a5d276e6 to your computer and use it in GitHub Desktop.
Save mikejsutherland/3d5572c670484ed19a7f0370a5d276e6 to your computer and use it in GitHub Desktop.
Simple pfsense WAN connection monitor with auto reset and notification
#!/bin/sh
WWW="https://google.com"
DELAY=30
FAILLIMIT=2
ITERATION=5
www_test() {
RES=`curl -s -L -X HEAD -4 -o /dev/null --connect-timeout 30 -m 60 $WWW`
return $?
}
FAILS=0
for i in `seq $ITERATION`;
do
echo -n "$WWW -> "
if [ ! www_test ]
then
echo "down"
FAILS=$((FAILS+1))
logger -i -t gwmonitor "down $FAILS"
else
echo "alive"
fi
sleep $DELAY
done
if [ $FAILS -ge $FAILLIMIT ]
then
logger -i -t gwmonitor "down, resetting WAN interface"
/etc/rc.newwanip
sleep $DELAY
/etc/rc.notify_message -e -m "$HOST WAN interface reset after $FAILS/$ITERATION failures detected (Limit: $FAILLIMIT)"
else
logger -i -t gwmonitor "alive"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment