Best approach to periodically poll another server?


I’m trying to write my first SmartApp/Device Handler. I’ve gone through the tutorials, but have a slightly ‘off’ situation I’m trying to resolve. My app is intended to monitor the changing state of a software application running on a physical server. The server itself has a REST/SOAP API. My thought is that I can write a DH/SM to periodically (say every 2 seconds) make a call to one of the state APIs on the server to ensure that it and the services it provides are up; if not, cycle a smart outlet (basically to trigger a reboot of the physical server.) In detail, basically, if my VMware ESXi server is not responsive, force a reboot via power cycle. My email server and some other “always on” services are hosted on this server, and I want it to always be up.

The specific questions I have are:
1) In looking at the ServiceManager example, I see that the SM has to do discovery via SSDP/UPnP. Do I explicitly need to do that if I already know the IP and PORT of the server? Or, can I simply stub it out with some hard-coded values since ESXi doesn’t support UPnP? Then, do IP communication since I know the device will always be on and has a static IP address.
2) OR, would it be better to use something like Zabbix or Monit to constantly check the state of the ESXi server and push alerts to ST (then have ST work its magic)?

Thanks in advance!

No, if you know the IP and it is fixed you are good.

I have an app that reboots my Roku devices. It won’t work for you but it will show you how to make local LAN requests. I’m doing a POST, you would do a GET.

def sendKeyPressToRoku(ip, key) {
	log("ip = ${ip} & key = ${key}.", "DEBUG")
    def httpRequest = [
    	method:		"POST",
        path: 		"/keypress/${key}",
        headers: [
                 	HOST:		"${ip}:8060",
                    Accept: 	"*/*",

    def hubAction = new physicalgraph.device.HubAction(httpRequest)

I think I could end up using your app if it worked like this (don’t change your design for me).

After X requests fail (server not up), turn off a switch, wait x seconds, turn it back on.

This is a perfect app for parent / child setup.

1 Like