mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
netwatch-notify: support parents in a chain
This commit is contained in:
parent
d5125b816a
commit
e7855b4611
1 changed files with 13 additions and 3 deletions
|
@ -42,19 +42,28 @@
|
|||
}
|
||||
}
|
||||
:set ($Metric->"notified") false;
|
||||
:set ($Metric->"parent") ($HostInfo->"parent");
|
||||
:set ($Metric->"since");
|
||||
} else={
|
||||
:set ($Metric->"count") ($Metric->"count" + 1);
|
||||
:set ($Metric->"parent") ($HostInfo->"parent");
|
||||
:set ($Metric->"since") ($HostVal->"since");
|
||||
:local Count [ $IfThenElse ([ :tonum ($HostInfo->"count") ] > 0) ($HostInfo->"count") 5 ];
|
||||
:local ParentNotified [ $IfThenElse (($NetwatchNotify->($HostInfo->"parent")->"notified") = true) true false ];
|
||||
:if ([ :len ($HostInfo->"parent") ] > 0) do={
|
||||
:local Parent ($HostInfo->"parent");
|
||||
:if ([ :len $Parent ] > 0) do={
|
||||
:set Count ($Count + 1);
|
||||
}
|
||||
:local ParentNotified false;
|
||||
:while ($ParentNotified = false && [ :len $Parent ] > 0) do={
|
||||
:set ParentNotified [ $IfThenElse (($NetwatchNotify->$Parent->"notified") = true) true false ];
|
||||
:if ($ParentNotified = false) do={
|
||||
:set Parent ($NetwatchNotify->$Parent->"parent");
|
||||
}
|
||||
}
|
||||
$LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \
|
||||
$Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \
|
||||
($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \
|
||||
("parent host " . $HostInfo->"parent" . " is down.") ]) false;
|
||||
("parent host " . $Parent . " is down.") ]) false;
|
||||
:if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={
|
||||
$SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \
|
||||
("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".");
|
||||
|
@ -68,5 +77,6 @@
|
|||
:set ($NetwatchNotify->$HostName) {
|
||||
"count"=($Metric->"count");
|
||||
"notified"=($Metric->"notified");
|
||||
"parent"=($Metric->"parent");
|
||||
"since"=($Metric->"since") };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue