templates = [x['uid'] for x in z.get_templates(uid)['result']] for template in templates: template_name = template.split('/')[-1] result_json[name][template_name] = { 'datasources': {}, 'thresholds': {} } datasources = [{ 'name': x['name'], 'source': x['source'] } for x in z.get_data_sources(template)['result']['data']] thresholds = [{ 'name': x['name'], 'ds': x['dsnames'] } for x in z.get_thresholds(template)['result']['data']] for ds in datasources: if not result_json[name][template_name]['datasources'].get( ds['name']): result_json[name][template_name]['datasources'][ ds['name']] = ds['source'] else: print 'Datasource {} already exists.'.format(ds['name']) for thr in thresholds: if not result_json[name][template_name]['thresholds'].get( thr['name']): result_json[name][template_name]['thresholds'][ thr['name']] = thr['ds'] else: print 'Threshold {} already exists'.format(thr)
from zen import ZenossAPI import sys z = ZenossAPI() template_uid = sys.argv[1] print 'Removing datasources...' try: for datasource in z.get_data_sources(template_uid)['result']['data']: print '\t--{}'.format(datasource['name']) print z.del_data_source(datasource['uid']) except Exception as e: print e print '\nRemoving graphs...' try: for graph in z.list_graphs(template_uid)['result']: print '\t--{}'.format(graph['name']) print z.del_graph(graph['uid']) except Exception as e: print e print '\nRemoving thresholds...' try: for threshold in z.get_thresholds(template_uid)['result']['data']: print '\t--{}'.format(threshold['name']) print z.del_threshold(threshold['uid']) except Exception as e: print e
template_name = sys.argv[1] root_template = '/zport/dmd/Devices/rrdTemplates/' class_templates = [ x['uid'] for x in z.get_subbindings(template_name, network_class) ] f = open('/tmp/template_report_{}.txt'.format(template_name), 'w') f.write('\nTemplate\t{}\n'.format(template_name)) print 'Working on {}'.format(root_template + template_name) global_template_datasources = z.get_data_sources( root_template + template_name)['result']['data'] global_datasources = set([x['name'] for x in global_template_datasources]) global_template_thresholds = z.get_thresholds(root_template + template_name)['result']['data'] global_thresholds = set([x['name'] for x in global_template_thresholds]) global_template_graphs = z.list_graphs(root_template + template_name)['result'] global_graphs = set([x['name'] for x in global_template_graphs]) extra_datasources = [] unique_extra_datasources = [] extra_thresholds = [] unique_extra_thresholds = [] extra_graphs = [] unique_extra_graphs = [] for local_template in class_templates: print 'Working on {}'.format(local_template) local_template_datasources = z.get_data_sources( local_template)['result']['data']
from zen import ZenossAPI from clint.textui import colored import sys import os z = ZenossAPI() with open(sys.argv[1], 'r') as f: for ci in f.readlines(): ci = ci.replace('\n', '') print 'Working on {}'.format(ci) with open('/tmp/threshold_report.csv', 'a') as g: deviceinfo = z.get_device(name=ci) uid = deviceinfo['uid'] templates = z.get_obj_templates(uid=uid) g.write( '\nCI NUMBER|TEMPLATE|THRESHOLD|THRESHOLD TYPE|DATAPOINTS|MinVal|MaxVal|SEVERITY|Time Period|Violation Percentage|ENABLED\n' ) for template in templates['result']['data']: t_uid = template['uid'] template_name = template['name'] thresholds = z.get_thresholds(t_uid)['result']['data'] if thresholds: for thr in thresholds: g.write('{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}\n'.format( ci, template_name, thr['name'], thr['type'], thr['dataPoints'], thr['minval'] or 'n/a', thr['maxval'] or 'n/a', thr['severity'], thr.get('timePeriod', False) or 'n/a', thr.get('violationPercentage', False) or 'n/a', thr['enabled']))