I’m trying to create a simple probe to monitor uptime. Either 1 for “up” or 0 for “down”.
Using a Probe:
Type: Function
Agent: default
Available: if(array_element(ping(“192.168.4.5”), 3)=“ok”, 1, -1)
Error: 0
Value: 1
Unit:
Rate: none
I just get a “down” probe all he time (Error field triggering). I’ve tried a few settings in “Available” like:
array_element(ping(“192.168.4.5”), 3)=“ok”
and
array_find(ping(“192.168.4.5”), “ok”)>0
But it always error’s out and runs that line. I’ve even pasted the code above into the error line so I could see if I was working off of the right fields and it looks like I am.
The Ping function itself returns exactly the opposite of what you want (-1 if Ping Fails), so to graph the System Down Times you would create a probe with the following elements:
I’ve used ping(device_property(“FirstAddress”)) rather than hard coded the IP address because you can then apply it to any device whose up time you want to graph.
By all means replace this with ping(“192.168.0.1”) or whatever.
Unfortunately, that’s not working either. I put your code in the available (I did want to make it more generic eventually, I was just working on making it work first) and I still get the error line executing.
I wonder if the Available line can’t handle array’s, but the error line can. Maybe I’ll try a custom function that uses ping, but only returns one item.