Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 21054

Scripting • Send alert only if the specific route status be changed

$
0
0
Hi,

I have the script bellow that I have got here in the forum of Mikrotik.

It works correctly notifying if one of the default routes become "Unreachable", but the problem is that on every script run it shows repeated status on the logs and e-mail notification (ie: link Down, link Down, Link Down...). I would like to be notified only if the current status become different from the last status. How could the code be adjusted?

Code:
:local emailTo "123@gmail.com":local emailSubject "Link Down - Unreachable Gateway Detected":local emailBody "An unreachable gateway has been detected.":local DeviceName [/system identity get name]:local commentFilters ("Default Route ISP1", "Default Route ISP2"):foreach commentFilter in=$commentFilters do={  :local unreachableGateways [:toarray [/routing route find where unreachable and comment=$commentFilter]]  :if ([:len $unreachableGateways] > 0) do={    :log warning ("Link Down - An unreachable gateway has been detected " . $commentFilter)    /tool e-mail send to=$emailTo subject="[$DeviceName] $emailSubject $commentFilter" body="$emailBody"    }}
Thank you!

Statistics: Posted by ragno — Sat Dec 09, 2023 6:37 pm



Viewing all articles
Browse latest Browse all 21054

Trending Articles