Пример #1
0
def get_report(key, value, request, timespan='latest', environment=None):
    source_url, source_certs, source_verify = get_server(request)
    # If key is any of the below, all is good!
    allowed_keys = ['certname', 'resource_title', 'resource_type', 'containing_class']
    if key in allowed_keys:
        pass
    # If key does not match above the default will be shown
    else:
        key = 'containing_class'

    events_params = {
        'query':
            {
                'operator': 'and',
                2: '["=","' + key + '","' + value + '"]',
                3: '["in", "certname",["extract", "certname",["select_nodes",["null?","deactivated",true]]]]'
            },
    }
    if timespan == 'latest':
        events_params['query'][1] = '["=","latest_report?",true]'
    elif len(timespan) == 2:
        events_params['query'][1] = '["and",[">","timestamp","' + timespan[0] + '"],["<", "timestamp", "' + timespan[
            1] + '"]]'

    results = pdb_api_get(
        api_url=source_url,
        cert=source_certs,
        verify=source_verify,
        path='/events',
        api_version='v4',
        params=mk_puppetdb_query(events_params, request),
    )
    return results
Пример #2
0
def get_report(key, value, request):
    source_url, source_certs, source_verify = get_server(request)
    # If key is any of the below, all is good!
    allowed_keys = [
        'certname', 'resource_title', 'resource_type', 'containing_class'
    ]
    if key in allowed_keys:
        pass
    # If key does not match above the default will be shown
    else:
        key = 'containing_class'

    events_params = {
        'query': {
            'operator':
            'and',
            1:
            '["=","' + key + '","' + value + '"]',
            2:
            '["=","latest_report?",true]',
            3:
            '["in", "certname",["extract", "certname",["select_nodes",["null?","deactivated",true]]]]'
        },
    }
    results = pdb_api_get(
        api_url=source_url,
        cert=source_certs,
        verify=source_verify,
        path='/events',
        api_version='v4',
        params=mk_puppetdb_query(events_params, request),
    )
    return results
Пример #3
0
 def get_resource(certname, rtype, rtitle):
     resource_params = {
         'query': {
             'operator': 'and',
             1: '["=", "certname", "' + certname + '"]',
             2: '["=", "type", "' + rtype + '"]',
             3: '["=", "title", "' + rtitle + '"]'
         },
     }
     data = pdb_api_get(api_url=puppetdb_source,
                        path='resources',
                        verify=puppetdb_verify,
                        cert=puppetdb_certs,
                        params=mk_puppetdb_query(resource_params, request))
     if not data:
         return False
     else:
         return data
Пример #4
0
def get_events_summary(request, timespan='latest'):
    if timespan == 'latest':
        events_params = {
            'query':
                {
                    'operator': 'and',
                    1: '["=","latest_report?",true]',
                    2: '["in","certname",["extract","certname",["select_nodes",["null?","deactivated",true]]]]',
                },
        }
    source_url, source_certs, source_verify = get_server(request)
    events = pdb_api_get(
        api_url=source_url,
        cert=source_certs,
        verify=source_verify,
        path='/events',
        api_version='v4',
        params=mk_puppetdb_query(events_params, request))
    summary = summary_of_events(events)
    return summary
Пример #5
0
def get_events_summary(request, timespan='latest'):
    if timespan == 'latest':
        events_params = {
            'query': {
                'operator':
                'and',
                1:
                '["=","latest_report?",true]',
                2:
                '["in","certname",["extract","certname",["select_nodes",["null?","deactivated",true]]]]',
            },
        }
    source_url, source_certs, source_verify = get_server(request)
    events = pdb_api_get(api_url=source_url,
                         cert=source_certs,
                         verify=source_verify,
                         path='/events',
                         api_version='v4',
                         params=mk_puppetdb_query(events_params, request))
    summary = summary_of_events(events)
    return summary
Пример #6
0
    def get_resource(certname, rtype, rtitle):
        resource_params = {
            'query':
                {
                    'operator': 'and',
                    1: '["=", "certname", "' + certname + '"]',
                    2: '["=", "type", "' + rtype + '"]',
                    3: '["=", "title", "' + rtitle + '"]'

                },
        }
        data = pdb_api_get(
            api_url=puppetdb_source,
            path='resources',
            verify=puppetdb_verify,
            cert=puppetdb_certs,
            params=mk_puppetdb_query(resource_params, request))
        if not data:
            return False
        else:
            return data
Пример #7
0
def get_events_summary(request, timespan='latest', environment=None):
    events_params = {
        'query':
            {
                'operator': 'and',
                2: '["in","certname",["extract","certname",["select_nodes",["null?","deactivated",true]]]]',
            },
    }
    if timespan == 'latest':
        events_params['query'][1] = '["=","latest_report?",true]'
    elif len(timespan) == 2:
        events_params['query'][1] = '["and",[">","timestamp","' + timespan[0] + '"],["<", "timestamp", "' + timespan[
            1] + '"]]'

    source_url, source_certs, source_verify = get_server(request)
    events = pdb_api_get(
        api_url=source_url,
        cert=source_certs,
        verify=source_verify,
        path='/events',
        api_version='v4',
        params=mk_puppetdb_query(events_params, request))
    summary = summary_of_events(events)
    return summary
Пример #8
0
def get_events_summary(request, timespan='latest', environment=None):
    events_params = {
        'query': {
            'operator':
            'and',
            2:
            '["in","certname",["extract","certname",["select_nodes",["null?","deactivated",true]]]]',
        },
    }
    if timespan == 'latest':
        events_params['query'][1] = '["=","latest_report?",true]'
    elif len(timespan) == 2:
        events_params['query'][1] = '["and",[">","timestamp","' + timespan[
            0] + '"],["<", "timestamp", "' + timespan[1] + '"]]'

    source_url, source_certs, source_verify = get_server(request)
    events = pdb_api_get(api_url=source_url,
                         cert=source_certs,
                         verify=source_verify,
                         path='/events',
                         api_version='v4',
                         params=mk_puppetdb_query(events_params, request))
    summary = summary_of_events(events)
    return summary