Created
October 17, 2020 06:56
-
-
Save elmer/066fe9bbcd65a0997607074f35e5b58b to your computer and use it in GitHub Desktop.
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
# rb-check | |
# Mikrotik RayBill Network Checker | |
# PPPoE Interface | |
:local rbInterface pppoe-rb | |
# Gateway in RB network | |
:local rbGateway 192.168.1.1 | |
# Ping failure threshold | |
:local rbFailThreshold 3 | |
# globals | |
:global rbPingFailCount | |
:global rbTimerCount | |
# initialize global variable | |
:if ([:typeof $rbPingFailCount] = "nothing") do={ :set rbPingFailCount 0 } | |
:if ([:typeof $rbTimerCount] = "nothing") do={ :set rbTimerCount 0 } | |
# locals | |
:local rbPingResult | |
:set rbTimerCount ($rbTimerCount + 1) | |
:set rbPingResult [/ping $rbGateway count=1 interface=$rbInterface] | |
# ping failed | |
if ($rbPingResult = 0) do={ | |
:log warning "Ping to RB network failed." | |
:set rbPingFailCount ($rbPingFailCount + 1) | |
:if ($rbPingFailCount > ($rbFailThreshold - 1)) do={ | |
:log warning "RB Gateway Check threshold reach, will restart the interface" | |
/interface set disabled=yes [/interface find name=$rbInterface] | |
delay 6 | |
/interface set disabled=no [/interface find name=$rbInterface] | |
:set rbTimerCount 0 | |
} | |
} | |
# ping success | |
:if ($rbPingResult = 1) do={ | |
:set rbTimerCount 0 | |
:log info "Ping to RB network - OK" | |
} | |
:if ($rbTimerCount = 0 ) do={ | |
:set rbPingFailCount 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment