Can anyone tell me how to do the following from within a modeler plugin (i.e. SnmpPlugin) within a Zenpack? My goal is to find a device in the dmd database with a given attribute (in this case a specific MAC address) and create a zLink to that device on my Overview page.
1. Obtain a reference to the dmd root. The purpose is to be able to get or set properties of other devices in the database.
For example, the following code fragment runs fine from within zendmd:
for dev in dmd.Devices.Server.getSubDevices():
print "Device: %s, IP: %s, MAC: %s at:%s" % (dev.getDeviceName(),dev.getDeviceIpAddress(),dev.getDeviceMacaddress(),dev.getDeviceUrl())
But if I try to implement that from within my modeler plugin I get something like:
2011-10-22 19:40:56,740 ERROR zen.ZenModeler: Problem while executing plugin community.snmp.IBMIMMDeviceMap
2011-10-22 19:40:56,743 ERROR zen.ZenModeler: Traceback (most recent call last):
File "/opt/zenoss/Products/DataCollector/zenmodeler.py", line 613, in processClient
datamaps = plugin.process(device, results, self.log)
File "/opt/zenoss/local/ZenPacks.community.IBMSystemxIMM/ZenPacks/community/IBMSystemxIMM/modeler/plugins/community/snmp/IBMIMMDeviceMap.py", line 128, in process
for dev in dmd.Devices.Server.getSubDevices():
NameError: global name 'dmd' is not defined
Is there a simple import I'm missing? Are there any priviledge issues WRT setting vs. getting device parameters?
2. Obtain a reference to myself (i.e. the current instance of my device Object Class). The purpose is to be able to get or set properties of the current device, by operating on methods supported by the device.
For example, I can do the following from within zendmd, and this will update the zLink on the device's Overview page.
device=find('some.device.by.id')
zenLink = "Some URL corresponding to the thing I want to create a link to."
device.manage_changeProperties(zLinks=zenLink)
commit()
But if I try to implement that from within my modeler plugin, using the 'device' variable available from within my modeler class, I get something like:
2011-10-22 18:50:44,057 ERROR zen.ZenModeler: Problem while executing plugin community.snmp.IBMIMMDeviceMap
2011-10-22 18:50:44,060 ERROR zen.ZenModeler: Traceback (most recent call last):
File "/opt/zenoss/Products/DataCollector/zenmodeler.py", line 613, in processClient
datamaps = plugin.process(device, results, self.log)
File "/opt/zenoss/local/ZenPacks.community.IBMSystemxIMM/ZenPacks/community/IBMSystemxIMM/modeler/plugins/community/snmp/IBMIMMDeviceMap.py", line 138, in process
device.manage_changeProperties(zLinks=zenLink)
AttributeError: DeviceProxy instance has no attribute 'manage_changeProperties'
Apparently, 'device' here is an instance of class: DeviceProxy, not class: Device. And the methods directly supported by class DeviceProxy are very limited.
Is there some way I can "walk back" from the DeviceProxy class to the Device class from which it was created? And then operation on my device (i.e myself) directly?
NOTE: If I had 1. but not 2. I could still do what need by looking myself up in the database, assuming find() would work within the modeler plugin:
myDevice = find('device.id')
I used the following excellent reference to do the above withing zendmd. But there is no mention of how to do the same from within a running Zenpack:
http://www.nickyeates.com/technology/zenoss/dmd
Thanks!