mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
Merge branch 'netwatch-notify'
This commit is contained in:
commit
34a0d4ab85
6 changed files with 37 additions and 8 deletions
|
@ -8,8 +8,9 @@ Description
|
||||||
|
|
||||||
This script sends notifications about host UP and DOWN events. In comparison
|
This script sends notifications about host UP and DOWN events. In comparison
|
||||||
to just netwatch (`/ tool netwatch`) and its `up-script` and `down-script`
|
to just netwatch (`/ tool netwatch`) and its `up-script` and `down-script`
|
||||||
this script implements a simple state machine. Host down events are triggered
|
this script implements a simple state machine and dependency model. Host
|
||||||
only if the host is down for several checks to avoid false alerts.
|
down events are triggered only if the host is down for several checks and
|
||||||
|
optional parent host is not down to avoid false alerts.
|
||||||
|
|
||||||
Requirements and installation
|
Requirements and installation
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
@ -39,6 +40,15 @@ The count threshould (default is 5 checks) is configurable as well:
|
||||||
|
|
||||||
/ tool netwatch add comment="notify, hostname=example.com, count=10" host=104.18.144.11;
|
/ tool netwatch add comment="notify, hostname=example.com, count=10" host=104.18.144.11;
|
||||||
|
|
||||||
|
If the host is behind another checked host add a dependency, this will
|
||||||
|
suppress notification if the parent host is down:
|
||||||
|
|
||||||
|
/ tool netwatch add comment="notify, hostname=gateway" host=93.184.216.1;
|
||||||
|
/ tool netwatch add comment="notify, hostname=example.com, parent=gateway" host=93.184.216.34;
|
||||||
|
|
||||||
|
Note that every configured parent in a chain increases the check count
|
||||||
|
threshould by one.
|
||||||
|
|
||||||
Also notification settings are required for e-mail and telegram.
|
Also notification settings are required for e-mail and telegram.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
:global GlobalConfigVersion 36;
|
:global GlobalConfigVersion 37;
|
||||||
|
|
||||||
# This is used for DNS and backup file.
|
# This is used for DNS and backup file.
|
||||||
:global Domain "example.com";
|
:global Domain "example.com";
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
# Comment or remove to disable change notifications.
|
# Comment or remove to disable change notifications.
|
||||||
:global GlobalConfigVersion 36;
|
:global GlobalConfigVersion 37;
|
||||||
|
|
||||||
# Copy configuration from global-config here and modify it.
|
# Copy configuration from global-config here and modify it.
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,5 @@
|
||||||
34="Introduced script 'ospf-to-leds' to visualize OSPF instance state via LEDs.";
|
34="Introduced script 'ospf-to-leds' to visualize OSPF instance state via LEDs.";
|
||||||
35="Implemented visual feedback for 'mode-button' with configurable LED.";
|
35="Implemented visual feedback for 'mode-button' with configurable LED.";
|
||||||
36="Added support for installing updates automatically if seen in neighbor list.";
|
36="Added support for installing updates automatically if seen in neighbor list.";
|
||||||
|
37="Implemented simple dependency model in 'netwatch-notify'.";
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/
|
# https://git.eworm.de/cgit/routeros-scripts/about/
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 36;
|
:global ExpectedConfigVersion 37;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
|
|
@ -42,14 +42,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
:set ($Metric->"notified") false;
|
:set ($Metric->"notified") false;
|
||||||
|
:set ($Metric->"parent") ($HostInfo->"parent");
|
||||||
:set ($Metric->"since");
|
:set ($Metric->"since");
|
||||||
} else={
|
} else={
|
||||||
:set ($Metric->"count") ($Metric->"count" + 1);
|
:set ($Metric->"count") ($Metric->"count" + 1);
|
||||||
|
:set ($Metric->"parent") ($HostInfo->"parent");
|
||||||
:set ($Metric->"since") ($HostVal->"since");
|
:set ($Metric->"since") ($HostVal->"since");
|
||||||
|
:local Count [ $IfThenElse ([ :tonum ($HostInfo->"count") ] > 0) ($HostInfo->"count") 5 ];
|
||||||
|
:local Parent ($HostInfo->"parent");
|
||||||
|
:while ([ :len $Parent ] > 0) do={
|
||||||
|
:set Count ($Count + 1);
|
||||||
|
:set Parent ($NetwatchNotify->$Parent->"parent");
|
||||||
|
}
|
||||||
|
:set Parent ($HostInfo->"parent");
|
||||||
|
: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 " . \
|
$LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \
|
||||||
$Metric->"count" . " checks.") false;
|
$Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \
|
||||||
:if ($Metric->"count" >= [ $IfThenElse ([ :typeof ($HostInfo->"count") ] != "nothing") ($HostInfo->"count") 5 ] && \
|
($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \
|
||||||
$Metric->"notified" != true) do={
|
("parent host " . $Parent . " is down.") ]) false;
|
||||||
|
:if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={
|
||||||
$SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \
|
$SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \
|
||||||
("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".");
|
("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".");
|
||||||
:set ($Metric->"notified") true;
|
:set ($Metric->"notified") true;
|
||||||
|
@ -62,5 +79,6 @@
|
||||||
:set ($NetwatchNotify->$HostName) {
|
:set ($NetwatchNotify->$HostName) {
|
||||||
"count"=($Metric->"count");
|
"count"=($Metric->"count");
|
||||||
"notified"=($Metric->"notified");
|
"notified"=($Metric->"notified");
|
||||||
|
"parent"=($Metric->"parent");
|
||||||
"since"=($Metric->"since") };
|
"since"=($Metric->"since") };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue