2024-08-05 02:30:34 +00:00
|
|
|
from models import RuleCheckResult
|
|
|
|
import boto3
|
|
|
|
|
|
|
|
|
2024-08-08 07:46:20 +00:00
|
|
|
client = boto3.client("autoscaling")
|
2024-08-05 02:30:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def autoscaling_group_elb_healthcheck_required():
|
2024-08-08 07:46:20 +00:00
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
|
|
|
asgs = client.describe_auto_scaling_groups()["AutoScalingGroups"]
|
|
|
|
|
|
|
|
for asg in asgs:
|
2024-08-08 11:19:41 +00:00
|
|
|
if asg["LoadBalancerNames"] or asg["TargetGroupARNs"] and asg["HealthCheckType"] != "ELB":
|
2024-08-08 07:46:20 +00:00
|
|
|
non_compliant_resources.append(asg["AutoScalingGroupARN"])
|
2024-08-08 11:19:41 +00:00
|
|
|
else:
|
|
|
|
compliant_resources.append(asg["AutoScalingGroupARN"])
|
2024-08-08 07:46:20 +00:00
|
|
|
|
2024-08-05 02:30:34 +00:00
|
|
|
return RuleCheckResult(
|
2024-08-08 07:46:20 +00:00
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
2024-08-05 02:30:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def autoscaling_multiple_az():
|
2024-08-08 07:46:20 +00:00
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
|
|
|
asgs = client.describe_auto_scaling_groups()["AutoScalingGroups"]
|
|
|
|
|
|
|
|
for asg in asgs:
|
2024-08-08 11:19:41 +00:00
|
|
|
if len(asg["AvailabilityZones"]) > 1:
|
2024-08-08 07:46:20 +00:00
|
|
|
compliant_resources.append(asg["AutoScalingGroupARN"])
|
|
|
|
else:
|
|
|
|
non_compliant_resources.append(asg["AutoScalingGroupARN"])
|
|
|
|
|
2024-08-05 02:30:34 +00:00
|
|
|
return RuleCheckResult(
|
2024-08-08 07:46:20 +00:00
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
2024-08-05 02:30:34 +00:00
|
|
|
)
|