def multi_date_number_servers(): ## given a list of gdb's, return number of servers by group and total ## output will be a dictionary (date as key) of dictionaries ## per-date dictionaries will have keys of groups and total ## input is two environmental variables: GDBPATH, DATELIST ## GDBPATH is path to graphdb directory ## DATELIST is ascii text of python list of dates of form yyyy.mm.dd ## initialize from env gdbpath = get_gdbpath() datelist = get_datelist() ## init output dict data = {} ## validate all the files exist ## so don't waste time processing a bunch to then have die filelist = [(d, gdbpath + d + ".gdb") for d in datelist] validate_file_access([f for (d, f) in filelist]) ## now process each file for (d, filename) in filelist: one_day_graph = load_graph(filename) ## init the day in output dictionary data[d] = {} data[d]['total'] = 0 for g in get_groups(one_day_graph): data[d][g] = 0 ## loop thru all the servers for svr in one_day_graph.neighbors("type_server"): data[d]['total'] += 1 ## find group and inc g = intermediate(one_day_graph, 'type_group', svr) data[d][g] += 1 return (data)
sg = svr_grp_dict ## Parses dictionary to only include the one group specified (variable "svr_grp") data = (sg[svr_grp]) ##For loop to run through each server in the group specified using the variable ## entered in to the script "svr_grp" - output is server health report for every server in the entire group for svr in data: ## Print each servers health report - each server separated by *** above and below contents print( "**************************************************************************************" ) print("+++ file {0} ".format(gfile)) print("++++ group {0}".format(svr_grp)) print("++++ svr", svr) hostname = intermediate(graphdata, 'type_hostname', svr) print("++++ hostname {0}".format(hostname)) (num_pkg_vers, num_pkgs, pkg_ver_dict, pkg_multiver_dict) = svr_pkgs(graphdata, svr) print("+++++ {0} package/versions".format(num_pkg_vers)) print("+++++ {0} packages".format(num_pkgs)) mypprint(pkg_multiver_dict) ## print supressed cves print("supressed cve's:") scp = svr_cve_pkgs(graphdata, svr) sup_cves = pkg_cve_supr(scp) mypprint(sup_cves) ## print bins of cvss
print("2nd arg is server eg 84a421cd887f11e887244dfe08192208") exit() else: d = sys.argv[1] svr = sys.argv[2] gfile = get_gdbpath() + d + '.gdb' #validate gdb file exists validate_file_access([gfile]) graphdata = load_graph(gfile) print("+++ file {0} ".format(gfile)) print("++++ svr {0}".format(svr)) svr_grp = intermediate(graphdata, 'type_group', svr) print("++++ grp {0}".format(svr_grp)) hostname = intermediate(graphdata, 'type_hostname', svr) print("++++ hostname {0}".format(hostname)) (num_pkg_vers, num_pkgs, pkg_ver_dict, pkg_multiver_dict) = svr_pkgs(graphdata, svr) print("+++++ {0} package/versions".format(num_pkg_vers)) print("+++++ {0} packages".format(num_pkgs)) mypprint(pkg_multiver_dict) ## print supressed cves print("supressed cve's:") scp = svr_cve_pkgs(graphdata, svr) sup_cves = pkg_cve_supr(scp)