Only run external when in device is pingable

Hey, I am having some difficultly getting this to work due to limited info I can find on The Dude function etc compared the RouterOS scripting.

I have two services running on a device.

  1. ping
  2. winbox

ping = standard ping probe.
winbox = TCP probe I created that checks if you can winbox to the device.

Basically if you cannot winbox to the device, I want to reboot it (only if the device is still pingable). No point trying to reboot it if is offline.

I have setup a notification called cmd-run-reboot that runs when the state goes:

  1. up → down
  2. unstable → down

cmd-run-reboot calls an AutoIt script I wrote that reboots the device and other a few things via SSH’ing to the device.
notification code:
Z:\run_cmd.exe “[Device.FirstAddress]” “[Device.UserName]” “[Device.Password]” “[Device.ServicesUp]” “/system reboot”

I would like to only call the AutoIt script from The Dude if the device is online (pingable). The issue being…if the device is powered off then the script is run as both services are offline.
I can get around this by pinging the device from my script and exiting the script if it is online, but I would rather do this check from the notification within The Dude and not call the script if it is not necessary.

I have tried a few things like creating a function called ‘online’ :
if(string_find(“[Device.ServicesUp]”, “ping”), “True”, “False”)

I think what I am after is some code to put in my notification to test the ping service status.

But I cannot seem to get it work, I am sure there is a simple answer for this.

Any ideas?

Thanks.