Compare commits

...

3 Commits

Author SHA1 Message Date
Guillaume BOURGEOIS 041cadade2 feat(extrahop): new ExtraHop Reveal(x) NDR integration
ExtraHop REST API v1, 6 commands: search/get detections, list/search devices,
get device. ESA API-key auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:48:03 +02:00
Guillaume BOURGEOIS 41e8aa8e7e feat(vectra): new Vectra AI NDR integration
Vectra Detect API v2.3, 8 commands: list/get detections, mark detection fixed,
add note, list/get hosts, list accounts. Token auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:48:01 +02:00
Guillaume BOURGEOIS 0775500b15 feat(darktrace): new Darktrace NDR integration
Darktrace Threat Visualizer API, 7 commands: get/acknowledge model breaches,
get devices, get/activate Antigena actions (autonomous-response containment).
HMAC-SHA1 signed auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:48:00 +02:00
24 changed files with 1635 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
id: darktrace
name: Darktrace
version: 1.0.0
description: "Darktrace (Threat Visualizer API) — network detection and autonomous response: read model breaches, acknowledge a breach, look up devices, and read/activate Antigena network actions (containment). HMAC-SHA1 signed authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: get/acknowledge model breaches, get devices, get/activate Antigena actions."
category: ndr
# Per-instance configuration. Requests are signed (HMAC-SHA1) with the public +
# private API tokens (headers DTAPI-Token / DTAPI-Date / DTAPI-Signature).
config_schema:
properties:
base_url:
type: string
description: "Darktrace master URL (e.g. https://darktrace.example.com)"
public_token:
type: string
description: "Public API token"
private_token:
type: string
description: "Private API token"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- base_url
- public_token
- private_token
commands:
- id: get_model_breaches
name: darktrace-get-model-breaches
description: "List model breaches (optionally since a time)."
risk: read
inputs_schema:
properties:
min_score: { type: number, description: "Minimum breach score 0-1 (optional)" }
from_time: { type: string, description: "Start time YYYY-MM-DD HH:MM:SS (optional)" }
count: { type: number, description: "Max breaches (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: get_model_breach
name: darktrace-get-model-breach
description: "Get a single model breach by its PBID."
risk: read
inputs_schema:
properties:
pbid: { type: string, description: "Policy breach ID (PBID)" }
required: [pbid]
outputs_schema: { properties: {} }
- id: acknowledge_breach
name: darktrace-acknowledge-breach
description: "Acknowledge a model breach."
inputs_schema:
properties:
pbid: { type: string, description: "Policy breach ID (PBID)" }
required: [pbid]
outputs_schema: { properties: {} }
- id: get_devices
name: darktrace-get-devices
description: "Look up devices (by IP or device ID)."
risk: read
inputs_schema:
properties:
did: { type: string, description: "Device ID (optional)" }
ip: { type: string, description: "IP address (optional)" }
count: { type: number, description: "Max devices (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: get_antigena_actions
name: darktrace-get-antigena-actions
description: "List Antigena (autonomous response) actions."
risk: read
inputs_schema:
properties:
include_cleared: { type: boolean, description: "Include cleared actions (default false)" }
required: []
outputs_schema: { properties: {} }
- id: activate_antigena
name: darktrace-activate-antigena
description: "Activate an Antigena action (containment — enforce autonomous response)."
inputs_schema:
properties:
codeid: { type: string, description: "Antigena action code ID" }
duration: { type: number, description: "Duration in seconds (optional)" }
required: [codeid]
outputs_schema: { properties: {} }
- id: test_connection
name: darktrace-test-connection
description: "Verify connectivity and the signed credentials (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,81 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
pbid = inputs.get("pbid")
if pbid in (None, ""):
raise Exception("pbid is required")
result = request(
"POST",
"/modelbreaches/" + q(pbid) + "/acknowledge",
cfg,
params={"acknowledge": "true"},
)
return result if result else {"ok": True}
_run(main)
@@ -0,0 +1,78 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
codeid = inputs.get("codeid")
duration = inputs.get("duration")
if codeid in (None, ""):
raise Exception("codeid is required")
params = {"codeid": codeid, "action": "activate"}
if duration not in (None, ""):
params["duration"] = int(duration)
result = request("POST", "/antigena/action", cfg, params=params)
return result if result else {"ok": True}
_run(main)
@@ -0,0 +1,80 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def _as_bool(v):
if isinstance(v, bool):
return v
if isinstance(v, str):
return v.strip().lower() in ("1", "true", "yes", "on")
return bool(v)
def main(cfg, inputs):
include_cleared = _as_bool(inputs.get("include_cleared", False))
params = {"includecleared": "true"} if include_cleared else {}
return request("GET", "/antigena", cfg, params=params)
_run(main)
@@ -0,0 +1,78 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
did = inputs.get("did")
ip = inputs.get("ip")
count = inputs.get("count")
params = {"count": int(count or 50)}
if did not in (None, ""):
params["did"] = did
if ip not in (None, ""):
params["ip"] = ip
return request("GET", "/devices", cfg, params=params)
_run(main)
@@ -0,0 +1,72 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
pbid = inputs.get("pbid")
if pbid in (None, ""):
raise Exception("pbid is required")
return request("GET", "/modelbreaches", cfg, params={"pbid": pbid})
_run(main)
@@ -0,0 +1,78 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
count = inputs.get("count")
min_score = inputs.get("min_score")
from_time = inputs.get("from_time")
params = {"count": int(count or 50)}
if min_score not in (None, ""):
params["minscore"] = float(min_score)
if from_time not in (None, ""):
params["from"] = from_time
return request("GET", "/modelbreaches", cfg, params=params)
_run(main)
@@ -0,0 +1,69 @@
import json, os, sys, hmac, hashlib, ssl, datetime
import urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _sign(request_path, cfg, date):
public_token = str(cfg.get("public_token", ""))
private_token = str(cfg.get("private_token", "")).encode("utf-8")
signed = request_path + "\n" + public_token + "\n" + date
return hmac.new(private_token, signed.encode("utf-8"), hashlib.sha1).hexdigest()
def request(method, path, cfg, params=None, body=None):
request_path = path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
request_path += "?" + urllib.parse.urlencode(clean)
date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
sig = _sign(request_path, cfg, date)
url = str(cfg.get("base_url", "")).rstrip("/") + request_path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"DTAPI-Token": str(cfg.get("public_token", "")),
"DTAPI-Date": date,
"DTAPI-Signature": sig,
"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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
request("GET", "/status", cfg)
return {"ok": True}
_run(main)
+84
View File
@@ -0,0 +1,84 @@
id: extrahop
name: ExtraHop
version: 1.0.0
description: "ExtraHop Reveal(x) (REST API v1) — network detection and asset context: search and read detections, list and search devices, and read a device. API-key (ESA) authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: search/get detections, list/search devices, get device."
category: ndr
# Per-instance configuration. Auth header 'Authorization: ESA <api_key>'.
config_schema:
properties:
base_url:
type: string
description: "ExtraHop appliance URL (e.g. https://extrahop.example.com)"
api_key:
type: string
description: "ExtraHop REST API key"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- base_url
- api_key
commands:
- id: search_detections
name: extrahop-search-detections
description: "Search detections in a time window."
risk: read
inputs_schema:
properties:
from_time: { type: number, description: "Start time (Unix ms, negative = relative, e.g. -3600000)" }
limit: { type: number, description: "Max detections (default 50)" }
min_risk_score: { type: number, description: "Minimum risk score 0-99 (optional)" }
required: []
outputs_schema: { properties: {} }
- id: get_detection
name: extrahop-get-detection
description: "Get a single detection by ID."
risk: read
inputs_schema:
properties:
detection_id: { type: string, description: "Detection ID" }
required: [detection_id]
outputs_schema: { properties: {} }
- id: list_devices
name: extrahop-list-devices
description: "List devices."
risk: read
inputs_schema:
properties:
limit: { type: number, description: "Max devices (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: search_devices
name: extrahop-search-devices
description: "Search devices by IP, name, or MAC."
risk: read
inputs_schema:
properties:
field: { type: string, description: "Field to match: ipaddr, name, or macaddr (default ipaddr)" }
value: { type: string, description: "Value to match" }
limit: { type: number, description: "Max devices (default 50)" }
required: [value]
outputs_schema: { properties: {} }
- id: get_device
name: extrahop-get-device
description: "Get a single device by ID."
risk: read
inputs_schema:
properties:
device_id: { type: string, description: "Device ID" }
required: [device_id]
outputs_schema: { properties: {} }
- id: test_connection
name: extrahop-test-connection
description: "Verify connectivity and the API key (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,57 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
detection_id = inputs.get("detection_id")
if not detection_id:
raise Exception("detection_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/detections/" + q(detection_id), cfg)
_run(main)
@@ -0,0 +1,57 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
device_id = inputs.get("device_id")
if not device_id:
raise Exception("device_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/devices/" + q(device_id), cfg)
_run(main)
@@ -0,0 +1,54 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
limit = inputs.get("limit")
response = request("GET", "/devices", cfg, params={"limit": int(limit or 50)})
return {"devices": response}
_run(main)
@@ -0,0 +1,64 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
from_time = inputs.get("from_time")
limit = inputs.get("limit")
min_risk_score = inputs.get("min_risk_score")
body = {
"limit": int(limit or 50),
"from": int(from_time) if from_time not in (None, "") else -3600000,
}
if min_risk_score not in (None, ""):
body["filter"] = {"risk_score_min": int(min_risk_score)}
response = request("POST", "/detections/search", cfg, body=body)
return {"detections": response}
_run(main)
@@ -0,0 +1,68 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
field = inputs.get("field")
value = inputs.get("value")
limit = inputs.get("limit")
if not value:
raise Exception("value is required")
body = {
"filter": {
"field": field or "ipaddr",
"operand": value,
"operator": "=",
},
"limit": int(limit or 50),
}
response = request("POST", "/devices/search", cfg, body=body)
return {"devices": response}
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
request("GET", "/extrahop", cfg)
return {"ok": True}
_run(main)
+100
View File
@@ -0,0 +1,100 @@
id: vectra
name: Vectra AI
version: 1.0.0
description: "Vectra AI (Detect API v2.3) — network threat detection: list and read detections, mark a detection fixed, add a note, and list/read hosts and accounts. Token authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: list/get detections, mark detection fixed, add note, list/get hosts, list accounts."
category: ndr
# Per-instance configuration. Auth header 'Authorization: Token <api_token>'.
config_schema:
properties:
base_url:
type: string
description: "Vectra brain URL (e.g. https://vectra.example.com)"
api_token:
type: string
description: "Vectra API token"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- base_url
- api_token
commands:
- id: list_detections
name: vectra-list-detections
description: "List detections (optionally filtered)."
risk: read
inputs_schema:
properties:
state: { type: string, description: "Filter by state (active, inactive, fixed)" }
min_threat: { type: number, description: "Minimum threat score (optional)" }
page_size: { type: number, description: "Max detections (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: get_detection
name: vectra-get-detection
description: "Get a single detection by ID."
risk: read
inputs_schema:
properties:
detection_id: { type: string, description: "Detection ID" }
required: [detection_id]
outputs_schema: { properties: {} }
- id: mark_detection_fixed
name: vectra-mark-detection-fixed
description: "Mark one or more detections as fixed."
inputs_schema:
properties:
detection_ids: { type: string, description: "Comma-separated detection IDs" }
required: [detection_ids]
outputs_schema: { properties: {} }
- id: add_detection_note
name: vectra-add-detection-note
description: "Add a note to a detection."
inputs_schema:
properties:
detection_id: { type: string, description: "Detection ID" }
note: { type: string, description: "Note text" }
required: [detection_id, note]
outputs_schema: { properties: {} }
- id: list_hosts
name: vectra-list-hosts
description: "List hosts (optionally filtered)."
risk: read
inputs_schema:
properties:
min_threat: { type: number, description: "Minimum threat score (optional)" }
page_size: { type: number, description: "Max hosts (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: get_host
name: vectra-get-host
description: "Get a single host by ID."
risk: read
inputs_schema:
properties:
host_id: { type: string, description: "Host ID" }
required: [host_id]
outputs_schema: { properties: {} }
- id: list_accounts
name: vectra-list-accounts
description: "List accounts (optionally filtered)."
risk: read
inputs_schema:
properties:
page_size: { type: number, description: "Max accounts (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: vectra-test-connection
description: "Verify connectivity and the API token (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,60 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
detection_id = inputs.get("detection_id")
note = inputs.get("note")
if not detection_id:
raise Exception("detection_id is required")
if not note:
raise Exception("note is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("POST", "/detections/" + q(detection_id) + "/notes", cfg, body={"note": note})
_run(main)
@@ -0,0 +1,57 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
detection_id = inputs.get("detection_id")
if not detection_id:
raise Exception("detection_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/detections/" + q(detection_id), cfg)
_run(main)
+57
View File
@@ -0,0 +1,57 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
host_id = inputs.get("host_id")
if not host_id:
raise Exception("host_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/hosts/" + q(host_id), cfg)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
page_size = inputs.get("page_size")
return request("GET", "/accounts", cfg, params={"page_size": int(page_size or 50)})
_run(main)
@@ -0,0 +1,62 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
state = inputs.get("state")
min_threat = inputs.get("min_threat")
page_size = inputs.get("page_size")
params = {"page_size": int(page_size or 50)}
if state:
params["state"] = state
if min_threat not in (None, ""):
params["threat_gte"] = int(min_threat)
return request("GET", "/detections", cfg, params=params)
_run(main)
+59
View File
@@ -0,0 +1,59 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
min_threat = inputs.get("min_threat")
page_size = inputs.get("page_size")
params = {"page_size": int(page_size or 50)}
if min_threat not in (None, ""):
params["threat_gte"] = int(min_threat)
return request("GET", "/hosts", cfg, params=params)
_run(main)
@@ -0,0 +1,64 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
detection_ids = inputs.get("detection_ids")
if not detection_ids:
raise Exception("detection_ids is required")
detection_ids_list = [s.strip() for s in str(detection_ids).split(",") if s.strip()]
if not detection_ids_list:
raise Exception("detection_ids is required")
body = {
"detectionIdList": [int(x) for x in detection_ids_list],
"mark_as_fixed": "True",
}
return request("PATCH", "/detections", cfg, body=body)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def request(method, path, cfg, body=None, params=None):
url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v2.3" + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Token " + str(cfg.get("api_token", "")), "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=60, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
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)
def main(cfg, inputs):
request("GET", "/detections", cfg, params={"page_size": 1})
return {"ok": True}
_run(main)