If I configure a netwatch to ping a host on the network, even if mikrotik own local IP-address with the action to write to the log (for example Host online, Host offline), then immediately after rebooting microtik apparently cannot determine the availability of an IP-address (even its own) and writes to the log that the Host is offline, although in fact the host is online. Someone in the know what could be wrong?
To work around this problem, I tried using a script that monitors the previous availability state.
But there is a nuance. On mikrotiK 962UiGS-5HacT2HnT, the script runs without problems, the entries in the log are one-time. On mikrotik RBLtAP-2HnD this script, if the host is not available, writes a message “Host 192.168.1.252 is offline” every time until the host becomes available again (https://prnt.sc/1dluijn). Firmware on 962UiGS-5HacT2HnT - 6.48.3 stable, firmware on RBLtAP-2HnD - 6.47.10 long term.
evidenced errors on your script:
:global vdsdown
:local host 192.168.1.252 # better put the editable things up:local checkvds [/ping $host count=3]
:if ($checkvds = 0) do={ # $ must used for call variables:if ($vdsdown != true) do={
/log warning "Host $host is offline"; # useless ";" :set $vdsdown true # $ must not be used on set}
} else={
:if ($vdsdown != false = true) do={ # better != false instead of =true/log info "Host $host is online"; # useless ";" :set $vdsdown false # $ must not be used on set}
}
My revised version:
:local host 192.168.0.101
:global vdsdown
:global vdsstatus
# for test "warning unstable" set the count to 2
:local checkvds [/ping $host count=3]
:if ($checkvds = 0) do={
:if ($vdsstatus != "offline") do={ /log error "Host $host change status from $vdsstatus to offline" }
:set vdsstatus "offline"
:set vdsdown true
}
:if (($checkvds > 0) && ($checkvds < 3)) do={
:if ($vdsstatus != "unstable") do={ /log warning "Host $host change status from $vdsstatus to unstable" }
:set vdsstatus "unstable"
:set vdsdown false
}
:if ($checkvds = 3) do={
:if ($vdsstatus != "online") do={ /log info "Host $host change status from $vdsstatus to online" }
:set vdsstatus "online"
:set vdsdown false
}
Thanks for the hints regarding the script. In this case, since the script works as it should, the question about the Netwatch has become irrelevant.
Thank you!
I ask you to clarify one nuance. I corrected my version of the script and also tried yours. Both scripts, if run manually, work as expected. But if the same scripts are launched by the scheduler, the status of the host, online or offline, is constantly written to the log. I just can't understand what's the matter ...
Here is the script and the scheduler, nothing special. When the scheduler runs this script every 10 seconds, we have in the log (screenshot https://prnt.sc/1ed2ifr). When manually started, the result is the same. What has changed or broken, I do not understand ...
RouterOS is 6.47.10 version (long-term). Thank you for the hint, I didn’t notice the “$” symbol. But it also didn’t help for some reason. Log entries about the state of the hots are still written every time the script is executed …
Okay, I’ll try to figure out what’s the matter. Thanks for the tips.