Skip to content

Commit

Permalink
Added back in some of the old resource types that were counted for th…
Browse files Browse the repository at this point in the history
…e stats, and added a flag stats_all_resources to report and stats commands
  • Loading branch information
0xdabbad00 committed Apr 29, 2019
1 parent 84c1361 commit 89b962d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ htmlcov/
account-data/
tmp/
trusted_ips.png
resource_stats.png
data/
private_commands/
output/
8 changes: 7 additions & 1 deletion commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def report(accounts, config, args):
account_stats = {}
print('* Getting resource counts')
for account in accounts:
account_stats[account['name']] = get_account_stats(account)
account_stats[account['name']] = get_account_stats(account,args.stats_all_resources)
print(' - {}'.format(account['name']))

# Get names of resources
Expand Down Expand Up @@ -374,6 +374,12 @@ def run(arguments):
help="Number of days a user or role hasn't been used before it's marked inactive",
default=90,
type=int)
parser.add_argument(
"--stats_all_resources",
help="Show stats for all resource types",
action='store_true',
default=False,
dest='stats_all_resources')
args, accounts, config = parse_arguments(arguments, parser)

report(accounts, config, args)
22 changes: 17 additions & 5 deletions commands/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def stats(accounts, config, args):
# Collect counts
account_stats = {}
for account in accounts:
account_stats[account['name']] = get_account_stats(account)
account_stats[account['name']] = get_account_stats(account,args.stats_all_resources)
resource_names = account_stats[account['name']]['keys']

# Print header
Expand All @@ -81,10 +81,22 @@ def stats(accounts, config, args):
def run(arguments):
parser = argparse.ArgumentParser()

parser.add_argument('--output_image',
help='Name of output image', default='resource_stats.png', type=str)
parser.add_argument("--no_output_image", help="Don't create output image",
default=False, action='store_true')
parser.add_argument(
'--output_image',
help='Name of output image',
default='resource_stats.png',
type=str)
parser.add_argument(
"--no_output_image",
help="Don't create output image",
default=False,
action='store_true')
parser.add_argument(
"--stats_all_resources",
help="Show stats for all resource types",
action='store_true',
default=False,
dest='stats_all_resources')

args, accounts, config = parse_arguments(arguments, parser)

Expand Down
8 changes: 7 additions & 1 deletion shared/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def parse_arguments(arguments, parser=None):
return (args, accounts, config)


def get_account_stats(account):
def get_account_stats(account, all_resources=False):
"""Returns stats for an account"""

with open("stats_config.yaml", 'r') as f:
Expand All @@ -202,13 +202,19 @@ def get_account_stats(account):
stats = {}
stats['keys'] = []
for resource in resources:
# If the resource is marked as verbose, and we're not showing all resources, skip it.
if resource.get('verbose',False) and not all_resources:
continue
stats['keys'].append(resource['name'])
stats[resource['name']] = {}

for region_json in get_regions(account):
region = Region(account, region_json)

for resource in resources:
if resource.get('verbose',False) and not all_resources:
continue

# Skip global services (just CloudFront)
if ('region' in resource) and (resource['region'] != region.name):
continue
Expand Down
71 changes: 70 additions & 1 deletion stats_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,73 @@
source: kms-list-keys
- name: Lambda functions
query: .Functions|length
source: lambda-list-functions
source: lambda-list-functions
# Verbose resources
- name: Route53 hosted zones
query: .HostedZones|length
source: route53-list-hosted-zones
verbose: true
- name: Route53 domains
query: .Domains|length
source: route53domains-list-domains
verbose: true
- name: EC2 AMIs
query: .Images|length
source: ec2-describe-images
verbose: true
- name: Network ACLs
query: .NetworkAcls|length
source: ec2-describe-network-acls
verbose: true
- name: Route tables
query: .RouteTables|length
source: ec2-describe-route-tables
verbose: true
- name: EC2 snapshots
query: .Snapshots|length
source: ec2-describe-snapshots
verbose: true
- name: VPC endpoints
query: .VpcEndpointConnections|length
source: ec2-describe-vpc-endpoint-connections
verbose: true
- name: VPN connections
query: .VpnConnections|length
source: ec2-describe-vpn-connections
verbose: true
- name: DirectConnects
query: .connections|length
source: directconnect-describe-connections
verbose: true
- name: CloudSearch domains
query: .DomainStatusList|length
source: cloudsearch-describe-domains
verbose: true
- name: ECR repositories
query: .repositories|length
source: ecr-describe-repositories
verbose: true
- name: CloudFormation stacks
query: .Stacks|length
source: cloudformation-describe-stacks
verbose: true
- name: EFS
query: .FileSystems|length
source: efs-describe-file-systems
verbose: true
- name: Cloudwatch alarms
query: .MetricAlarms|length
source: cloudwatch-describe-alarms
verbose: true
- name: Config rules
query: .ConfigRules|length
source: config-describe-config-rules
verbose: true
- name: Event rules
query: .Rules|length
source: events-list-rules
verbose: true
- name: Log groups
query: .logGroups|length
source: logs-describe-log-groups
verbose: true

0 comments on commit 89b962d

Please sign in to comment.