Simple Ping Monitor
-
Hi Wingnut2.0,
Of course! Scripts do enable pretty much anything. Can you say more about how you're going to monitor what sort of device's uptime? You could make HTTP requests through the HttpBuilder and check for timeouts. For that matter, in the referenced thread it is about pinging. You could do something like
function ping(host) { return $EXEC('ping -c 1 ' + host + '; echo $?'); //returns 0 on successful ping }
if you enabled shell access to your scripts: https://forum.infiniteautomation.com/topic/3818/invoke-shell-commands-from-a-scripting-environment
So, yes, it's probably possible, but a specific answer will require knowing how you'll be monitoring it.
-
Thank you, Phillip.
After your response, I am thinking about a binary meta point per device with timer update event and change detector to monitor the device(s) online status.
-
Certainly! Sounds like a good solution!
Another option could be setting the information to a single alphanumeric point with a change detector if you're only looking for event active emails. Then you could do it all in a single scripting data source, and just edit the script when new hosts come around.
-
In the Alphanumeric approach, would the scripting data point hold the host info (IP) and pass it to the data source script? Or are you suggesting the hosts be part of the script and the alphanumeric point is the trigger for a general alarm for any return of 1?
-
Hello Phillip,
I had a chance to try this out and I do not seem to get a response when running the ping command (this is on a MangoES). I have verified shell access is available via scripts by running commands like the ones below where I receive a response.
var response = $EXEC("ls -l"); print(response); var ip = $EXEC("ip a"); print(ip);
Can you confirm similar behavior? Is this a permissions issue?
Thank you.
-
Can you confirm similar behavior? Is this a permissions issue?
Yes, it is a Linux permission issue. One needs to give the ping a certain capability to be run with a lower privilege user, as java does to bind privileged ports. In this case, run,
sudo setcap 'cap_net_raw+ep' /bin/ping
-
I should have tested this, it doesn't look like
echo $?
works. Maybe something like,function ping(host) { return /1 received/.exec($EXEC("ping -c 1 " + host)) !== null; }
-
Ah, looks like there was an answer if only I had checked the documentation on enabling the shell scripting access: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/shell.html
So, maybe,
function ping(host) { $EXEC("ping -c 1 " + host); return $EXIT //=== 0 }
-
As always, thank you.
Works perfectly and I appreciate the link to the documentation.$EXIT This global object is used to store the exit code of the process. If the exit code is not zero, then the process failed.
-
You're welcome!