Zenoss ZenDMD Magic – Fix Invalid Primary Parent on OS and HW

As the zenoss user on the ZenMaster, zendmd.

Copy and paste in the following definition:

## Copyright 2015 GoVanguard Inc. Written by Shane William Scott. http://gvit.com
def fixOsHwPrimaryParent(deviceOrganizerToSearch = '/zport/dmd/Devices', doItForReal = False):
    problemsFound = 0
    if deviceOrganizerToSearch != None:
        print "Getting organizer..."
        organizerOb = dmd.Devices.getOrganizer(deviceOrganizerToSearch)
        if organizerOb:
            print "Collecting device list..."
            devicesToSearch = organizerOb.getSubDevices()
    if len(devicesToSearch) > 0:
        print 'Searching %s devices in %s for bad parents...' % (str(len(devicesToSearch)), deviceOrganizerToSearch)
        for d in devicesToSearch:
                testOs = d.os()
                testHw = d.hw()
                problemsFound = problemsFound + 1
                print "Device %s has a borked primary parent. Fixing" % (d.titleOrId())
                d.os.__primary_parent__ = d
                d.hw.__primary_parent__ = d
                if doItForReal == True:
        print "No devices scanned."
    if problemsFound > 0:
        print "Found and repaired a total of %s bad parents." % (str(problemsFound))
        if doItForReal == False:
            print "...but doItForReal was set to False so the changes are not commited"
        print "Congrats! You're clean! Nothing showed up during the scan for problem parents on OS and HW."

Execute the method to search devices in the provided path for bad parent acquisition on OS and HW objects. Pass doItForReal to ‘True' for actions to be committed. Actions are not committed by default.


fixOsHwPrimaryParent(doItForReal = True)