From bccb7c3452466aea0f8c1790643b3aeb21e9b1af Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Jul 2021 11:27:26 +0200 Subject: netwatch-notify: implement pre-down hook --- doc/netwatch-notify.md | 4 ++++ global-config | 2 +- global-config-overlay | 2 +- global-config.changes | 1 + global-functions | 2 +- netwatch-notify | 3 +++ 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index 199f050..14efe0b 100644 --- a/doc/netwatch-notify.md +++ b/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; diff --git a/global-config b/global-config index 06f43e0..efc5c2d 100644 --- a/global-config +++ b/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"; diff --git a/global-config-overlay b/global-config-overlay index 0888452..c65322b 100644 --- a/global-config-overlay +++ b/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. diff --git a/global-config.changes b/global-config.changes index 0cc6b1e..e3a035d 100644 --- a/global-config.changes +++ b/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 diff --git a/global-functions b/global-functions index 7b5227a..0a031ba 100644 --- a/global-functions +++ b/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; diff --git a/netwatch-notify b/netwatch-notify index eecfa9f..966d415 100644 --- a/netwatch-notify +++ b/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={ -- cgit v1.2.3-70-g09d2