We would occasionally have problems with our Processes which resulted in a 'KeyError' error. Usually running the following commands via the zendmd command would fix these errors:
> reindex()
> commit()
However there are cases where that doesn't work. The script listed below attempts to fix that (in a very quick and dirty way).
Based on information found in the thread: message/43380 I found that we had Orphaned entries in the Process list tables. A working entry would be listed as:
'/zport/dmd/Devices/Server/Linux/devices/server.company.com/os/processes/httpd'
where a broken entry would be listed as:
'httpd'
or
'httpd AAAAAAAA000000'
Note that the working entry has a full path where as the broken one doesn't.
The following code will go through and remove anything without a full path.
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
#CHANGEME
# to get the path navigate to the problem area in your browser and
# look at the URL. So for:
# http://zenoss.yourcompany.com/zport/dmd/Processes/Apache/osProcessClasses/httpd
# Your path will be
# dmd.Processes.Apache.osProcessClasses.httpd
fixpath = dmd.Processes.Apache.osProcessClasses.httpd
ind = 0
print "--- "
for i in fixpath.instances():
thispath = i.getPrimaryId()
if thispath.find('/zport') != 0:
print " Deleting: %i %s" % (ind , thispath)
fixpath.instances._remove(i)
ind = ind + 1
print " ** Committing changes"
# Uncomment the line below to actually save the changes.
# commit()