Esempio n. 1
0
def get_bt_details(transaction_filter=None, **kwargs):
    result = {}
    if transaction_filter is None:
        transaction_filter = kwargs['transactionFilter']
    endpoint = 'http://%s/controller/rest/applications/%s/business-transactions' \
        % (kwargs['controllerHost'], kwargs['application'])
    try:
        data = get_data(endpoint, kwargs['username'], kwargs['password'])
        # print data
    except:
        raise CommandInvocationError(
            'Error fetching business transaction details.')
    for transaction in data:
        transaction_id = str(transaction['id'])
        if transaction_id in transaction_filter or transaction_filter == '*':
            t = {
                'tierName': transaction['tierName'],
                'btName': transaction['name'],
                'displayName': get_bt_display_name(transaction['name'])
            }
            result[transaction_id] = t
    if len(result) == 0:
        raise CommandInvocationError(
            'No business transactions found for the specified IDs.')
    return result
Esempio n. 2
0
def command(options, args):
    if not options:
        raise CommandInvocationError('missing command: create_hr_transaction [args...]')
    bts=get_bt_details(**options)
    rules=create_bt_rules('OPS', '#', bts, **options)
    filename=create_rules_file('rules_output/transaction_rules.xml',rules)
    response=post_rules_file(filename, **options)
    print response
Esempio n. 3
0
def command(options, args):
    if not options:
        raise CommandInvocationError(
            'missing command: create_hr_infrastructure [args...]')
    tiers = get_tiers(**options)
    rules = create_infrastructure_rules('OPS', '#', tiers, **options)
    filename = create_rules_file('rules_output/infra_rules.xml', rules)
    response = post_rules_file(filename, **options)
    print response
Esempio n. 4
0
def get_application_name(**kwargs):
    application_id = kwargs['application']
    endpoint = 'http://%s/controller/rest/applications' \
        % (kwargs['controllerHost'])
    try:
        data = get_data(endpoint, kwargs['username'], kwargs['password'])
    except:
        raise CommandInvocationError('Error fetching application name.')
    for application in data:
        if str(application['id']) == str(application_id):
            return application['name']
Esempio n. 5
0
def get_healthrules(**kwargs):
    endpoint = 'http://%s/controller/healthrules/%s' \
        % (kwargs['controllerHost'], kwargs['application'])
    try:
        data = get_data(endpoint,
                        kwargs['username'],
                        kwargs['password'],
                        json=False)
    except:
        raise CommandInvocationError('Error fetching health rules.')
    return data
Esempio n. 6
0
def post_dashboard_file(filename, **kwargs):
    files = {'file': (filename, open(filename, 'rb'), 'application/json')}
    endpoint = 'http://%s/controller/CustomDashboardImportExportServlet' \
        % (kwargs['controllerHost'])
    try:
        r = requests.post(endpoint,
                          auth=(kwargs['username'], kwargs['password']),
                          files=files)
        return r._content
    except Exception as e:
        raise CommandInvocationError('Error posting dashboard JSON.')
Esempio n. 7
0
def get_endpoint(**kwargs):
    http_method = 'http'
    if 'client_ssl' in kwargs:
        client_ssl = bool(kwargs['client_ssl'])
        if client_ssl is True:
            http_method = 'https'
            if 'cert' not in kwargs or 'key' not in kwargs:
                raise CommandInvocationError("Both cert and key have to be specified when client_ssl is set to true.")
    endpoint = '%s://%s/%s' \
        % (http_method, kwargs['server'], API_ENDPOINT)
    return endpoint
Esempio n. 8
0
def has_jdbc_metrics(tier_id, **kwargs):
    endpoint = "http://%s/controller/rest/applications/%s/metric-data?metric-path=Application Infrastructure Performance|%s|JMX|JDBC Connection Pools|%s|Active Connections&time-range-type=BEFORE_NOW&duration-in-mins=15" \
        % (kwargs['controllerHost'], kwargs['application'], tier_id, '*')
    try:
        data = get_data(endpoint, kwargs['username'], kwargs['password'])
    except:
        raise CommandInvocationError(
            'Error verifying if tier has JDBC metrics.')
    if len(data) > 0:
        return True
    else:
        return False
