Skip to content

Instantly share code, notes, and snippets.

@reecestart
Last active November 20, 2019 16:57
Show Gist options
  • Save reecestart/7ec7fca5594ad1c6b1d8800d306b9260 to your computer and use it in GitHub Desktop.
Save reecestart/7ec7fca5594ad1c6b1d8800d306b9260 to your computer and use it in GitHub Desktop.
List all Personal Health Dashboard events in all regions and get affected entities with Python

List all Personal Health Dashboard events in all regions and get affected entities with Python

healthdemo.py

import boto3 # Import Python SDK for AWS
from pprint import pprint # For pretty printing
import sys # For exiting later on
healthclient = boto3.client('health',region_name='us-east-1') # Create the Health Client which is only in N. Virginia
# Get all Health Events
response = healthclient.describe_events(
)
# Print all Health Events
events = (response['events'])
print("You have " + str(len(events)) + " events")
x = 1
for i in events:
print("Event " + str(x))
print(i['service'] + " - " + i['eventTypeCode'] + " - " + i['region'] + " - " + i['statusCode'])
x = x + 1
print()
eventNumber = input("Which Event would you like more detail on? ") # Prompt user for Event #
eventNumber = int(eventNumber) - 1 # Array starts at zero so decrease by 1
eventARN = events[eventNumber]['arn'] # Get the Event ARN
# Describe particular health event details
response = healthclient.describe_event_details(
eventArns=[
eventARN,
]
)
# Print the event description in legible format
description = response['successfulSet'][0]['eventDescription']['latestDescription']
description = description.replace("\r","")
description = description.replace("\n","")
print(description)
# Set up the yes or no question for more detail on that event
def yes_or_no(question):
reply = str(input(question+' (y/n): ')).lower().strip()
if reply[0] == 'y':
return True
if reply[0] == 'n':
sys.exit()
else:
return yes_or_no("Uhhhh... please enter ")
yes_or_no('Would you like more detail on this event? ') # Prompt user if they want more detail
# Get list of affected entities for the event by ARN
response = healthclient.describe_affected_entities(
filter={
'eventArns': [
eventARN,
]
}
)
# print out the affected entity information
for i in response['entities']:
print("Affected entities:")
pprint(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment