From 05a7ae409ba1cee217b68adacf1d8d27d43414d5 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 18 May 2021 16:44:07 +0200 Subject: netwatch-notify: add info on hook in notification --- netwatch-notify | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 27afd70..c630678 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -60,18 +60,20 @@ :set ($Metric->"count") 0; } :if ($Metric->"notified" = true) do={ - $SendNotification2 ({ origin=$0; \ - subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \ - message=("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \ - "It was down for " . $Count . " checks since " . ($Metric->"since") . ".") }); + :local Message ("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \ + "It was down for " . $Count . " checks since " . ($Metric->"since") . "."); :if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={ :if ([ $ValidateSyntax ($HostInfo->"up-hook") ] = true) do={ $LogPrintExit2 info $0 ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false; + :set Message ($Message . "\n\nRunning hook:\n" . $HostInfo->"up-hook"); [ :parse ($HostInfo->"up-hook") ]; } else={ $LogPrintExit2 warning $0 ("The up-hook for host " . $HostName . " failed syntax validation.") false; } } + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \ + message=$Message }); } :set ($Metric->"notified") false; :set ($Metric->"parent") ($HostInfo->"parent"); @@ -99,18 +101,20 @@ ($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \ ("parent host " . $Parent . " is down.") ]) false; :if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={ - $SendNotification2 ({ origin=$0; \ - subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ - message=("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".") }); - :set ($Metric->"notified") true; + :local Message ("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . "."); :if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={ :if ([ $ValidateSyntax ($HostInfo->"down-hook") ] = true) do={ $LogPrintExit2 info $0 ("Running hook on host " . $HostName . " down: " . ($HostInfo->"down-hook")) false; + :set Message ($Message . "\n\nRunning hook:\n" . $HostInfo->"down-hook"); [ :parse ($HostInfo->"down-hook") ]; } else={ $LogPrintExit2 warning $0 ("The down-hook for host " . $HostName . " failed syntax validation.") false; } } + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ + message=$Message }); + :set ($Metric->"notified") true; } } :set ($NetwatchNotify->$HostName) { -- cgit v1.2.3-54-g00ecf