Esempio n. 9
0
def get_tiers_with_details(**kwargs):
    tiers = {}
    tier_filter = kwargs['tierFilter']
    endpoint = 'http://%s/controller/rest/applications/%s/tiers' \
        % (kwargs['controllerHost'], kwargs['application'])
    try:
        data = get_data(endpoint, kwargs['username'], kwargs['password'])
    except:
        raise CommandInvocationError('Error fetching tiers from application.')
    for tier in data:
        if tier['name'] in tier_filter or tier_filter == '*':
            t = {'tierName': tier['name']}
            tiers[tier['id']] = t
    return tiers
Esempio n. 10
0
def get_tiers(**kwargs):
    tier_names = []
    tier_filter = kwargs['tierFilter']
    endpoint = 'http://%s/controller/rest/applications/%s/tiers' \
        % (kwargs['controllerHost'], kwargs['application'])
    try:
        data = get_data(endpoint, kwargs['username'], kwargs['password'])
    except:
        raise CommandInvocationError('Error fetching tiers from application.')
    for tier in data:
        if tier_filter == '*':
            tier_names.append(tier['name'])
        elif tier['name'] in tier_filter:
            tier_names.append(tier['name'])
    return tier_names
Esempio n. 11
0
def post_rules_file(file, **kwargs):
    params = {"overwrite": "true"}
    files = {
        'file': ('fileUpload', open(file, 'rb'), 'application/xml', {
            'Expires': '0'
        })
    }
    endpoint = 'http://%s/controller/healthrules/%s' \
        % (kwargs['controllerHost'], kwargs['application'])
    try:
        r = requests.post(endpoint,
                          params=params,
                          auth=(kwargs['username'], kwargs['password']),
                          files=files)
        # print r._content
        return r._content
    except:
        raise CommandInvocationError('Error posting rules XML.')
Esempio n. 12
0
def command(options, args):
    if not options:
        raise CommandInvocationError(
            'missing command: create_dashboard [args...]')
    application_name = get_application_name(**options)
    rules = get_healthrules(**options)
    tiers = get_tiers_with_details(**options)
    bts = get_bt_details('*', **options)
    status_dashboards = {}
    for tier in tiers:
        infra_hrs = get_infrastructure_hrs('#', rules, tiers[tier]['tierName'])
        transaction_hrs = get_transaction_hrs('#', rules,
                                              tiers[tier]['tierName'])
        x = 25
        y = 10
        status_widget_height = 140
        status_widget_width = 140
        status_dashboard = create_status_dashboard(tiers[tier]['tierName'])
        infra_row = create_row_in_status_dashboard(
            status_widget_height, status_widget_width, x, y, application_name,
            'Application Infrastructure', infra_hrs)
        y = y + 50 + status_widget_height + 50
        transaction_drilldown_url = DRILLDOWN_URLS['bt'] \
                    % (options['controllerHost'], options['application'])
        transaction_row = create_row_in_status_dashboard(
            status_widget_height, status_widget_width, x, y, application_name,
            'Key Transactions', transaction_hrs, bts,
            transaction_drilldown_url)
        eventstream_drilldown_url = DRILLDOWN_URLS['eventStream'] \
                    % (options['controllerHost'], options['application'], tier)
        event_stream_widget = create_eventstream_widget(
            application_name, tiers[tier]['tierName'])
        event_stream_link_widget = create_eventstream_link_widget(
            eventstream_drilldown_url)
        status_dashboard["widgetTemplates"].extend(infra_row)
        status_dashboard["widgetTemplates"].extend(transaction_row)
        status_dashboard["widgetTemplates"].append(event_stream_widget)
        status_dashboard["widgetTemplates"].append(event_stream_link_widget)
        status_dashboards[tiers[tier]['tierName']] = status_dashboard
    for key in status_dashboards:
        file_name = 'dashboard_output/status_dashboard_%s.json' % (key)
        create_dashboard_file(file_name, status_dashboards[key])
        post_dashboard_file(file_name, **options)
Esempio n. 13
0
def command(options, args):
    if not options:
        raise CommandInvocationError('missing command: deploy_api [args...]')
    print("YAAY")
Esempio n. 14
0
def command(options, args):
    if not options:
        raise CommandInvocationError('missing command: delete_api [args...]')
    delete_apis(**options)
Esempio n. 15
0
def command(options, args):
    if not options:
        raise CommandInvocationError('missing command: update_api [args...]')
    update_api(**options)