def run(arguments): parser = argparse.ArgumentParser() parser.add_argument("--config", help="Config file name", default="config.json", type=str) parser.add_argument("--account-name", help="Account to collect from", required=False, type=str) parser.add_argument("--profile-name", help="AWS profile name", required=False, type=str) parser.add_argument( '--clean', help='Remove any existing data for the account before gathering', action='store_true') args = parser.parse_args(arguments) if not args.account_name: try: config = json.load(open(args.config)) except IOError: exit("ERROR: Unable to load config file \"{}\"".format( args.config)) except ValueError as e: exit( "ERROR: Config file \"{}\" could not be loaded ({}), see config.json.demo for an example" .format(args.config, e)) args.account_name = get_account(args.account_name, config, args.config)['name'] collect(args)
def run(arguments): parser = argparse.ArgumentParser() parser.add_argument("--config", help="Config file name", default="config.json", type=str) parser.add_argument( "--account", help="Account to collect from", required=False, type=str, dest="account_name", ) parser.add_argument( "--profile", help="AWS profile name", required=False, type=str, dest="profile_name", ) parser.add_argument( "--clean", help= "Remove any existing local, previously collected data for the account before gathering", action="store_true", ) parser.add_argument( "--max-attempts", help="Override Botocore config max_attempts (default 4)", required=False, type=int, dest="max_attempts", default=4, ) parser.add_argument( "--regions", help="Filter and query AWS only for the given regions (CSV)", required=False, type=str, dest="regions_filter", default="", ) args = parser.parse_args(arguments) if not args.account_name: try: config = json.load(open(args.config)) except IOError: exit('ERROR: Unable to load config file "{}"'.format(args.config)) except ValueError as e: exit( 'ERROR: Config file "{}" could not be loaded ({}), see config.json.demo for an example' .format(args.config, e)) args.account_name = get_account(args.account_name, config, args.config)["name"] collect(args)
def run(arguments): # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--config", help="Config file name", default="config.json", type=str) parser.add_argument("--account-name", help="Account to collect from", required=False, type=str) parser.add_argument("--regions", help="Regions to restrict to (ex. us-east-1,us-west-2)", default=None, type=str) parser.add_argument("--vpc-ids", help="VPC ids to restrict to (ex. vpc-1234,vpc-abcd)", default=None, type=str) parser.add_argument("--vpc-names", help="VPC names to restrict to (ex. prod,dev)", default=None, type=str) parser.add_argument("--internal-edges", help="Show all connections (default)", dest='internal_edges', action='store_true') parser.add_argument("--no-internal-edges", help="Only show connections to external CIDRs", dest='internal_edges', action='store_false') parser.add_argument("--inter-rds-edges", help="Show connections between RDS instances", dest='inter_rds_edges', action='store_true') parser.add_argument("--no-inter-rds-edges", help="Do not show connections between RDS instances (default)", dest='inter_rds_edges', action='store_false') parser.add_argument("--read-replicas", help="Show RDS read replicas (default)", dest='read_replicas', action='store_true') parser.add_argument("--no-read-replicas", help="Do not show RDS read replicas", dest='read_replicas', action='store_false') parser.add_argument("--azs", help="Show availability zones (default)", dest='azs', action='store_true') parser.add_argument("--no-azs", help="Do not show availability zones", dest='azs', action='store_false') parser.add_argument("--collapse-by-tag", help="Collapse nodes with the same tag to a single node", dest='collapse_by_tag', default=None, type=str) parser.set_defaults(internal_edges=True) parser.set_defaults(inter_rds_edges=False) parser.set_defaults(read_replicas=True) parser.set_defaults(azs=True) args = parser.parse_args(arguments) outputfilter = {} if args.regions: # Regions are given as 'us-east-1,us-west-2'. Split this by the comma, # wrap each with quotes, and add the comma back. This is needed for how we do filtering. outputfilter["regions"] = ','.join(['"' + r + '"' for r in args.regions.split(',')]) if args.vpc_ids: outputfilter["vpc-ids"] = ','.join(['"' + r + '"' for r in args.vpc_ids.split(',')]) if args.vpc_names: outputfilter["vpc-names"] = ','.join(['"' + r + '"' for r in args.vpc_names.split(',')]) outputfilter["internal_edges"] = args.internal_edges outputfilter["read_replicas"] = args.read_replicas outputfilter["inter_rds_edges"] = args.inter_rds_edges outputfilter["azs"] = args.azs outputfilter["collapse_by_tag"] = args.collapse_by_tag # Read accounts file try: config = json.load(open(args.config)) except IOError: exit("ERROR: Unable to load config file \"{}\"".format(args.config)) except ValueError as e: exit("ERROR: Config file \"{}\" could not be loaded ({}), see config.json.demo for an example".format(args.config, e)) account = get_account(args.account_name, config, args.config) prepare(account, config, outputfilter)
def run(arguments): # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--config", help="Config file name", default="config.json", type=str) parser.add_argument( "--account", help="Account to collect from", required=False, type=str, dest="account_name", ) parser.add_argument( "--regions", help="Regions to restrict to (ex. us-east-1,us-west-2)", default=None, type=str, ) parser.add_argument( "--vpc-ids", help="VPC ids to restrict to (ex. vpc-1234,vpc-abcd)", default=None, type=str, ) parser.add_argument( "--vpc-names", help="VPC names to restrict to (ex. prod,dev)", default=None, type=str, ) parser.add_argument( "--tags", help= "Filter nodes matching tags (ex. Name=batch,Env=prod), where the tag matches are AND'd together. Use this tag multiple times to OR sets (ex. --tags Env=prod --tags Env=Dev)", dest="tags", default=None, type=str, action="append", ) parser.add_argument( "--internal-edges", help="Show all connections (default)", dest="internal_edges", action="store_true", ) parser.add_argument( "--no-internal-edges", help="Only show connections to external CIDRs", dest="internal_edges", action="store_false", ) parser.add_argument( "--inter-rds-edges", help="Show connections between RDS instances", dest="inter_rds_edges", action="store_true", ) parser.add_argument( "--no-inter-rds-edges", help="Do not show connections between RDS instances (default)", dest="inter_rds_edges", action="store_false", ) parser.add_argument( "--read-replicas", help="Show RDS read replicas (default)", dest="read_replicas", action="store_true", ) parser.add_argument( "--no-read-replicas", help="Do not show RDS read replicas", dest="read_replicas", action="store_false", ) parser.add_argument( "--azs", help="Show availability zones (default)", dest="azs", action="store_true", ) parser.add_argument( "--no-azs", help="Do not show availability zones", dest="azs", action="store_false", ) parser.add_argument( "--collapse-by-tag", help="Collapse nodes with the same tag to a single node", dest="collapse_by_tag", default=None, type=str, ) parser.add_argument( "--collapse-asgs", help= "Show a single node for Auto Scaling Groups instead of all contained instances (default)", dest="collapse_asgs", action="store_true", ) parser.add_argument( "--no-collapse-asgs", help="Show all EC2 instances of Auto Scaling Groups", dest="collapse_asgs", action="store_false", ) parser.set_defaults(internal_edges=True) parser.set_defaults(inter_rds_edges=False) parser.set_defaults(read_replicas=True) parser.set_defaults(azs=True) parser.set_defaults(collapse_asgs=True) args = parser.parse_args(arguments) outputfilter = {} if args.regions: # Regions are given as 'us-east-1,us-west-2'. Split this by the comma, # wrap each with quotes, and add the comma back. This is needed for how we do filtering. outputfilter["regions"] = ",".join( ['"' + r + '"' for r in args.regions.split(",")]) if args.vpc_ids: outputfilter["vpc-ids"] = ",".join( ['"' + r + '"' for r in args.vpc_ids.split(",")]) if args.vpc_names: outputfilter["vpc-names"] = ",".join( ['"' + r + '"' for r in args.vpc_names.split(",")]) if args.tags: outputfilter["tags"] = args.tags outputfilter["internal_edges"] = args.internal_edges outputfilter["read_replicas"] = args.read_replicas outputfilter["inter_rds_edges"] = args.inter_rds_edges outputfilter["azs"] = args.azs outputfilter["collapse_by_tag"] = args.collapse_by_tag outputfilter["collapse_asgs"] = args.collapse_asgs # Read accounts file try: config = json.load(open(args.config)) except IOError: exit('ERROR: Unable to load config file "{}"'.format(args.config)) except ValueError as e: exit( 'ERROR: Config file "{}" could not be loaded ({}), see config.json.demo for an example' .format(args.config, e)) account = get_account(args.account_name, config, args.config) prepare(account, config, outputfilter)
def run(arguments): parser = argparse.ArgumentParser() parser.add_argument( "--config", help="Config file name", default="config.json", type=str ) parser.add_argument( "--account", help="Account to collect from", required=False, type=str, dest="account_name", ) parser.add_argument( "--get-all", help="Get all accounts in config.json, overrides --profile and --account", required=False, type=str, dest="get_all" ) parser.add_argument( "--profile", help="AWS profile name", required=False, type=bool, dest="profile_name", ) parser.add_argument( "--clean", help="Remove any existing data for the account before gathering", action="store_true", ) args = parser.parse_args(arguments) try: config = json.load(open(args.config)) except IOError: exit('ERROR: Unable to load config file "{}"'.format(args.config)) except ValueError as e: exit( 'ERROR: Config file "{}" could not be loaded ({}), see config.json.demo for an example'.format( args.config, e ) ) if args.get_all == "True": failed_accounts = [] print("\U0001F606 Lets do a lot!") # create a text trap and redirect stdout text_trap = io.StringIO() for account in config["accounts"]: # restore stdout function sys.stdout = sys.__stdout__ print("Mapping : " + account["name"]) # redirect stdout sys.stdout = text_trap try : args.account_name = account["name"] args.profile_name = account["name"] collect(args) except: failed_accounts.append(account["name"]) sys.stdout = sys.__stdout__ print("\U0001F635 Failed Accounts: ") print(*failed_accounts, sep = ", ") else: if not args.account_name: args.account_name = get_account(args.account_name, config, args.config)["name"] collect(args)
def test_get_collection_date(self): account = get_account("demo") assert_equal("2019-05-07T15:40:22+00:00", get_collection_date(account))
def test_get_account_stats(self): account = get_account("demo") stats = get_account_stats(account, True) assert_equal(stats["EC2 instances"]["us-east-1"], 3)
def test_get_collection_date(self): account = get_account("demo") assert_equal('2019-05-07', get_collection_date(account))
def test_get_account_stats(self): account = get_account("demo") stats = get_account_stats(account, True) assert_equal(stats['EC2 instances']['us-east-1'], 3)