apizenoss

How to get device names based on group name in zenoss?


Is there any API to get all the device names under the same group in zenoss?

Please point me in the right direction.


Solution

  • I am using Python for querying the devices under zenoss group. Key is sending request with data='{"action":"DeviceRouter", "method":"getDevices","data":[{"uid":"/zport/dmd/Devices/"}],"tid":1}')

    import requests
    def getZenossDeviceList(zenossURI, username, password, data): 
        try:
                s = requests.Session()
                s.auth = (username, password)
                s.headers["Content-Type"] = "application/json"
                r = s.post(zenossURI, data=data, timeout=(3.05, 30));
        except Exception as ex:
                raise Exception("getZenossDeviceList: {0}",ex )
        else:
                if r.status_code == requests.codes.ok:
                        return r.json()
                else:
                        raise Exception("getZenossDeviceList: {0}", r.reason)
    
    
     def getServerList(username,password):
          hostList = []
          zenossURI="https://<ZENOSSS_SERVER_IP>/zport/dmd/device_router"
    
        try:
                r = getZenossDeviceList(zenossURI, username, password,\
                        data='{"action":"DeviceRouter", "method":"getDevices","data":[{"uid":"/zport/dmd/Devices/<AbsolutePath_for_Groupname>"}],"tid":1}')
                print r
        except Exception as e:
                print "Exception", e