netwatch-notify: be more verbose on host downtime

Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
Christian Hesse 2020-08-24 14:18:32 +02:00
parent e58d8e4373
commit 92ca31a41d

View file

@ -35,15 +35,17 @@
:if ($Metric->"notified" = true) do={ :if ($Metric->"notified" = true) do={
$SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up") \ $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up") \
("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \ ("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \
"It was down for " . $Count . " checks."); "It was down for " . $Count . " checks since " . ($Metric->"since") . ".");
:if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={ :if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={
$LogPrintExit info ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false; $LogPrintExit info ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false;
[ :parse ($HostInfo->"up-hook") ]; [ :parse ($HostInfo->"up-hook") ];
} }
} }
:set ($Metric->"notified") false; :set ($Metric->"notified") false;
:set ($Metric->"since");
} else={ } else={
:set ($Metric->"count") ($Metric->"count" + 1); :set ($Metric->"count") ($Metric->"count" + 1);
:set ($Metric->"since") ($HostVal->"since");
$LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \ $LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \
$Metric->"count" . " checks.") false; $Metric->"count" . " checks.") false;
:if ($Metric->"count" >= [ $IfThenElse ([ :typeof ($HostVal->"count") ] != "nothing") ($HostVal->"count") 5 ] && \ :if ($Metric->"count" >= [ $IfThenElse ([ :typeof ($HostVal->"count") ] != "nothing") ($HostVal->"count") 5 ] && \
@ -57,5 +59,8 @@
} }
} }
} }
:set ($NetwatchNotify->$HostName) { "count"=($Metric->"count"); "notified"=($Metric->"notified") }; :set ($NetwatchNotify->$HostName) {
"count"=($Metric->"count");
"notified"=($Metric->"notified");
"since"=($Metric->"since") };
} }