def get_firewall_policies(host,authtoken,node_id,prox): queryurl = '/v1/firewall_policies/' results = api.apihit(host, 'GET', authtoken, queryurl, '', prox) details_results = [] for entry in results['firewall_policies']: detail_queryurl = ' /v1/firewall_policies/' + entry['id'] details = api.apihit(host, 'GET', authtoken, detail_queryurl, '', prox) details_results.append(details) #print json.dumps(details_results, indent = 2) return results,details_results
def get_specific(host, authtoken, savepath, data, proxy_host=None, proxy_port=None): conntype ="GET" reqbody = "" dataSpecific = {} policy_csm = [] policy_fim = [] policy_fw = [] policy_lids = [] policy_se = [] for i in data['csm']: queryurl_csm = "/v1/policies/" + i csm = api.apihit(host, conntype, authtoken, queryurl_csm, reqbody,proxy_host, proxy_port) name = csm['policy']['name'] + ".json" outcome = json.dumps(csm, indent = 2) path = savepath + "/csm" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) for i in data['fim']: queryurl_fim = "/v1/fim_policies/" + i fim = api.apihit(host, conntype, authtoken, queryurl_fim, reqbody,proxy_host, proxy_port) name = fim['fim_policy']['name'] +".json" outcome = json.dumps(csm, indent = 2) path = savepath + "/fim" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) for i in data['fw']: queryurl_fw = "/v1/firewall_policies/" + i fw = api.apihit(host, conntype, authtoken, queryurl_fw, reqbody,proxy_host, proxy_port) name = fw['firewall_policy']['name'] + ".json" outcome = json.dumps(fw, indent = 2) path = savepath + "/firewall" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) for i in data['lids']: queryurl_lids = "/v1/lids_policies/" + i lids = api.apihit(host, conntype, authtoken, queryurl_lids, reqbody,proxy_host, proxy_port) name = lids['lids_policy']['name'] + ".json" outcome = json.dumps(lids, indent = 2) path = savepath + "/lids" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) return "Finished backing up all policies\n " + "Checking if the file is empty or not...."
def get_all_policies(host, authtoken, proxy_host=None, proxy_port=None): conntype = "GET" queryurl_csm = "/v1/policies" queryurl_fim = "/v1/fim_policies" queryurl_fw = "/v1/firewall_policies/" queryurl_lids = "/v1/lids_policies/" queryurl_SpecialEvent = "/v1/special_events_policies/" reqbody = "" csm = api.apihit(host, conntype, authtoken, queryurl_csm, reqbody, proxy_host, proxy_port) fim = api.apihit(host, conntype, authtoken, queryurl_fim, reqbody, proxy_host, proxy_port) fw = api.apihit(host, conntype, authtoken, queryurl_fw, reqbody, proxy_host, proxy_port) lids = api.apihit(host, conntype, authtoken, queryurl_lids, reqbody, proxy_host, proxy_port) SpecialEvents = api.apihit(host, conntype, authtoken, queryurl_SpecialEvent, reqbody, proxy_host, proxy_port) data = {} data_csm = [] data_fim = [] data_fw = [] data_lids = [] data_SpecialEvent = [] for entry in csm['policies']: data_csm.append(entry['id']) for entry in fim['fim_policies']: data_fim.append(entry['id']) for entry in fw['firewall_policies']: data_fw.append(entry['id']) for entry in lids['lids_policies']: data_lids.append(entry['id']) for entry in SpecialEvents['special_events_policies']: data_SpecialEvent.append(entry['id']) data = { "csm": data_csm, "fim": data_fim, "fw": data_fw, "lids": data_lids, "se": data_SpecialEvent } return data
def build_server_list(host, authtoken, srch, field, prox): queryurl = '/v1/servers' jsondata = api.apihit(host, 'GET', authtoken, queryurl, '', prox) server_list = [] if srch == 'ALL': prefix = '^.*' else: prefix = '^'+str(srch)+'.*' relevant_servers = distil_server_list(jsondata, prefix, field) for s in relevant_servers: # Needed by Mr. Kozak platform = s["platform"] platform_version = s["platform_version"] os = s["os_version"] kernel = s["kernel_name"] machine = s["kernel_machine"] name = s["hostname"] label = s["server_label"] ident = s["id"] gname = s["group_name"] print (s["connecting_ip_address"] + ", " + name + ", " + platform_version + ", " + platform + ", " + os + ", " + kernel + ", " + machine) server_list.append(server.Server(name, ident, label, gname, platform, platform_version, os, kernel, machine)) if server_list == []: print "Did not find any matching servers to report on!" sys.exit(2) else: return(server_list)
def get_all_policies(host, authtoken, proxy_host=None, proxy_port=None): conntype = "GET" queryurl_csm = "/v1/policies" queryurl_fim = "/v1/fim_policies" queryurl_fw = "/v1/firewall_policies/" queryurl_lids = "/v1/lids_policies/" queryurl_SpecialEvent = "/v1/special_events_policies/" reqbody = "" csm = api.apihit(host, conntype, authtoken, queryurl_csm, reqbody,proxy_host, proxy_port) fim = api.apihit(host, conntype, authtoken, queryurl_fim, reqbody,proxy_host, proxy_port) fw = api.apihit(host, conntype, authtoken, queryurl_fw, reqbody,proxy_host, proxy_port) lids = api.apihit(host, conntype, authtoken, queryurl_lids, reqbody,proxy_host, proxy_port) SpecialEvents = api.apihit(host, conntype, authtoken, queryurl_SpecialEvent, reqbody,proxy_host, proxy_port) data = {} data_csm = [] data_fim = [] data_fw = [] data_lids = [] data_SpecialEvent = [] for entry in csm['policies']: data_csm.append(entry['id']) for entry in fim['fim_policies']: data_fim.append(entry['id']) for entry in fw['firewall_policies']: data_fw.append(entry['id']) for entry in lids['lids_policies']: data_lids.append(entry['id']) for entry in SpecialEvents['special_events_policies']: data_SpecialEvent.append(entry['id']) data={"csm": data_csm, "fim": data_fim, "fw": data_fw, "lids": data_lids, "se": data_SpecialEvent} return data
def build_server_list(host, authtoken, srch, field, prox): queryurl = '/v1/servers' jsondata = api.apihit(host, 'GET', authtoken, queryurl, '', prox) server_list = [] if srch == 'ALL': prefix = '^.*' else: prefix = '^'+str(srch)+'.*' relevant_servers = distil_server_list(jsondata, prefix, field) for s in relevant_servers: name = s["hostname"] label = s["server_label"] ident = s["id"] gname = s["group_name"] server_list.append(server.Server(name, ident, label, gname)) if server_list == []: print "Did not find any matching servers to report on!" sys.exit(2) else: return(server_list)
def get_server_issues(host,authtoken,node_id,prox): queryurl = '/v1/servers/'+str(node_id)+'/issues' results = api.apihit(host, 'GET', authtoken, queryurl, '', prox) return(results)
def get_specific(host, authtoken, prox, savepath,data): conntype ="GET" reqbody = "" dataSpecific = {} policy_csm = [] policy_fim = [] policy_fw = [] policy_lids = [] policy_se = [] print "here" for i in data['csm']: queryurl_csm = "/v1/policies/" + i csm = api.apihit(host, conntype, authtoken, queryurl_csm, reqbody,prox) name = csm['policy']['name'] + ".json" outcome = json.dumps(csm, indent = 2) path = savepath + "/csm" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) for i in data['fim']: queryurl_fim = "/v1/fim_policies/" + i fim = api.apihit(host, conntype, authtoken, queryurl_fim, reqbody,prox) name = fim['fim_policy']['name'] +".json" outcome = json.dumps(csm, indent = 2) path = savepath + "/fim" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) for i in data['fw']: queryurl_fw = "/v1/firewall_policies/" + i fw = api.apihit(host, conntype, authtoken, queryurl_fw, reqbody,prox) name = fw['firewall_policy']['name'] + ".json" outcome = json.dumps(fw, indent = 2) path = savepath + "/firewall" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) for i in data['lids']: queryurl_lids = "/v1/lids_policies/" + i lids = api.apihit(host, conntype, authtoken, queryurl_lids, reqbody,prox) name = lids['lids_policy']['name'] + ".json" outcome = json.dumps(lids, indent = 2) path = savepath + "/lids" completename = os.path.join(path, name) with open (completename, 'w') as outfile: outfile.write(outcome) # for i in data['se']: # queryurl_SpecialEvent = "/v1/special_events_policies/" + i # se = api.apihit(host, conntype, authtoken, queryurl_SpecialEvent, reqbody,prox) # print se # for entry in se['policy']: # name = entry['name'] # policy_se.append((name, se)) return "Finished backing up all policies\n " + "Checking if the file is empty or not...."
def get_specific(host, authtoken, prox, savepath, data): conntype = "GET" reqbody = "" dataSpecific = {} policy_csm = [] policy_fim = [] policy_fw = [] policy_lids = [] policy_se = [] print "here" for i in data['csm']: queryurl_csm = "/v1/policies/" + i csm = api.apihit(host, conntype, authtoken, queryurl_csm, reqbody, prox) name = csm['policy']['name'] + ".json" outcome = json.dumps(csm, indent=2) path = savepath + "/csm" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) for i in data['fim']: queryurl_fim = "/v1/fim_policies/" + i fim = api.apihit(host, conntype, authtoken, queryurl_fim, reqbody, prox) name = fim['fim_policy']['name'] + ".json" outcome = json.dumps(csm, indent=2) path = savepath + "/fim" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) for i in data['fw']: queryurl_fw = "/v1/firewall_policies/" + i fw = api.apihit(host, conntype, authtoken, queryurl_fw, reqbody, prox) name = fw['firewall_policy']['name'] + ".json" outcome = json.dumps(fw, indent=2) path = savepath + "/firewall" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) for i in data['lids']: queryurl_lids = "/v1/lids_policies/" + i lids = api.apihit(host, conntype, authtoken, queryurl_lids, reqbody, prox) name = lids['lids_policy']['name'] + ".json" outcome = json.dumps(lids, indent=2) path = savepath + "/lids" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) # for i in data['se']: # queryurl_SpecialEvent = "/v1/special_events_policies/" + i # se = api.apihit(host, conntype, authtoken, queryurl_SpecialEvent, reqbody,prox) # print se # for entry in se['policy']: # name = entry['name'] # policy_se.append((name, se)) return "Finished backing up all policies\n " + "Checking if the file is empty or not...."
def get_specific(host, authtoken, savepath, data, proxy_host=None, proxy_port=None): conntype = "GET" reqbody = "" dataSpecific = {} policy_csm = [] policy_fim = [] policy_fw = [] policy_lids = [] policy_se = [] for i in data['csm']: queryurl_csm = "/v1/policies/" + i csm = api.apihit(host, conntype, authtoken, queryurl_csm, reqbody, proxy_host, proxy_port) name = csm['policy']['name'] + ".json" outcome = json.dumps(csm, indent=2) path = savepath + "/csm" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) for i in data['fim']: queryurl_fim = "/v1/fim_policies/" + i fim = api.apihit(host, conntype, authtoken, queryurl_fim, reqbody, proxy_host, proxy_port) name = fim['fim_policy']['name'] + ".json" outcome = json.dumps(csm, indent=2) path = savepath + "/fim" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) for i in data['fw']: queryurl_fw = "/v1/firewall_policies/" + i fw = api.apihit(host, conntype, authtoken, queryurl_fw, reqbody, proxy_host, proxy_port) name = fw['firewall_policy']['name'] + ".json" outcome = json.dumps(fw, indent=2) path = savepath + "/firewall" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) for i in data['lids']: queryurl_lids = "/v1/lids_policies/" + i lids = api.apihit(host, conntype, authtoken, queryurl_lids, reqbody, proxy_host, proxy_port) name = lids['lids_policy']['name'] + ".json" outcome = json.dumps(lids, indent=2) path = savepath + "/lids" completename = os.path.join(path, name) with open(completename, 'w') as outfile: outfile.write(outcome) return "Finished backing up all policies\n " + "Checking if the file is empty or not...."