Created
April 18, 2019 16:47
-
-
Save bookshelfdave/5bb339ab247ae34647b357746a5114ce to your computer and use it in GitHub Desktop.
asg check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
REGIONS=['us-west-2', 'us-east-1', 'eu-central-1', 'ap-northeast-1'] | |
class ASGChecker: | |
def __init__(self, region): | |
self.region = region | |
self.asgclient = boto3.client('autoscaling', region_name=region) | |
self.elbclient = boto3.client('elb', region_name=region) | |
def get_asg_bound_elbs(self): | |
unique_elbs = set() | |
asg_response = self.asgclient.describe_auto_scaling_groups() | |
for asg in asg_response[u'AutoScalingGroups']: | |
print(asg[u'AutoScalingGroupName']) | |
#print(asg['LoadBalancerNames']) | |
for elb in asg[u'LoadBalancerNames']: | |
print("Adding ", elb) | |
unique_elbs.add(elb) | |
return unique_elbs | |
def check_existing_elbs(self, asg_elbs): | |
elb_response = self.elbclient.describe_load_balancers() | |
elbs = elb_response[u'LoadBalancerDescriptions'] | |
elb_names = set(map(lambda e: e[u'LoadBalancerName'], elbs)) | |
#print(elb_names) | |
if asg_elbs <= elb_names: | |
print("ALL bound ELBs exist in", self.region) | |
else: | |
print("Not all bound ELBs exist:") | |
print(esg_elbs - elb_names) | |
def run(self): | |
print("Checking ASGs in", self.region) | |
self.check_existing_elbs(self.get_asg_bound_elbs()) | |
for region in REGIONS: | |
ASGChecker(region).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment