如何在zenoss中根据组名获取设备名称?

时间:2016-03-08 04:24:48

标签: api zenoss

是否有任何API可以在zenoss中获取同一组下的所有设备名称?

请指出正确的方向。

1 个答案:

答案 0 :(得分:2)

我正在使用Python查询zenoss组下的设备。 密钥是发送请求,其中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