Example #1
0
def main():
    z = ZenossAPI()
    CI = sys.argv[1]
    deviceinfo = z.get_device(name=CI)
    uid = deviceinfo['uid']
    copy_template(z, uid)
    add_dp_to_graph(z, uid)
Example #2
0
def main():
    z = ZenossAPI()
    data = {}
    with open(sys.argv[1], 'r') as infile:
        for line in infile.readlines():
            (hi, template_name) = line.strip().split(';')
            unbind_template(z, hi, template_name)
            print '\n\n'
Example #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', dest='collector', help='Zenoss collector.', required=True)
    args = parser.parse_args()
    collector = args.collector
    username = "******"
    password = secrets.f5_certificate_check[username]['password']

    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:
        command = "/opt/zenoss/scripts/get_f5_details.py {} {} '{}'".format(device['ipAddressString'], username, password)
        stdout, stderr = Popen(command, stdout=PIPE, stderr=PIPE, shell=True).communicate()
        if not stderr:
            correct_device_class = '/Devices' + stdout.replace('\n', '')
            zenoss_device = z.get_device(name=device['name'])
            current_device_class = zenoss_device['deviceClass']
            if current_device_class.split('/')[-1].isdigit():
                current_device_class = current_device_class.replace('/{}'.format(current_device_class.split('/')[-1]), '')
            if 'Cannot determine the class' in correct_device_class:
                print '{} for {}.'.format(correct_device_class, device['name'])
            else:
                print 'Class of {}: {}. Correct class: {}.'.format(device['name'], current_device_class, correct_device_class)
            if current_device_class == correct_device_class:
                print '\t\t\tOK'
            else:
                print '\t\t\tNOT_OK'
                file_name = '/tmp/f5_add_{}'.format(device['name'])
                f = open(file_name, 'w')
                f.write('{};{};{};{};{}'.format(device['name'], device['ipAddressString'], username, password, zenoss_device['snmpCommunity']))
                f.close()
                add_command = "/opt/zenoss/scripts/add_f5_device.py --file {} -u monapps -p '***' -d".format(file_name)
                stdout, stderr = Popen(add_command, stdout=PIPE, stderr=PIPE, shell=True).communicate()
                print stdout
                print stderr
        else:
            print 'Cannot get details for {}'.format(device['name'])
Example #4
0
def main():
    z = ZenossAPI()
    text_file = sys.argv[1]
    with open(text_file, 'r') as f:
        lines = f.readlines()
        for line in lines:
            CI = line.split(';')[0]
            print colored.blue('=' * 30)
            print colored.blue('Working on {}...'.format(CI))
            datapoints = [dp.replace('\n', '') for dp in line.split(';')[1:]]
            bind_template(z, CI, datapoints)
def main():
    z = ZenossAPI()
    if len(sys.argv) != 2 or sys.argv[1] == '-h':
        usage()
    else:
        text_file = sys.argv[1]
        #if not os.path.isfile(text_file):
        #    sys.exit("The file {} does not exist.".format(text_file))
        with open(text_file, 'r') as f:
            lines = f.readlines()
            for line in lines:
                line_content = line.split(';')
                if len(line_content) == 4:
                    CI = line.split(';')[0]
                    print colored.yellow('='*30)
                    print colored.yellow('Working on {}...'.format(CI))
                    file_path = line.split(';')[1]
                    time_dif = line.split(';')[2]
                    severity = int(line.split(';')[3].replace('\n', ''))
                    try:
                        deviceinfo = z.get_device(name=CI)
                        deviceClass = deviceinfo['deviceClass']
                        if 'Windows/Base' in deviceClass:
                            uid = deviceinfo['uid']
                            #components = z.get_dev_components(uid)
                            #for component in components['result']['data']:
                            #    if component['name'] == 'Cegeka.UpdaterService':
                            collector = deviceinfo['collector']
                            bind_template(z, uid, file_path, time_dif, severity, collector)
                           #         break
                           # else:
                           #     print colored.yellow('INFO :'), '{} does not have the Cegeka.UpdaterService service. \
       # This CI will be skipped.'.format(CI)
                        else:
                            raise Exception('{} is not monitored through WinRM'.format(CI))
                    except Exception as e:
                        print colored.red('ERROR:'), 'Cannot apply the template on {}. {}'.format(CI, e)
                else:
                    print colored.red('ERROR:'), 'The line {} is not correct.'.format(line.replace('\n', ''))
                print colored.yellow('='*30)
                print '\n'
Example #6
0
def main():
    z = ZenossAPI()
    with open(sys.argv[1], 'r') as f:
        for i in f.readlines():
            ci = i.replace('\n', '').strip()
            print 'Working on {}...'.format(ci)
            prop_to_be = '|^\\\\\\\\\\?\\\\|^.*- mvram$)'
            property_name = 'zFileSystemMapIgnoreNames'

            try:
                zenoss_dev = get_zenoss_device(z, ci)
                ci_uid = zenoss_dev['uid']
                old_prop = get_property(z, ci_uid, property_name)
                value = old_prop[:-1] + prop_to_be
            except Exception as e:
                print 'Error for {}: {}'.format(ci, e)
            else:
                try:
                    set_property(z, ci_uid, property_name, value)
                except Exception as e:
                    print 'Error for {}: {}'.format(ci, e)
                else:
                    print 'Property set for {}. Old value: {} | New value: {}'.format(
                        ci, old_prop, value)
Example #7
0
#!/usr/bin/env python

from zen import ZenossAPI

