From 529a8be6406288985ce70ab84520ebd214f5ea83 Mon Sep 17 00:00:00 2001 From: Alexander Amiri Date: Mon, 16 Mar 2026 22:37:55 +0100 Subject: [PATCH] Fix alert resource names for ELB and CI source attribution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resource names: - Add extraction for ELB target groups, rules, listeners from nested response structures (targetGroups[0].targetGroupName, etc.) - Add fallback for request name/ARN fields CI source: - Extract run ID from session name convention (javabin-*-{run_id}) - Infer repo from role name (ci-infra → platform, ci-app-X → X) - Builds GitHub Actions run link even when OIDC session tags are absent --- terraform/lambda-src/slack_alert/handler.py | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/terraform/lambda-src/slack_alert/handler.py b/terraform/lambda-src/slack_alert/handler.py index 42ebd10..6f4642e 100644 --- a/terraform/lambda-src/slack_alert/handler.py +++ b/terraform/lambda-src/slack_alert/handler.py @@ -305,6 +305,24 @@ def parse_identity(detail): ci_ctx["repo"] = sub_match.group(1) ci_ctx["ref"] = sub_match.group(2) + # Fallback: extract run ID from our session name convention + # Pattern: javabin-{purpose}-{run_id} or javabin-{repo}-{purpose}-{run_id} + if not ci_ctx.get("GitHubRunID"): + run_match = re.search(r"-(\d{8,})$", session) + if run_match: + ci_ctx["GitHubRunID"] = run_match.group(1) + + # Fallback: infer repo from role name if not resolved + # javabin-ci-infra → javaBin/platform + # javabin-ci-app-{repo} → javaBin/{repo} + if not ci_ctx.get("repo") and not ci_ctx.get("GitHubRepo"): + if "ci-infra" in role_name: + ci_ctx["repo"] = f"{GITHUB_ORG_URL.split('/')[-1]}/platform" + else: + app_match = re.match(r"javabin-ci-app-(.+)", role_name) + if app_match: + ci_ctx["repo"] = f"{GITHUB_ORG_URL.split('/')[-1]}/{app_match.group(1)}" + return f"{role_name} (CI/CD)", True, ci_ctx or None # Non-CI assumed role @@ -376,6 +394,21 @@ def extract_resource_name(event_name, detail): if event_name == "ModifyInstanceAttribute": return request.get("instanceId") + # ELB: target groups, rules, listeners (nested response structures) + for list_key in ("targetGroups", "rules", "listeners"): + items = response.get(list_key, []) + if items and isinstance(items, list): + item = items[0] + name = item.get("targetGroupName") or item.get("listenerArn") or item.get("ruleArn") + if name: + return name.split("/")[-1] if "/" in str(name) else name + + # Fallback: check request for name/arn patterns + for key in ("name", "targetGroupArn", "listenerArn", "ruleArn"): + val = request.get(key) + if val and isinstance(val, str): + return val.split("/")[-1] if "/" in val else val + return None