Matthew Purdy
2013-04-02 21:54:02 UTC
Matthew Purdy [http://community.zenoss.org/people/mpurdy] created the discussion
"a basic tree traversal of all devices"
To view the discussion, visit: http://community.zenoss.org/message/72687#72687
--------------------------------------------------------------
i have a basic script which i started; which traverses the dmd tree and then call a method device_info(d) to return all the attributes from the device (using *http://fqdn:8080/zport/dmd/manage http://fqdn:8080/zport/dmd/manage*, clicking on *Devices* and then clicking on the *"property" tab*)
problem is when i iterate over the dmd.Devices the objects are strings; which then i cannot get any of the attributes. i was assuming that dmd.Devices would return an object reference to some sub-class of DeviceClass.
+question: once you get the list of devices as a string; how can you then use that string to get all its attributes? also, is there a way to just simple get the DeviceClass objects directly?+
def *indent_spaces*(level = 1):
       ret = ''
       indent = '  '
       for i in xrange(level):
               ret += indent
       return ret
def *device_info*(device, level = 1):
       ret = ""
      Â
       #add device description
       ret += indent_spaces(level)
       ret += 'description => '
       ret += device.description
       ret += "\n"
       #add device zPythonClass
       ret += indent_spaces(level)
       ret += 'pythonClass => '
       ret += device.zPythonClass
       ret += "\n"
       # add more attributes here
       return ret
dmd = ZenScriptBase(connect=True).dmd
print '######################################'
print 'dmd.Devices'
print '######################################'
for d in dmd.Devices:
         print "device => %s " % d
         print *device_info(d)*
print ''
print ''
print '######################################'
print 'dmd.Devices.getSubDevices'
print '######################################'
for d in dmd.Devices.getSubDevices():
        print "device.subDevice => %s" % d
        print *device_info(d)*
print ''
print ''
--------------------------------------------------------------
Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/72687#72687]
Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
"a basic tree traversal of all devices"
To view the discussion, visit: http://community.zenoss.org/message/72687#72687
--------------------------------------------------------------
i have a basic script which i started; which traverses the dmd tree and then call a method device_info(d) to return all the attributes from the device (using *http://fqdn:8080/zport/dmd/manage http://fqdn:8080/zport/dmd/manage*, clicking on *Devices* and then clicking on the *"property" tab*)
problem is when i iterate over the dmd.Devices the objects are strings; which then i cannot get any of the attributes. i was assuming that dmd.Devices would return an object reference to some sub-class of DeviceClass.
+question: once you get the list of devices as a string; how can you then use that string to get all its attributes? also, is there a way to just simple get the DeviceClass objects directly?+
def *indent_spaces*(level = 1):
       ret = ''
       indent = '  '
       for i in xrange(level):
               ret += indent
       return ret
def *device_info*(device, level = 1):
       ret = ""
      Â
       #add device description
       ret += indent_spaces(level)
       ret += 'description => '
       ret += device.description
       ret += "\n"
       #add device zPythonClass
       ret += indent_spaces(level)
       ret += 'pythonClass => '
       ret += device.zPythonClass
       ret += "\n"
       # add more attributes here
       return ret
dmd = ZenScriptBase(connect=True).dmd
print '######################################'
print 'dmd.Devices'
print '######################################'
for d in dmd.Devices:
         print "device => %s " % d
         print *device_info(d)*
print ''
print ''
print '######################################'
print 'dmd.Devices.getSubDevices'
print '######################################'
for d in dmd.Devices.getSubDevices():
        print "device.subDevice => %s" % d
        print *device_info(d)*
print ''
print ''
--------------------------------------------------------------
Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/72687#72687]
Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]