def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        dest='collector',
                        help='Zenoss collector.',
                        required=True)
    args = parser.parse_args()
    collector = args.collector
    template_name = 'CgkF5VpnConn'

    z = ZenossAPI()
    big_ip_devices = z.get_devices('/zport/dmd/Devices/Network/BIG-IP')
    collector_devices = []
    if big_ip_devices['result'].get('devices', False):
        for device in big_ip_devices['result']['devices']:
            if device['collector'] == collector:
                collector_devices.append(device)
    else:
        print 'No BIG-IP devices found on {}\n{}'.format(
            collector, big_ip_devices)

    for device in collector_devices:
        zenoss_device = z.get_device(name=device['name'])
        templates = z.get_templates(zenoss_device['uid'])['result']

        template_found = False
        template_local = False
        differences_found = False
        for template in templates:
            if template_name in template['text'] and template[
                    'path'] == 'Locally Defined':
                template_found = True
                template_local = True
                break
            elif template_name in template['text']:
                template_found = True
                break

        if template_found and template_local:
            print 'Working on {}'.format(device['name'])
            datasource_uid = z.get_data_sources(
                template['uid'])['result']['data'][0]['uid']
            zenoss_datapoints = [{
                'newId': x['newId'],
                'uid': x['uid']
            } for x in z.get_data_points(template['uid'])['result']['data']]
            zenoss_datapoints_no_uid = set(
                [x['newId'] for x in zenoss_datapoints])
            graphs = [{
                'id': x['id'],
                'uid': x['uid']
            } for x in z.list_graphs(template['uid'])['result']]
            snmp_datapoints = set(
                get_snmp_data(device['ipAddressString'],
                              zenoss_device['snmpCommunity']))
            missing_datapoints = list(snmp_datapoints -
                                      zenoss_datapoints_no_uid)
            extra_datapoints = list(zenoss_datapoints_no_uid - snmp_datapoints)

            if missing_datapoints or extra_datapoints:
                differences_found = True

            if differences_found:
                print '\t--differences found.'
                print 'Missing: {}'.format(missing_datapoints)
                print 'Extra: {}'.format(extra_datapoints)
                for ds in missing_datapoints:
                    dp_uid = ''
                    add_dp = z.add_data_point(datasource_uid, ds)
                    if add_dp['result'].get('success', False):
                        print '\t-----datapoint {} added.'.format(ds)
                    else:
                        print '\t-----datapoint {} NOT ADDED. ERROR.'.format(
                            ds)
                    add_graph = z.add_graph(template['uid'], ds)
                    if add_graph['result'].get('success', False):
                        print '\t-----graph {} added.'.format(ds)
                    else:
                        print '\t-----graph {} NOT ADDED. ERROR.'.format(ds)
                    sleep(3)
                    all_datapoints = [{
                        'newId': x['newId'],
                        'uid': x['uid']
                    } for x in z.get_data_points(template['uid'])['result']
                                      ['data']]
                    all_graphs = [{
                        'id': x['id'],
                        'uid': x['uid']
                    } for x in z.list_graphs(template['uid'])['result']]
                    for dp in all_datapoints:
                        if ds == dp['newId']:
                            dp_uid = dp['uid']
                            break
                    for graph in all_graphs:
                        if graph['id'] == ds:
                            add_dp_to_graph = z.add_data_point_to_graph(
                                dp_uid, graph['uid'])
                            if add_dp_to_graph['result'].get('success', False):
                                print '\t-----datapoint {} added to the graph.'.format(
                                    ds)
                            else:
                                print '\t-----datapoint {} was not added to the graph. ERROR.'.format(
                                    ds)
                            break

                for ds in extra_datapoints:
                    for dp in zenoss_datapoints:
                        if dp['newId'] == ds:
                            del_dp = z.del_data_point(dp['uid'])
                            if del_dp['result'].get('success', False):
                                print '\t-----datapoint {} removed.'.format(ds)
                            else:
                                print '\t-----datapoint {} was not removed. ERROR.'.format(
                                    ds)
                    for dp in graphs:
                        if dp['id'] == ds:
                            del_graph = z.del_graph(dp['uid'])
                            if del_graph['result'].get('success', False):
                                print '\t-----graph {} removed.'.format(ds)
                            else:
                                print '\t-----graph {} was not removed. ERROR.'.format(
                                    ds)
            else:
                print '\t--no differences found.'
        elif template_found:
            print 'Working on {}'.format(device['name'])
            print 'Template globally bound.'
        print '\n\n'
Пример #2
0
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
Пример #3
0
    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']
    local_template_thresholds = z.get_thresholds(
        local_template)['result']['data']
    local_template_graphs = z.list_graphs(local_template)['result']
Пример #4
0
z = ZenossAPI()


apm_template = '/zport/dmd/Devices/rrdTemplates/CgkF5Apm'
ltm_template = '/zport/dmd/Devices/rrdTemplates/CgkF5LTM'


print 'Removing the cgk_f5_apm datasource from CgkF5Apm...'
for datasource in z.get_data_sources(apm_template)['result']['data']:
    if 'cgk_f5_apm' == datasource['name']:
        print z.del_data_source(datasource['uid'])
        print '\n\n'

print 'Removing empty graphs from CgkF5Apm...'
for graph in z.list_graphs(apm_template)['result']:
    if graph['graphPoints'] == '':
	    print '\t--{}'.format(graph['name'])
	    print z.del_graph(graph['uid'])

print 'Creating the apmAccessStatCurrentActiveSessions datasource in CgkF5Apm...'
add_snmp_ds(apm_template, 'apmAccessStatCurrentActiveSessions', '1.3.6.1.4.1.3375.2.6.1.5.3.0')


print 'Add apmAccessStatCurrentActiveSessions to the apmAccessStatCurrentActiveSessions graph in CgkF5Apm...'
add_dp_to_graph(apm_template, 'apmAccessStatCurrentActiveSessions', 'apmAccessStatCurrentActiveSessions')


print 'Add datasources and graphs to CgkF5LTM...'
ds_dict = {
              'sysAttrFailoverIsRedundant': '.1.3.6.1.4.1.3375.2.1.1.1.1.13.0',