mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-06-21 01:15:42 +02:00
netwatch-notify: allow to suppress notification on host down
This commit is contained in:
parent
42c203291a
commit
c6e581d4f9
6 changed files with 23 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
||||
# Copy configuration from global-config here and modify it.
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
75=("Finally merged the RouterOS v7 code into the main branch. " . [ $IfThenElse ([ $RequiredRouterOS "global-config.changes" "7.0" false ] = true) \
|
||||
("You may now drop '\$ScriptUpdatesUrlSuffix' from 'global-config-overlay'.") \
|
||||
("Still running RouterOS v6, so last reminder to see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v6") ]);
|
||||
76="Added an option to suppress notifications on host down with 'netwatch-notify'.";
|
||||
};
|
||||
|
||||
# Migration steps to be applied on script updates
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue