ZenDMD Tip - Replace modeler plugin programmatically

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

Updating modeler plugins can be a hassle. Why not do it the easy way? The following DMD function allows one to search a list of devices and replace an old plugin with a new one. As the zenoss user on your Zenoss master, zendmd and paste the following code after filling in the plugins you wish to update.

oldPlugin="zenoss.snmp.RouteMap"
newPlugin="zenoss.snmp.NewRouteMap"
def replacePlugin(objs):
for obj in objs:
    if not obj.hasProperty('zCollectorPlugins'): continue
    if oldPlugin not in obj.zCollectorPlugins: continue
    print "Replacing plugin for %s." % obj.id
    obj.zCollectorPlugins = [ p for p in obj.zCollectorPlugins if p != oldPlugin ]
    commit()

Example usage:

replacePlugin(dmd.Devices.Network.Router.Cisco.getSubOrganizers())

and

replacePlugin(dmd.Devices.Network.Router.Cisco.getSubDevices())

Don't forget to

commit()