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
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
def get_resource(certname, rtype, rtitle): data = pdb_api_get( api_url=puppetdb_source, path='nodes/' + certname + '/resources/' + rtype + '/' + rtitle, verify=puppetdb_verify, cert=puppetdb_certs) if not data: return False else: return data
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
def get_events_summary(request, timespan='latest'): if timespan == 'latest': events_params = { 'query': { 1: '["and",["=","latest-report?",true],["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)) summary = summary_of_events(events) return summary
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
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
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