Last active
October 17, 2023 21:38
-
-
Save cristianmenghi/bfab7456ffde2626619467da3699b223 to your computer and use it in GitHub Desktop.
route monitoring script, for 2 internet connections, which notifies in case of failure.
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
# Main interface name | |
:global MainIf WAN-FTTH | |
# Reserve interface name | |
:global RsrvIf WAN-LTE | |
:local PingCount 5 | |
:local PingTargets1 {"1.1.1.1";"8.8.8.8"}; | |
:local PingTargets2 {"1.0.0.1";"8.8.4.4"}; | |
:local MESSAGE "ROUTE DOWN" | |
:local DATE [/system clock get date] | |
:local HOUR [/system clock get time] | |
:local STATION [/system identity get name] | |
:local MainIfInetOk false; | |
:local RsrvIfInetOk false; | |
# Check Main Internet connection | |
:foreach target in=$PingTargets1 do={ | |
:local PingResult [/ping $target count=$PingCount interface=$MainIf] | |
:set MainIfInetOk ($MainIfInetOk || ($PingResult >= 3)) | |
} | |
# Check Reserve Internet connection | |
:foreach target in=$PingTargets2 do={ | |
:local PingResult [/ping $target count=$PingCount interface=$RsrvIf] | |
:set RsrvIfInetOk ($RsrvIfInetOk || ($PingResult >= 3)) | |
} | |
:put "MainIfInetOk=$MainIfInetOk" | |
:put "RsrvIfInetOk=$RsrvIfInetOk" | |
if (!$MainIfInetOk) do={ | |
/log error "Main internet connection error" | |
:local send "$STATION $MESSAGE $MainIf $DATE $HOUR" | |
/tool fetch keep-result=no url="https://api.telegram.org/bot0000000:Aaaaaaaaaaaaaa-thPM/sendMessage\?chat_id=-11111111111&text=$send" | |
} | |
if (!$RsrvIfInetOk) do={ | |
/log error "Reserve internet connection error" | |
:local send "$STATION $MESSAGE $RsrvIf $DATE $HOUR" | |
/tool fetch keep-result=no url="https://api.telegram.org/bot0000000:Aaaaaaaaaaaaaa-thPM/sendMessage\?chat_id=-11111111111&text=$send" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment