aboutsummaryrefslogtreecommitdiffstats
path: root/netwatch-notify.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-02-29 14:21:46 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-02-29 14:21:46 +0100
commitb9e0ffac1d5bed0d8243e9ee1467336517f8957a (patch)
tree6aa3ae44b4a5a3fa575446e5ff04eeefa90d9056 /netwatch-notify.rsc
parent872abbea7d147a8c6291270ba9389731e998b1e0 (diff)
parenta924de274c482b79777d9c1ca9d2e1d1919155cb (diff)
Merge branch 'netwatch-notify' into next
Diffstat (limited to 'netwatch-notify.rsc')
-rw-r--r--netwatch-notify.rsc42
1 files changed, 35 insertions, 7 deletions
diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc
index ae9c8a8..cd4fc0d 100644
--- a/netwatch-notify.rsc
+++ b/netwatch-notify.rsc
@@ -52,6 +52,28 @@
:return ("Ran hook:\n" . $Hook);
}
+:local ResolveExpected do={
+ :local Name [ :tostr $1 ];
+ :local Expected [ :tostr $2 ];
+
+ :delay 100ms;
+
+ :if ([ :len [ /ip/dns/cache/find where name=$Name data=$Expected ] ] > 0) do={
+ :return true;
+ }
+
+ :local Cname [ /ip/dns/cache/find where name=$Name type="CNAME" ];
+ :if ([ :len $Cname ] > 0) do={
+ :set Cname [ /ip/dns/cache/get $Cname data ];
+ :set Cname [ :pick $Cname 0 ([ :len $Cname ] - 1) ];
+ :if ([ :len [ /ip/dns/cache/find where name=$Cname data=$Expected ] ] > 0) do={
+ :return true;
+ }
+ }
+
+ :return false;
+}
+
$ScriptLock $0;
:local ScriptFromTerminalCached [ $ScriptFromTerminal $0 ];
@@ -80,12 +102,15 @@ $ScriptLock $0;
:do {
:local Resolve [ :resolve ($HostInfo->"resolve") ];
:if ($Resolve != $HostVal->"host") do={
- $LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
- ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
- $HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
- ", updating.") false;
- /tool/netwatch/set host=$Resolve $Host;
- :set ($Metric->"resolve-failcnt") 0;
+ :if ([ $ResolveExpected ($HostInfo->"resolve") ($HostVal->"host") ] = false) do={
+ $LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
+ ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
+ $HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
+ ", updating.") false;
+ /tool/netwatch/set host=$Resolve $Host;
+ :set ($Metric->"resolve-failcnt") 0;
+ :set ($HostVal->"status") "unknown";
+ }
}
} on-error={
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);
@@ -124,7 +149,9 @@ $ScriptLock $0;
:set ($Metric->"notified") false;
:set ($Metric->"parent") ($HostInfo->"parent");
:set ($Metric->"since");
- } else={
+ }
+
+ :if ($HostVal->"status" = "down") do={
:set ($Metric->"count-down") ($Metric->"count-down" + 1);
:set ($Metric->"count-up") 0;
:set ($Metric->"parent") ($HostInfo->"parent");
@@ -177,6 +204,7 @@ $ScriptLock $0;
:set ($Metric->"notified") true;
}
}
+
:set ($NetwatchNotify->$Name) {
"count-down"=($Metric->"count-down");
"count-up"=($Metric->"count-up");