Skip to content

Instantly share code, notes, and snippets.

@cktricky
Created January 30, 2017 00:58
Show Gist options
  • Save cktricky/f19e8d55ea5dcb1fdade6ede588c6576 to your computer and use it in GitHub Desktop.
Save cktricky/f19e8d55ea5dcb1fdade6ede588c6576 to your computer and use it in GitHub Desktop.
List Configuration of Monitoring Services in AWS
import boto3
import pprint
pp = pprint.PrettyPrinter(indent=5, width=80, compact=False)
#http://docs.aws.amazon.com/general/latest/gr/rande.html
regions = ['us-east-1', 'us-west-2', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'eu-central-1', 'eu-west-1']
'''
The following code is to list out how the config service is used, if its used at all
'''
# MAKE SURE YOU CHANGE THESE VALUES OR THE TOOL WON'T WORK.
access_key_id = 'replace me'
secret_access_key = 'replace me'
def print_section_header_and_footer(text, end=False):
print("-" * 50)
print(text)
print("-" * 50)
if end:
print("\n\n")
print_section_header_and_footer("BEGINNING OF CONFIG SERVICE REVIEW")
for region in regions:
client = boto3.client(
'config',
aws_access_key_id = access_key_id,
aws_secret_access_key = secret_access_key,
region_name=region
)
response = client.describe_configuration_recorders()
def print_config_text(text):
print("#" * len(text))
config_service_text = "Config Service Recorders"
print_config_text(config_service_text)
print(config_service_text)
print("Region:" + region)
print_config_text(config_service_text)
if len(response['ConfigurationRecorders']) <= 0:
print("NO CONFIGURATION DETECTED")
else:
for group in response['ConfigurationRecorders']:
pp.pprint(group['recordingGroup'])
print_section_header_and_footer("END OF CONFIG SERVICE REVIEW", True)
'''
The following lists if CloudTrail is enabled per region
'''
print_section_header_and_footer("BEGINNING OF CLOUDTRAIL SERVICE REVIEW")
list_of_trails = []
list_of_trail_arns = []
for region in regions:
client = boto3.client(
'cloudtrail',
aws_access_key_id = access_key_id,
aws_secret_access_key = secret_access_key,
region_name=region
)
response = client.describe_trails()
trail_list = response['trailList']
for trail in trail_list:
if not trail['TrailARN'] in list_of_trail_arns:
list_of_trail_arns.append(trail['TrailARN'])
list_of_trails.append(trail)
for item in list_of_trails:
pp.pprint(item)
print_section_header_and_footer("END OF CLOUDTRAIL SERVICE REVIEW", True)
'''
The following lists CloudWatch alarms per region.
'''
print_section_header_and_footer("BEGINNING OF CLOUDWATCH ALARM REVIEW")
for region in regions:
client = boto3.client(
'cloudwatch',
aws_access_key_id = access_key_id,
aws_secret_access_key = secret_access_key,
region_name=region
)
text = "Region: " + region
print("#" * len(text))
print(text)
print("#" * len(text))
response = client.describe_alarms()
for alarm in response['MetricAlarms']:
pp.pprint(alarm)
print_section_header_and_footer("END OF CLOUDWATCH ALARM REVIEW", True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment