Last active
February 22, 2020 17:51
-
-
Save mikejsutherland/3d5572c670484ed19a7f0370a5d276e6 to your computer and use it in GitHub Desktop.
Simple pfsense WAN connection monitor with auto reset and notification
This file contains hidden or 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/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