From 1c10044b2430c4bd8ec5955ead84fbe282587bef Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 3 Jul 2020 15:19:46 +0200 Subject: netwatch-notify: add support for down hook Adding up-hook does not make sense... Just use netwatch's up-script for that. --- netwatch-notify | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netwatch-notify b/netwatch-notify index 854d5fa..350c088 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -18,7 +18,8 @@ :foreach Host in=[ / tool netwatch find where comment~"^notify," ] do={ :local HostVal [ / tool netwatch get $Host ]; - :local HostName ([ $ParseKeyValueStore ($HostVal->"comment") ]->"hostname"); + :local HostInfo [ $ParseKeyValueStore ($HostVal->"comment") ]; + :local HostName ($HostInfo->"hostname"); :local Metric { "count"=0; "notified"=false }; :if ([ :typeof ($NetwatchNotify->$HostName) ] = "array") do={ @@ -43,6 +44,10 @@ $SendNotification ("Netwatch Notify: \E2\9D\8C " . $HostName . " down") \ ("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . "."); :set ($Metric->"notified") true; + :if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={ + $LogPrintExit info ("Running hook on host " . $HostName . " down: " . ($HostInfo->"down-hook")) false; + [ :parse ($HostInfo->"down-hook") ]; + } } } :set ($NetwatchNotify->$HostName) { "count"=($Metric->"count"); "notified"=($Metric->"notified") }; -- cgit v1.2.3-54-g00ecf