0f5f4a900e
Falcon records a verdict as a tag — true_positive, false_positive or ignored, which the console's Resolution column reads — and update_status only takes new, in_progress, reopened and closed, so resolve_detection had no way to record one. Its new verdict input adds the tag after removing the other two, add_tag never replacing one; status and verdict are drop-downs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WhDQSYZd1mFtRsXK4ixtyB
78 lines
3.3 KiB
Python
78 lines
3.3 KiB
Python
import json, os, sys, urllib.request, urllib.parse, urllib.error
|
|
|
|
SECRETS = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
|
INPUTS = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
|
BASE = SECRETS.get("base_url", "https://api.crowdstrike.com").rstrip("/")
|
|
|
|
|
|
def token():
|
|
data = urllib.parse.urlencode({"client_id": SECRETS.get("client_id", ""), "client_secret": SECRETS.get("client_secret", "")}).encode()
|
|
req = urllib.request.Request(BASE + "/oauth2/token", data=data, headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}, method="POST")
|
|
with urllib.request.urlopen(req, timeout=30) as r:
|
|
return json.loads(r.read()).get("access_token", "")
|
|
|
|
|
|
def call(method, path, tok, params=None, body=None):
|
|
url = BASE + path
|
|
if params:
|
|
# params is a list of (key, value) tuples to allow repeated keys (e.g. ids)
|
|
url += "?" + urllib.parse.urlencode(params)
|
|
data = json.dumps(body).encode() if body is not None else None
|
|
headers = {"Authorization": "Bearer " + tok, "Accept": "application/json"}
|
|
if data is not None:
|
|
headers["Content-Type"] = "application/json"
|
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
|
with urllib.request.urlopen(req, timeout=90) as r:
|
|
raw = r.read()
|
|
return json.loads(raw) if raw else {}
|
|
|
|
|
|
def csv(v):
|
|
return [x.strip() for x in str(v or "").split(",") if x.strip()]
|
|
|
|
|
|
VERDICTS = ("true_positive", "false_positive", "ignored")
|
|
|
|
|
|
def main():
|
|
tok = token()
|
|
ids = csv(INPUTS.get("ids"))
|
|
verdict = str(INPUTS.get("verdict") or "").strip()
|
|
if verdict and verdict not in VERDICTS:
|
|
raise ValueError("verdict must be one of " + ", ".join(VERDICTS) + ", got " + verdict)
|
|
action_params = []
|
|
if verdict:
|
|
# The console's Resolution is read from these tags, and add_tag never
|
|
# replaces one: drop the other two first, or a false positive turned
|
|
# true positive would show both. Removing a tag the alert does not
|
|
# carry is not an error worth stopping for — the add below is the call
|
|
# that has to land.
|
|
for other in VERDICTS:
|
|
if other == verdict:
|
|
continue
|
|
try:
|
|
call("PATCH", "/alerts/entities/alerts/v3", tok,
|
|
body={"action_parameters": [{"name": "remove_tag", "value": other}], "composite_ids": ids})
|
|
except urllib.error.HTTPError:
|
|
pass
|
|
action_params.append({"name": "add_tag", "value": verdict})
|
|
if INPUTS.get("status"):
|
|
action_params.append({"name": "update_status", "value": str(INPUTS["status"])})
|
|
if INPUTS.get("comment"):
|
|
action_params.append({"name": "append_comment", "value": str(INPUTS["comment"])})
|
|
if INPUTS.get("assign_to_uuid"):
|
|
action_params.append({"name": "assign_to_uuid", "value": str(INPUTS["assign_to_uuid"])})
|
|
body = {"action_parameters": action_params, "composite_ids": ids}
|
|
result = call("PATCH", "/alerts/entities/alerts/v3", tok, body=body)
|
|
print(json.dumps(result))
|
|
|
|
|
|
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)
|