aboutsummaryrefslogtreecommitdiff
path: root/sections/route53.py
blob: d2da7cf59c6cb278cdf518a27d5db283bbcee3ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# route53.py
import boto3
from tabulate import tabulate


def get_section(config):
    profile = config["aws"].get("profile")
    region = config["aws"]["region"]  # Not used by Route53, but kept for consistency

    session = boto3.Session(profile_name=profile if profile else None)
    client = session.client("route53")

    health_checks = client.list_health_checks()["HealthChecks"]
    rows = []

    for hc in health_checks:
        hc_id = hc["Id"]
        name = hc.get("HealthCheckConfig", {}).get(
            "FullyQualifiedDomainName", "Unnamed"
        )
        status = client.get_health_check_status(HealthCheckId=hc_id)
        status_summary = status["HealthCheckObservations"]
        healthy = all(
            obs["StatusReport"]["Status"].startswith("Success")
            for obs in status_summary
        )
        state = "HEALTHY" if healthy else "UNHEALTHY"
        rows.append([name, state])

    if not rows:
        return "Route 53 Health Checks:\nNo health checks configured."

    table = tabulate(rows, headers=["Domain", "Status"], tablefmt="simple_grid")
    lines = [
        "Route 53 Health Checks:",
        f"[https://{config['aws'].get('region')}.console.aws.amazon.com/route53/v2/healthchecks/home]",
        table,
    ]

    return "\n".join(lines)