1

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

请指出我正确的方向。

4

1 回答 1

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
于 2016-04-04T22:10:07.407 回答