Several scripts for zendmd manipulations provided by Zenoss engineer Kells Kearney.
copy_alert_rules.zendmd
import sys
source_name = 'blue'
target_names = [ 'green' ]
source = getattr(dmd.ZenUsers, source_name, None)
if source is None:
print "The source user/group named '%s' does not exist" % source_name
sys.exit(1)
rules = source.getActionRules()
copied = 0
for target_name in target_names:
target = getattr(dmd.ZenUsers, target_name, None)
if target is None:
print "No user/group named '%s' found -- skipping" % target_name
continue
for rule in rules:
try:
target.manage_addActionRule(rule.id)
except:
# Ignore duplicate rule names
continue
new_rule = [x for x in target.getActionRules() if x.id == rule.id][0]
new_rule.where = rule.where
new_rule.format = rule.format
new_rule.body = rule.body
new_rule.sendClear = rule.sendClear
new_rule.clearFormat = rule.clearFormat
new_rule.clearBody = rule.clearBody
new_rule.delay = rule.delay
new_rule.action = rule.action
new_rule.enabled = rule.enabled
new_rule.targetAddr = rule.targetAddr
new_rule.repeatTime = rule.repeatTime
new_rule.plainText = rule.plainText
for name, sched in rule.windows.objectItemsAll():
try:
new_rule.manage_addActionRuleWindow(name)
except:
# Ignore duplicate window names
continue
new_sched = [y for x, y in new_rule.windows.objectItemsAll() if x == name][0]
new_sched.start = sched.start
new_sched.started = sched.started
new_sched.duration = sched.duration
new_sched.repeat = sched.repeat
new_sched.skip = sched.skip
copied += 1
print "Copied alerting rules to %d targets" % copied
commit()
move_devices_to_collector.zendmd
import sys
import re
targetCollectorName = 'myCollectorName'
regex = re.compile('^prefix_string')
collectors = dmd.Monitors.getPerformanceMonitorNames()
if targetCollectorName not in collectors:
print "Collector '%s' is not in the list of known collectors %s" % (
targetCollectorName, collectors)
sys.exit(1)
for dev in dmd.Devices.getSubDevices():
if regex.match(dev.id):
print "Moving %s to %s" % (dev.id, targetCollectorName)
dev.setPerformanceMonitor(targetCollectorName)
commit()
rename_devices.py
from xmlrpclib import ServerProxy, ProtocolError
# Needs to be reset for your site
baseUrl = 'http://admin:zenoss@localhost:8080'
fd = open('/tmp/devices_list')
for line in fd:
try:
oldname, newname = line.split()
print "Attempting to update %s's name to %s" % (oldname, newname)
url = '/'.join([baseUrl, oldname])
serv = ServerProxy( url )
serv.renameDevice(newname)
except: # Ignore all errors
pass
zendmd_copy_datasources.py
import sys
device = find('blue')
template_name = 'HttpMonitor'
template = device.getRRDTemplateByName(template_name)
source_DS = 'demo_cacti'
for ds in template.getRRDDataSources():
if ds.id == source_DS:
source_DS = ds
all_datapoints = ds.getRRDDataPoints()
break
else:
print "Unable to find DS %s in template %s" % (source_DS, template_name)
sys.exit(1)
available_DS_types = dict(template.getDataSourceOptions())
dsOptionString = available_DS_types[ source_DS.sourcetype ]
new_DS = [ 'dsCopy1', 'dsCopy2','dsCopy3','dsCopy4','dsCopy5',]
for ds_name in new_DS:
DS = template.manage_addRRDDataSource(ds_name, dsOptionString)
# Copy data source information -- specific to template type
DS.enabled = source_DS.enabled
DS.usessh = source_DS.usessh
DS.component = source_DS.component
DS.eventClass = source_DS.eventClass
DS.eventKey = source_DS.eventKey
DS.severity = source_DS.severity
DS.cycletime = source_DS.cycletime
DS.parser = source_DS.parser
DS.commandTemplate = source_DS.commandTemplate
#
# Copy datapoint information over
for dp in all_datapoints:
new_dp = DS.manage_addRRDDataPoint(dp.id)
new_dp.rrdtype = dp.rrdtype
new_dp.rdmin=dp.rrdmin
new_dp.rdmax=dp.rrdmax
new_dp.reateCmd=dp.createCmd
#commit()