From c03da561cdf7cf6f47de79772749ef459f6ee495 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 3 Feb 2022 13:51:40 +0100 Subject: netwatch-notify: allow to suppress notification on host down (cherry picked from commit c6e581d4f90c9bea0adf405685aa634e264d1f3b) --- doc/netwatch-notify.md | 10 ++++++++++ global-config | 2 +- global-config-overlay | 2 +- global-config.changes | 1 + global-functions | 2 +- netwatch-notify | 16 +++++++++------- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index 9b504f7..dc107f2 100644 --- a/doc/netwatch-notify.md +++ b/doc/netwatch-notify.md @@ -78,6 +78,16 @@ But be warned: Dynamic updates will probably cause issues if the name has more than one record in dns - a high rate of configuration changes (and flash writes) at least. +### No notification on host down + +Also suppressing the notification on host down is possible with parameter +`no-down-notification`. This may be desired for devices that are usually +powered off, but accessibility is of interest. + + / tool netwatch add comment="notify, hostname=printer, no-down-notification" host=10.0.0.30; + +Go and get your coffee ☕️ before sending the print job. + Also notification settings are required for e-mail, matrix and/or telegram. Tips & Tricks diff --git a/global-config b/global-config index 75fbba4..5f0f4db 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 75; +:global GlobalConfigVersion 76; # This is used for DNS and backup file. :global Domain "example.com"; diff --git a/global-config-overlay b/global-config-overlay index c443bea..dfa2b99 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 75; +:global GlobalConfigVersion 76; # Use branch routeros-v6 with RouterOS v6: :global ScriptUpdatesUrlSuffix "\?h=routeros-v6"; diff --git a/global-config.changes b/global-config.changes index 6f0e2f7..37aa074 100644 --- a/global-config.changes +++ b/global-config.changes @@ -79,6 +79,7 @@ 73="Renamed backup scripts ('cloud-backup' -> 'backup-cloud', 'email-backup' -> 'backup-email', 'upload-backup' -> 'backup-upload')."; 74="Extended 'hotspot-to-wpa', it can now read additional configuration from templates and hotspot users."; 75="You are using the branch 'routeros-v6', well done."; + 76="Added an option to suppress notifications on host down with 'netwatch-notify'."; }; # Migration steps to be applied on script updates diff --git a/global-functions b/global-functions index 70f1077..68d8250 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 75; +:global ExpectedConfigVersion 76; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/netwatch-notify b/netwatch-notify index ae89cfb..e82cea6 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -122,10 +122,10 @@ $ScriptLock $0; :set Parent ($NetwatchNotify->$Parent->"parent"); } } - $LogPrintExit2 info $0 ("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 " . $Parent . " is down.") ]) false; + $LogPrintExit2 [ $IfThenElse ($HostInfo->"no-down-notification" != true) info debug ] $0 \ + ("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 " . $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"); } @@ -134,9 +134,11 @@ $ScriptLock $0; :if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={ :set Message ($Message . "\n\n" . [ $NetwatchNotifyHook $HostName "down" ($HostInfo->"down-hook") ]); } - $SendNotification2 ({ origin=$0; \ - subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ - message=$Message }); + :if ($HostInfo->"no-down-notification" != true) do={ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ + message=$Message }); + } :set ($Metric->"notified") true; } } -- cgit v1.2.3-70-g09d2