TECHZEN Zenoss User Community ARCHIVE  

REST method for overall device status?

Subject: REST method for overall device status?
Author: Topher Kessler
Posted: 2017-07-25 20:19

Is there a REST method for getting a device's overall status that mirrors the Up/Down status displayed in the overview? I'm hoping there's something like the following URL that will just give me a boolean value of sorts:

https://zenoss.example.com/zport/dmd/Devices/Ping/Camera/devices/172.17.3.25/getStatus

While I could ping the device from the host running my script, I need to get the status based on the metrics that Zenoss is configured to monitor, so polling each device for its status in Zenoss would be preferred.

Thanks,
-Topher

------------------------------
Topher Kessler
Blue Apron
------------------------------


Subject: RE: REST method for overall device status?
Author: Patrick McMahon
Posted: 2017-07-31 18:20

Checkout the zenoss json api, the "status" property in "data" might be what you're after

https://www.zenoss.com/services-support/documentation/zenoss-json-api-0
You can Google for more Documentation / Examples scattered through github, zenoss knowledge base, zenoss wiki, etc...

Rough example that uses json_api.sh:
zenoss_api device_router DeviceRouter getInfo '{"keys":["status"], "uid":"/zport/dmd/Devices/The/Device/Class/devices/yourdevicename"}'

Expect output like...
{{ "uuid": "blah", "action": "DeviceRouter", "result": { "disabled": false, "data": { "status": true, "uid": "/zport/dmd/Devices/The/Device/Class/devices/yourdevicename" }, "success": true }, "tid": 1, "type": "rpc", "method": "getInfo"}

------------------------------
Patrick McMahon
Sr. Client Services Engineer
Zenoss
------------------------------


Subject: RE: REST method for overall device status?
Author: Kapil Khanduja
Posted: 2018-04-26 05:19

Hi Patrick,

I had the similar requirement of fetching zenoss device's information through "getInfo" method under "DeviceRouter" action. However this method seems to be working only in Device Organizer and not at Device level. 

Everytime I try to execute this method I get - "msg": "ObjectNotFoundException: Cannot find \"/zport/dmd/Devices/Server/Windows/XYZServer\". KeyError: 'XYZServer'", "type": "exception", "success": false}, "tid": 1, "type": "rpc", "method": "getInfo"

And if I execute the same method on Device Organizer till "/zport/dmd/Devices/Server/Windows", I get the desired results.

I am seeking a device information in particular.

Can you please suggest something here.



------------------------------
Kapil Khanduja
Developer
------------------------------


Subject: RE: REST method for overall device status?
Author: Jay Stanley
Posted: 2018-06-28 08:09

@Kapil

It looks like you are not using the proper Uid.

If XYZServer​ is the device name and /Server/Windows/ is the device class, the Uid is most likely:

/zport/dmd/Devices/Server/Windows/devices/XYZServer

You can get the Uid by using the getDevices API call or by looking at the Url when viewing a device.




------------------------------
jstanley
------------------------------


Subject: RE: REST method for overall device status?
Author: randy clark
Posted: 2018-08-15 03:15

Like my wireless home security systems, I make sure it's app is working fine.

------------------------------
randy clark
sas
San Fernando
------------------------------

Subject: RE: REST method for overall device status?
Author: Steve Aiello
Posted: 2018-08-24 12:40

Leveraging zenApiLib, you could use the following code to get the devices in a deviceClass and their statuses in a single API call.

#!/bin/env python

import zenApiLib
zenApi = zenApiLib.zenConnector()
zenApi.setRouter('DeviceRouter')
for pagedResult in zenApi.pagingMethodCall('getDevices', uid='/zport/dmd/Devices', keys=['name', 'status']):
if pagedResult['result']:
for dev in pagedResult['result']['devices']:
print "{} - {}".format(dev['name'], dev['status'])
else:
print "API call success was false"


For Reference, raw API call payload:
{"action":"DeviceRouter","method":"getDevices","data":[{"params":{},"uid":"/zport/dmd/Devices","keys":["name","status"],"page":1,"start":0,"limit":100,"sort":"name","dir":"ASC"}],"type":"rpc","tid":1}


------------------------------
Steve Aiello
Zenoss
------------------------------


< Previous
Events Summary and Message fields size
  Next
Zenpack Issue
>