Hey guys,
we need a script that turn off our WAN connection if the package loss is to high. But we don’t know if it is working or if we made some errors since we don’t get any feedback from the RouterOS.
:local pingTargetIn;
:local pingTargetOut;
:local ispIn;
:local ispOut;
# SAVE WAN STATUS BEFORE RUNNING SCRIPT (enabled/disabled)
:local E [/interface get WAN running]
:if ($E=false) do={
# IF WAN IS DOWN, FIRST ENABLE IT
/interface ethernet enable WAN;
}
# RUN CONNECTION TEST ON WAN
/tool flood-ping 176.221.xxx.xxx count=10 do={
:if ($sent >= 10) do={
:set pingTargetOut $sent;
:set pingTargetIn $received;
}
}
:local packageloss (100 - (($pingTargetIn * 100) / $pingTargetOut));
# CHECK RESULT OF TEST CONNECTION
:if ($packageloss >= 30 && ([/interface get [find name="WAN"] running]=true)) do={
# DISABLE WAN
/interface ethernet disable WAN;
:if ($E=false) do={
# STAY DOWN, NO NEED TO SEND NOTIFICATION
}else={
# WAN IS DISABLED, NOTIFY USER
/tool e-mail send to="user@company.com" from=mikrotik@company.com subject=("CONNECTION BAD") body="Currently we have badly RTO when ping to www.pingTarget.colm. Our main internet trouble, Please use the internet wisely";
}
}else={
:if ($E=false) do={
# WAN IS ENABLED; NOTIFY USER
/tool e-mail send to="user@company.com" from=mikrotik@company.com subject=("[RTO]") body="WAN UP. Thank You";
}else={
# STAY UP, NO NEED TO SEND NOTIFICATION
}
}
Any help is appreciated. Thank you