2024-08-14 01:05:06 +00:00
|
|
|
from models import RuleCheckResult, RuleChecker
|
|
|
|
from functools import cached_property
|
2024-08-05 02:30:34 +00:00
|
|
|
import boto3
|
|
|
|
|
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
class ASGRuleChecker(RuleChecker):
|
|
|
|
def __init__(self):
|
|
|
|
self.client = boto3.client("autoscaling")
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
@cached_property
|
|
|
|
def asgs(self):
|
|
|
|
return self.client.describe_auto_scaling_groups()["AutoScalingGroups"]
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
def autoscaling_group_elb_healthcheck_required(self):
|
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
2024-08-08 07:46:20 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
for asg in self.asgs:
|
|
|
|
if (
|
|
|
|
asg["LoadBalancerNames"]
|
|
|
|
or asg["TargetGroupARNs"]
|
|
|
|
and asg["HealthCheckType"] != "ELB"
|
|
|
|
):
|
|
|
|
non_compliant_resources.append(asg["AutoScalingGroupARN"])
|
|
|
|
else:
|
|
|
|
compliant_resources.append(asg["AutoScalingGroupARN"])
|
2024-08-08 07:46:20 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
return RuleCheckResult(
|
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
|
|
|
)
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
def autoscaling_multiple_az(self):
|
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
for asg in self.asgs:
|
|
|
|
if len(asg["AvailabilityZones"]) > 1:
|
|
|
|
compliant_resources.append(asg["AutoScalingGroupARN"])
|
|
|
|
else:
|
|
|
|
non_compliant_resources.append(asg["AutoScalingGroupARN"])
|
2024-08-08 07:46:20 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
return RuleCheckResult(
|
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
|
|
|
)
|
2024-08-08 07:46:20 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
def autoscaling_launch_template(self):
|
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
|
|
|
|
|
|
|
for asg in self.asgs:
|
|
|
|
if "LaunchConfigurationName" in asg:
|
|
|
|
non_compliant_resources.append(asg["AutoScalingGroupARN"])
|
|
|
|
else:
|
|
|
|
compliant_resources.append(asg["AutoScalingGroupARN"])
|
|
|
|
|
|
|
|
return RuleCheckResult(
|
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
rule_checker = ASGRuleChecker
|