Browse Source

netwatch-notify: implement pre-down hook

pull/15/head change-60
Christian Hesse 3 months ago
parent
commit
bccb7c3452
  1. 4
      doc/netwatch-notify.md
  2. 2
      global-config
  3. 2
      global-config-overlay
  4. 1
      global-config.changes
  5. 2
      global-functions
  6. 3
      netwatch-notify

4
doc/netwatch-notify.md

@ -44,6 +44,10 @@ comment:
/ tool netwatch add comment="notify, hostname=poe-device, down-hook=/ interface ethernet poe power-cycle en21;" host=10.0.0.20;
Also there is a `pre-down-hook` that fires at two thirds of failed checks
required for the notification. The idea is to fix the issue before a
notification is sent.
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;

2
global-config

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
:global GlobalConfigVersion 59;
:global GlobalConfigVersion 60;
# This is used for DNS and backup file.
:global Domain "example.com";

2
global-config-overlay

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
# Comment or remove to disable news and change notifications.
:global GlobalConfigVersion 59;
:global GlobalConfigVersion 60;
# Copy configuration from global-config here and modify it.

1
global-config.changes

@ -63,6 +63,7 @@
57="Celebrating the 1.000th commit - Hooray!";
58="Added a cleanup script for 'hotspot-to-wpa' to purge old access list entries.";
59="Updating CAP with 'check-routeros-update' is now possible with opt-in.";
60="Implemented a pre-down hook in 'netwatch-notify' that fires at two thirds of failed checks.";
};
# Migration steps to be applied on script updates

2
global-functions

@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
:global ExpectedConfigVersion 59;
:global ExpectedConfigVersion 60;
# global variables not to be changed by user
:global GlobalFunctionsReady false;

3
netwatch-notify

@ -117,6 +117,9 @@
$Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \
($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \
("parent host " . $Parent . " is down.") ]) false;
:if ((($Count * 2) - ($Metric->"count" * 3)) / 2 = 0 && [ :typeof ($HostInfo->"pre-down-hook") ] = "str") do={
$NetwatchNotifyHook $HostName "pre-down" ($HostInfo->"pre-down-hook");
}
:if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={
:local Message ("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".");
:if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={

Loading…
Cancel
Save