aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2022-02-03 13:51:40 +0100
committerGravatar Christian Hesse <mail@eworm.de>2022-02-10 09:14:36 +0100
commitc03da561cdf7cf6f47de79772749ef459f6ee495 (patch)
tree315f8bbf20215b40733e6ef41d5f470f3d7ee0d1
parent8d49babb0114ad55ec3094f7d9cec2f1bfea43be (diff)
netwatch-notify: allow to suppress notification on host downchange-76-v6
(cherry picked from commit c6e581d4f90c9bea0adf405685aa634e264d1f3b)
-rw-r--r--doc/netwatch-notify.md10
-rw-r--r--global-config2
-rw-r--r--global-config-overlay2
-rw-r--r--global-config.changes1
-rw-r--r--global-functions2
-rw-r--r--netwatch-notify16
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;
}
}