From 493e4fc8c116e094a420adb4cb2383065cf02443 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 20 Sep 2022 22:40:47 +0200 Subject: netwatch-notify: use a counter for resolve failures This should relax the error message a bit as it is not triggered on first failure. --- netwatch-notify | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 1d285de..f95f426 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -69,7 +69,7 @@ $ScriptLock $0; :if ($HostInfo->"notify" = true && $HostInfo->"disabled" != true) do={ :local Name [ $EitherOr ($HostInfo->"name") ($HostVal->"name") ]; - :local Metric { "count-down"=0; "count-up"=0; "notified"=false }; + :local Metric { "count-down"=0; "count-up"=0; "notified"=false; "resolve-failcnt"=0 }; :if ([ :typeof ($NetwatchNotify->$Name) ] = "array") do={ :set $Metric ($NetwatchNotify->$Name); } @@ -84,14 +84,14 @@ $ScriptLock $0; $HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \ ", updating.") false; /tool/netwatch/set host=$Resolve $Host; - :set ($Metric->"resolve-failed") false; + :set ($Metric->"resolve-failcnt") 0; } } on-error={ - :if ($Metric->"resolve-failed" != true) do={ + :set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1); + :if ($Metric->"resolve-failcnt" = 3) do={ $LogPrintExit2 warning $0 ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \ ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \ $HostInfo->"name") "" ] . "' failed.") false; - :set ($Metric->"resolve-failed") true; } } } @@ -174,7 +174,7 @@ $ScriptLock $0; "count-up"=($Metric->"count-up"); "notified"=($Metric->"notified"); "parent"=($Metric->"parent"); - "resolve-failed"=($Metric->"resolve-failed"); + "resolve-failcnt"=($Metric->"resolve-failcnt"); "since"=($Metric->"since") }; } } -- cgit v1.2.3-54-g00ecf