z = ZenossAPI()

all_classes = [
    '/Network/BIG-IP/VCMP/LTM',
    '/Network/BIG-IP/VCMP/HA/LTM',
    '/Network/BIG-IP/VE/LTM',
    '/Network/BIG-IP/VE/HA/LTM',
    '/Network/BIG-IP/APP/LTM',
    '/Network/BIG-IP/APP/HA/LTM',
    '/Network/BIG-IP/VCMP/LTM-APM',
    '/Network/BIG-IP/VCMP/HA/LTM-APM',
    '/Network/BIG-IP/VE/LTM-APM',
    '/Network/BIG-IP/VE/HA/LTM-APM',
    '/Network/BIG-IP/APP/LTM-APM',
    '/Network/BIG-IP/APP/HA/LTM-APM',
    '/Network/BIG-IP/VCMP/LTM-ASM',
    '/Network/BIG-IP/VCMP/HA/LTM-ASM',
    '/Network/BIG-IP/VE/LTM-ASM',
    '/Network/BIG-IP/VE/HA/LTM-ASM',
    '/Network/BIG-IP/APP/LTM-ASM',
    '/Network/BIG-IP/APP/HA/LTM-ASM',
    '/Network/BIG-IP/VCMP/LTM-APM-ASM',
    '/Network/BIG-IP/VCMP/HA/LTM-APM-ASM',
    '/Network/BIG-IP/VE/LTM-APM-ASM',
    '/Network/BIG-IP/VE/HA/LTM-APM-ASM',
    '/Network/BIG-IP/APP/LTM-APM-ASM',
    '/Network/BIG-IP/APP/HA/LTM-APM-ASM',
Example #8
0
#!/usr/bin/env python

import sys
import paramiko
import time
from zen import ZenossAPI
from subprocess import Popen, PIPE
from cmdb import Usd12_dict
import argparse

z = ZenossAPI()
c = Usd12_dict()


def usage():
    return """
Usage: {} --file /path/to/file -u username -p password [-c COLLECTOR] [-d]

The username and password are used to connect to zenossmgmt.
-c COLLECTOR -> Used when a new F5 CI is added in Zenoss. 

The file has this format:
CI;ip;user;password;community_string

The user and password from the file are used to connect to the f5 device.
""".format(sys.argv[0])


def get_collector(ci, username, password, ip):
    deviceinfo = z.get_device(name=ci)
    if deviceinfo:
Example #9
0
"""
Prod
"""

from zen import ZenossAPI

z = ZenossAPI()
result_json = {}

big_ip_devices_all = z.get_devices(
    deviceClass='/zport/dmd/Devices/Network/BIG-IP')['result']['devices']
big_ip_devices = [(x['name'], x['uid']) for x in big_ip_devices_all]

for dev in big_ip_devices:
    name = dev[0]
    uid = dev[1]
    class_name = uid.replace('/devices/{}'.format(name), '')
    result_json[name] = {}
    result_json[name]['class'] = class_name.replace('/zport/dmd/Devices', '')

    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']
Example #10
0
#!/usr/bin/env python


from zen import ZenossAPI
z = ZenossAPI()


all_classes = [
'/Network/BIG-IP/VCMP/LTM',
'/Network/BIG-IP/VCMP/HA/LTM',
'/Network/BIG-IP/VE/LTM',
'/Network/BIG-IP/VE/HA/LTM',
'/Network/BIG-IP/APP/LTM',
'/Network/BIG-IP/APP/HA/LTM',
'/Network/BIG-IP/VCMP/LTM-APM',
'/Network/BIG-IP/VCMP/HA/LTM-APM',
'/Network/BIG-IP/VE/LTM-APM',
'/Network/BIG-IP/VE/HA/LTM-APM',
'/Network/BIG-IP/APP/LTM-APM',
'/Network/BIG-IP/APP/HA/LTM-APM',
'/Network/BIG-IP/VCMP/LTM-ASM',
'/Network/BIG-IP/VCMP/HA/LTM-ASM',
'/Network/BIG-IP/VE/LTM-ASM',
'/Network/BIG-IP/VE/HA/LTM-ASM',
'/Network/BIG-IP/APP/LTM-ASM',
'/Network/BIG-IP/APP/HA/LTM-ASM',
'/Network/BIG-IP/VCMP/LTM-APM-ASM',
'/Network/BIG-IP/VCMP/HA/LTM-APM-ASM',
'/Network/BIG-IP/VE/LTM-APM-ASM',
'/Network/BIG-IP/VE/HA/LTM-APM-ASM',
'/Network/BIG-IP/APP/LTM-APM-ASM',
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'
Example #12
0
#!/usr/bin/env python

import sys
from pprint import pprint as pp
from zen import ZenossAPI

z = ZenossAPI()

network_class = '/Network/BIG-IP'
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])
Example #13
0
#!/usr/bin/env python

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
#!/usr/bin/env python

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',
Example #15
0
    add_dp_to_graph = z.add_data_point_to_graph('{template_uid}/datasources/{dp}/datapoints/{dp}'.format(template_uid=template_uid, dp=dp),
    						 '{}/graphDefs/{}'.format(template_uid, graph))
    if add_dp_to_graph['result'].get('success', False):
        print 'Updating graph point...'
        print z.import_update_graph_point_template(template_uid, 
                        template_uid.split('/')[-1],
                        graph, 
                        dp,
                        line_type='AREA',  
                        )
    else:
        print 'Cannot add graph {}.'.format(graph)



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'] == '':