Then I use fetch as-value I get _exception_ which terminates my whole script. But then I use normal fetch I get normal result with status=failure.
Then I try to print as-value result to log, nothing appears too.
I expected to get failure status as variable which then I could use to handle in script. Instead script dies on fetch command, also this exception is not logged by my default settings.
Example in terminal (which I expect to behave the same, except saving results to variable then using as-value): I use self-signed certificate in PiHole webserver.
PS. The script I want to make is to http healthcheck if PiHole service is alive, then dynamically set DNS upstream server to it, then it is alive. And if it is not alive, then set DNS upsteam server to 1.1.1.1. Typical expected failures is: link timeout, raspberrypi did not finished starting, and PiHole have not finished starting. Netwatch is not enough to healthcheck pihole.
Yes, I will change API key I posted here, don't get frisky.
Appending script I want to use in scheduler (status=failed part doesn't work, because script dies in first line):
Code: Select all
# License: MIT
{
:local result [/tool fetch url="https://pi.hole/admin/api.php\?status&auth=a138b30f41929c6ec46a6886772cae9f415e60cb6bba58dff079ad459adeefba" as-value output=user];
:if ($result->"status" = "finished") do={
:if ($result->"data" = "{\"status\":\"enabled\"}") do={
/ip dns set servers=192.168.88.20
} else={
/ip dns set servers=1.1.1.1,8.8.8.8,1.0.0.1,8.8.4.4
}
}
:if ($result->"status" = "failed") do={
/ip dns set servers=1.1.1.1,8.8.8.8,1.0.0.1,8.8.4.4
}
}