aboutsummaryrefslogtreecommitdiffstats
path: root/netwatch-notify.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'netwatch-notify.rsc')
-rw-r--r--netwatch-notify.rsc44
1 files changed, 24 insertions, 20 deletions
diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc
index 8b05c5e..00f03cd 100644
--- a/netwatch-notify.rsc
+++ b/netwatch-notify.rsc
@@ -8,11 +8,11 @@
# monitor netwatch and send notifications
# https://rsc.eworm.de/doc/netwatch-notify.md
-:global GlobalFunctionsReady;
-:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-
:local ExitOK false;
-:do {
+:onerror Err {
+ :global GlobalConfigReady; :global GlobalFunctionsReady;
+ :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
+ do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
:local ScriptName [ :jobname ];
:global NetwatchNotify;
@@ -38,10 +38,10 @@
:global ValidateSyntax;
:if ([ $ValidateSyntax $Hook ] = true) do={
- :do {
+ onerror Err {
[ :parse $Hook ];
- } on-error={
- $LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run.");
+ } do={
+ $LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run: " . $Err);
:return ("The hook failed to run.");
}
} else={
@@ -61,15 +61,19 @@
:global GetRandom20CharAlNum;
:local FwAddrList ($ScriptName . "-" . [ $GetRandom20CharAlNum ]);
- /ip/firewall/address-list/add address=$Name list=$FwAddrList dynamic=yes timeout=1s;
- :delay 20ms;
- :if ([ :len [ /ip/firewall/address-list/find where list=$FwAddrList address=$Expected ] ] > 0) do={
- :return true;
+ :if ([ :typeof [ :toip $Expected ] ] = "ip") do={
+ /ip/firewall/address-list/add address=$Name list=$FwAddrList dynamic=yes timeout=10s;
+ :delay 20ms;
+ :if ([ :len [ /ip/firewall/address-list/find where list=$FwAddrList address=$Expected ] ] > 0) do={
+ :return true;
+ }
}
- /ipv6/firewall/address-list/add address=$Name list=$FwAddrList dynamic=yes timeout=1s;
- :delay 20ms;
- :if ([ :len [ /ipv6/firewall/address-list/find where list=$FwAddrList address=$Expected ] ] > 0) do={
- :return true;
+ :if ([ :typeof [ :toip6 $Expected ] ] = "ip6") do={
+ /ipv6/firewall/address-list/add address=$Name list=$FwAddrList dynamic=yes timeout=10s;
+ :delay 20ms;
+ :if ([ :len [ /ipv6/firewall/address-list/find where list=$FwAddrList address=$Expected ] ] > 0) do={
+ :return true;
+ }
}
:return false;
@@ -103,7 +107,7 @@
:if ([ :typeof ($HostInfo->"resolve") ] = "str") do={
:if ([ $IsDNSResolving ] = true) do={
- :do {
+ :onerror Err {
:local Resolve [ :resolve type=[ $IfThenElse ([ :typeof ($HostVal->"host") ] = "ip") \
"ipv4" "ipv6" ] ($HostInfo->"resolve") ];
:if ($Resolve != $HostVal->"host") do={
@@ -117,13 +121,13 @@
:set ($HostVal->"status") "unknown";
}
}
- } on-error={
+ } do={
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);
:if ($Metric->"resolve-failcnt" = 3) do={
$LogPrint [ $IfThenElse ($HostInfo->"no-resolve-fail" != true) warning debug ] \
$ScriptName ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \
($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
- $HostInfo->"name") "" ] . "' failed.");
+ $HostInfo->"name") "" ] . "' failed: " . $Err);
}
}
}
@@ -220,6 +224,6 @@
"since"=($Metric->"since") };
}
}
-} on-error={
- :global ExitError; $ExitError $ExitOK [ :jobname ];
+} do={
+ :global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
}