From 098b90d6f3049c84349dbc3e4ca4f4f8dda3376f Mon Sep 17 00:00:00 2001 From: Guillaume BOURGEOIS Date: Tue, 21 Jul 2026 22:18:01 +0200 Subject: [PATCH] feat(harfanglab): alert triage commands (tag, comment, details, history) Co-Authored-By: Claude Fable 5 --- .../harfanglab/scripts/alert_comment.py | 32 +++++++++++++++ .../harfanglab/scripts/alert_details.py | 32 +++++++++++++++ .../harfanglab/scripts/alert_history.py | 32 +++++++++++++++ integrations/harfanglab/scripts/alert_tag.py | 41 +++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 integrations/harfanglab/scripts/alert_comment.py create mode 100644 integrations/harfanglab/scripts/alert_details.py create mode 100644 integrations/harfanglab/scripts/alert_history.py create mode 100644 integrations/harfanglab/scripts/alert_tag.py diff --git a/integrations/harfanglab/scripts/alert_comment.py b/integrations/harfanglab/scripts/alert_comment.py new file mode 100644 index 0000000..789326b --- /dev/null +++ b/integrations/harfanglab/scripts/alert_comment.py @@ -0,0 +1,32 @@ +import json, os, sys, urllib.request, urllib.parse, urllib.error + + +def request(method, url, headers, body=None): + data = json.dumps(body).encode("utf-8") if body is not None else None + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as resp: + raw = resp.read() + return json.loads(raw) if raw else {} + + +def main(): + secrets = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + base = secrets.get("url", "").rstrip("/") + headers = { + "Authorization": "Token " + secrets.get("api_token", ""), + "Accept": "application/json", + "Content-Type": "application/json", + } + url = base + "/api/data/alert/alert/Alert/" + str(inputs.get("alert_id")) + "/comment/" + print(json.dumps(request("POST", url, headers, {"comment": inputs.get("comment")}))) + + +try: + main() +except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) +except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) diff --git a/integrations/harfanglab/scripts/alert_details.py b/integrations/harfanglab/scripts/alert_details.py new file mode 100644 index 0000000..f3fc973 --- /dev/null +++ b/integrations/harfanglab/scripts/alert_details.py @@ -0,0 +1,32 @@ +import json, os, sys, urllib.request, urllib.parse, urllib.error + + +def request(method, url, headers, body=None): + data = json.dumps(body).encode("utf-8") if body is not None else None + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as resp: + raw = resp.read() + return json.loads(raw) if raw else {} + + +def main(): + secrets = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + base = secrets.get("url", "").rstrip("/") + headers = { + "Authorization": "Token " + secrets.get("api_token", ""), + "Accept": "application/json", + "Content-Type": "application/json", + } + url = base + "/api/data/alert/alert/Alert/" + str(inputs.get("alert_id")) + "/details/" + print(json.dumps(request("GET", url, headers))) + + +try: + main() +except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) +except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) diff --git a/integrations/harfanglab/scripts/alert_history.py b/integrations/harfanglab/scripts/alert_history.py new file mode 100644 index 0000000..359a32d --- /dev/null +++ b/integrations/harfanglab/scripts/alert_history.py @@ -0,0 +1,32 @@ +import json, os, sys, urllib.request, urllib.parse, urllib.error + + +def request(method, url, headers, body=None): + data = json.dumps(body).encode("utf-8") if body is not None else None + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as resp: + raw = resp.read() + return json.loads(raw) if raw else {} + + +def main(): + secrets = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + base = secrets.get("url", "").rstrip("/") + headers = { + "Authorization": "Token " + secrets.get("api_token", ""), + "Accept": "application/json", + "Content-Type": "application/json", + } + url = base + "/api/data/alert/alert/Alert/" + str(inputs.get("alert_id")) + "/history/" + print(json.dumps(request("GET", url, headers))) + + +try: + main() +except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) +except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1) diff --git a/integrations/harfanglab/scripts/alert_tag.py b/integrations/harfanglab/scripts/alert_tag.py new file mode 100644 index 0000000..1619064 --- /dev/null +++ b/integrations/harfanglab/scripts/alert_tag.py @@ -0,0 +1,41 @@ +import json, os, sys, urllib.request, urllib.parse, urllib.error + + +def csv(v): + return [x.strip() for x in str(v or "").split(",") if x.strip()] + + +def request(method, url, headers, body=None): + data = json.dumps(body).encode("utf-8") if body is not None else None + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as resp: + raw = resp.read() + return json.loads(raw) if raw else {} + + +def main(): + secrets = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + base = secrets.get("url", "").rstrip("/") + headers = { + "Authorization": "Token " + secrets.get("api_token", ""), + "Accept": "application/json", + "Content-Type": "application/json", + } + body = { + "ids": csv(inputs.get("alert_ids")), + "new_status": inputs.get("new_status"), + } + if inputs.get("new_comment"): + body["new_comment"] = inputs.get("new_comment") + print(json.dumps(request("POST", base + "/api/data/alert/alert/Alert/tag/", headers, body))) + + +try: + main() +except urllib.error.HTTPError as e: + print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")})) + sys.exit(1) +except Exception as e: + print(json.dumps({"error": str(e)})) + sys.exit(1)