Compare commits
3 Commits
cf950cf6e4
...
046fb79008
| Author | SHA1 | Date | |
|---|---|---|---|
| 046fb79008 | |||
| 6548740890 | |||
| 16deec38f8 |
@@ -0,0 +1,88 @@
|
||||
id: datadog
|
||||
name: Datadog
|
||||
version: 1.0.0
|
||||
description: "Datadog (API v1/v2) — observability and monitoring: search logs, list and read monitors, submit and list events. API-key + Application-key authentication; stdlib-only, no extra Python dependencies."
|
||||
changelog: "1.0.0 — Initial release: search logs, list/get monitors, submit event, list events."
|
||||
category: siem
|
||||
|
||||
# Per-instance configuration. Auth uses the 'DD-API-KEY' and 'DD-APPLICATION-KEY'
|
||||
# headers. site selects the API host (e.g. datadoghq.com, datadoghq.eu, us5.datadoghq.com).
|
||||
config_schema:
|
||||
properties:
|
||||
api_key:
|
||||
type: string
|
||||
description: "Datadog API key"
|
||||
x-soar-sensitive: true
|
||||
app_key:
|
||||
type: string
|
||||
description: "Datadog Application key"
|
||||
x-soar-sensitive: true
|
||||
site:
|
||||
type: string
|
||||
description: "Datadog site (default datadoghq.com)"
|
||||
default: "datadoghq.com"
|
||||
required:
|
||||
- api_key
|
||||
- app_key
|
||||
|
||||
commands:
|
||||
- id: search_logs
|
||||
name: datadog-search-logs
|
||||
description: "Search logs."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
query: { type: string, description: "Log search query (e.g. 'service:web status:error')" }
|
||||
from_time: { type: string, description: "From time (e.g. now-1h)" }
|
||||
to_time: { type: string, description: "To time (e.g. now)" }
|
||||
limit: { type: number, description: "Max logs (default 50)" }
|
||||
required: [query]
|
||||
outputs_schema: { properties: {} }
|
||||
- id: list_monitors
|
||||
name: datadog-list-monitors
|
||||
description: "List monitors."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
tag: { type: string, description: "Optional monitor tag filter" }
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
- id: get_monitor
|
||||
name: datadog-get-monitor
|
||||
description: "Get a single monitor by ID."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
monitor_id: { type: string, description: "Monitor ID" }
|
||||
required: [monitor_id]
|
||||
outputs_schema: { properties: {} }
|
||||
- id: submit_event
|
||||
name: datadog-submit-event
|
||||
description: "Post an event to the Datadog event stream."
|
||||
inputs_schema:
|
||||
properties:
|
||||
title: { type: string, description: "Event title" }
|
||||
text: { type: string, description: "Event body" }
|
||||
tags: { type: string, description: "Comma-separated tags" }
|
||||
alert_type: { type: string, description: "info, warning, error, or success (default info)" }
|
||||
required: [title, text]
|
||||
outputs_schema: { properties: {} }
|
||||
- id: list_events
|
||||
name: datadog-list-events
|
||||
description: "List events in a time window."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
start: { type: number, description: "Start POSIX timestamp (seconds)" }
|
||||
end: { type: number, description: "End POSIX timestamp (seconds)" }
|
||||
required: [start, end]
|
||||
outputs_schema: { properties: {} }
|
||||
|
||||
- id: test_connection
|
||||
name: datadog-test-connection
|
||||
description: "Verify the API/app keys (used by the Test button)."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties: {}
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
@@ -0,0 +1,57 @@
|
||||
import json, os, sys, 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 _base(cfg):
|
||||
return "https://api." + str(cfg.get("site") or "datadoghq.com")
|
||||
|
||||
|
||||
def request(method, path, cfg, body=None, params=None):
|
||||
url = _base(cfg) + 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 = {
|
||||
"DD-API-KEY": str(cfg.get("api_key", "")),
|
||||
"DD-APPLICATION-KEY": str(cfg.get("app_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) 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):
|
||||
monitor_id = inputs.get("monitor_id")
|
||||
if not monitor_id:
|
||||
raise Exception("monitor_id is required")
|
||||
return request("GET", "/api/v1/monitor/" + q(monitor_id), cfg)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,58 @@
|
||||
import json, os, sys, 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 _base(cfg):
|
||||
return "https://api." + str(cfg.get("site") or "datadoghq.com")
|
||||
|
||||
|
||||
def request(method, path, cfg, body=None, params=None):
|
||||
url = _base(cfg) + 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 = {
|
||||
"DD-API-KEY": str(cfg.get("api_key", "")),
|
||||
"DD-APPLICATION-KEY": str(cfg.get("app_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) 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):
|
||||
start = inputs.get("start")
|
||||
if start in (None, ""):
|
||||
raise Exception("start is required")
|
||||
end = inputs.get("end")
|
||||
if end in (None, ""):
|
||||
raise Exception("end is required")
|
||||
params = {"start": int(start), "end": int(end)}
|
||||
return request("GET", "/api/v1/events", cfg, params=params)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,53 @@
|
||||
import json, os, sys, 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 _base(cfg):
|
||||
return "https://api." + str(cfg.get("site") or "datadoghq.com")
|
||||
|
||||
|
||||
def request(method, path, cfg, body=None, params=None):
|
||||
url = _base(cfg) + 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 = {
|
||||
"DD-API-KEY": str(cfg.get("api_key", "")),
|
||||
"DD-APPLICATION-KEY": str(cfg.get("app_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) 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):
|
||||
tag = inputs.get("tag")
|
||||
params = {"monitor_tags": tag}
|
||||
return request("GET", "/api/v1/monitor", cfg, params=params)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,66 @@
|
||||
import json, os, sys, 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 _base(cfg):
|
||||
return "https://api." + str(cfg.get("site") or "datadoghq.com")
|
||||
|
||||
|
||||
def request(method, path, cfg, body=None, params=None):
|
||||
url = _base(cfg) + 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 = {
|
||||
"DD-API-KEY": str(cfg.get("api_key", "")),
|
||||
"DD-APPLICATION-KEY": str(cfg.get("app_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) 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):
|
||||
query = inputs.get("query")
|
||||
if not query:
|
||||
raise Exception("query is required")
|
||||
from_time = inputs.get("from_time") or "now-1h"
|
||||
to_time = inputs.get("to_time") or "now"
|
||||
limit = inputs.get("limit")
|
||||
body = {
|
||||
"filter": {
|
||||
"query": query,
|
||||
"from": from_time,
|
||||
"to": to_time,
|
||||
},
|
||||
"page": {"limit": int(limit or 50)},
|
||||
"sort": "-timestamp",
|
||||
}
|
||||
return request("POST", "/api/v2/logs/events/search", cfg, body=body)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,68 @@
|
||||
import json, os, sys, 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 _base(cfg):
|
||||
return "https://api." + str(cfg.get("site") or "datadoghq.com")
|
||||
|
||||
|
||||
def request(method, path, cfg, body=None, params=None):
|
||||
url = _base(cfg) + 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 = {
|
||||
"DD-API-KEY": str(cfg.get("api_key", "")),
|
||||
"DD-APPLICATION-KEY": str(cfg.get("app_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) 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):
|
||||
title = inputs.get("title")
|
||||
if not title:
|
||||
raise Exception("title is required")
|
||||
text = inputs.get("text")
|
||||
if not text:
|
||||
raise Exception("text is required")
|
||||
alert_type = inputs.get("alert_type")
|
||||
body = {
|
||||
"title": title,
|
||||
"text": text,
|
||||
"alert_type": (alert_type or "info"),
|
||||
}
|
||||
tags_raw = inputs.get("tags")
|
||||
if tags_raw:
|
||||
tags_list = [s.strip() for s in str(tags_raw).split(",") if s.strip()]
|
||||
if tags_list:
|
||||
body["tags"] = tags_list
|
||||
return request("POST", "/api/v1/events", cfg, body=body)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,52 @@
|
||||
import json, os, sys, 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 _base(cfg):
|
||||
return "https://api." + str(cfg.get("site") or "datadoghq.com")
|
||||
|
||||
|
||||
def request(method, path, cfg, body=None, params=None):
|
||||
url = _base(cfg) + 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 = {
|
||||
"DD-API-KEY": str(cfg.get("api_key", "")),
|
||||
"DD-APPLICATION-KEY": str(cfg.get("app_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) 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", "/api/v1/validate", cfg)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,70 @@
|
||||
id: graylog
|
||||
name: Graylog
|
||||
version: 1.0.0
|
||||
description: "Graylog (REST API) — log search and investigation: run a relative message search, list and read streams, and fetch a single message. API-token (Basic) authentication; stdlib-only, no extra Python dependencies."
|
||||
changelog: "1.0.0 — Initial release: search messages, list/get streams, get message."
|
||||
category: siem
|
||||
|
||||
# Per-instance configuration. Auth is HTTP Basic using the API token as the
|
||||
# username and the literal 'token' as the password.
|
||||
config_schema:
|
||||
properties:
|
||||
base_url:
|
||||
type: string
|
||||
description: "Graylog URL (e.g. https://graylog.example.com)"
|
||||
token:
|
||||
type: string
|
||||
description: "Graylog API token"
|
||||
x-soar-sensitive: true
|
||||
required:
|
||||
- base_url
|
||||
- token
|
||||
|
||||
commands:
|
||||
- id: search_messages
|
||||
name: graylog-search-messages
|
||||
description: "Run a relative message search (last N seconds)."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
query: { type: string, description: "Search query (e.g. 'source:web01 AND level:3')" }
|
||||
range: { type: number, description: "Relative range in seconds (default 3600)" }
|
||||
limit: { type: number, description: "Max messages (default 50)" }
|
||||
required: [query]
|
||||
outputs_schema: { properties: {} }
|
||||
- id: list_streams
|
||||
name: graylog-list-streams
|
||||
description: "List streams."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties: {}
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
- id: get_stream
|
||||
name: graylog-get-stream
|
||||
description: "Get a single stream by ID."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
stream_id: { type: string, description: "Stream ID" }
|
||||
required: [stream_id]
|
||||
outputs_schema: { properties: {} }
|
||||
- id: get_message
|
||||
name: graylog-get-message
|
||||
description: "Get a single message by index and ID."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
index: { type: string, description: "Elasticsearch index name" }
|
||||
message_id: { type: string, description: "Message ID" }
|
||||
required: [index, message_id]
|
||||
outputs_schema: { properties: {} }
|
||||
|
||||
- id: test_connection
|
||||
name: graylog-test-connection
|
||||
description: "Verify connectivity and the token (used by the Test button)."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties: {}
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
@@ -0,0 +1,56 @@
|
||||
import json, os, sys, base64, 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 _auth(cfg):
|
||||
raw = str(cfg.get("token", "")) + ":token"
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def request(method, path, cfg, params=None):
|
||||
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||
if params:
|
||||
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||
if clean:
|
||||
url += "?" + urllib.parse.urlencode(clean)
|
||||
headers = {"Authorization": _auth(cfg), "Accept": "application/json", "X-Requested-By": "riposte"}
|
||||
req = urllib.request.Request(url, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=60) 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):
|
||||
index = inputs.get("index")
|
||||
if not index:
|
||||
raise Exception("index is required")
|
||||
|
||||
message_id = inputs.get("message_id")
|
||||
if not message_id:
|
||||
raise Exception("message_id is required")
|
||||
|
||||
return request("GET", "/messages/" + q(index) + "/" + q(message_id), cfg)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,52 @@
|
||||
import json, os, sys, base64, 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 _auth(cfg):
|
||||
raw = str(cfg.get("token", "")) + ":token"
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def request(method, path, cfg, params=None):
|
||||
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||
if params:
|
||||
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||
if clean:
|
||||
url += "?" + urllib.parse.urlencode(clean)
|
||||
headers = {"Authorization": _auth(cfg), "Accept": "application/json", "X-Requested-By": "riposte"}
|
||||
req = urllib.request.Request(url, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=60) 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):
|
||||
stream_id = inputs.get("stream_id")
|
||||
if not stream_id:
|
||||
raise Exception("stream_id is required")
|
||||
|
||||
return request("GET", "/streams/" + q(stream_id), cfg)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,45 @@
|
||||
import json, os, sys, base64, 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 _auth(cfg):
|
||||
raw = str(cfg.get("token", "")) + ":token"
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def request(method, path, cfg, params=None):
|
||||
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||
if params:
|
||||
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||
if clean:
|
||||
url += "?" + urllib.parse.urlencode(clean)
|
||||
headers = {"Authorization": _auth(cfg), "Accept": "application/json", "X-Requested-By": "riposte"}
|
||||
req = urllib.request.Request(url, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=60) 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):
|
||||
return request("GET", "/streams", cfg)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,60 @@
|
||||
import json, os, sys, base64, 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 _auth(cfg):
|
||||
raw = str(cfg.get("token", "")) + ":token"
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def request(method, path, cfg, params=None):
|
||||
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||
if params:
|
||||
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||
if clean:
|
||||
url += "?" + urllib.parse.urlencode(clean)
|
||||
headers = {"Authorization": _auth(cfg), "Accept": "application/json", "X-Requested-By": "riposte"}
|
||||
req = urllib.request.Request(url, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=60) 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):
|
||||
query = inputs.get("query")
|
||||
if not query:
|
||||
raise Exception("query is required")
|
||||
|
||||
range_secs = inputs.get("range")
|
||||
range_secs = int(range_secs) if range_secs not in (None, "") else 3600
|
||||
|
||||
limit = inputs.get("limit")
|
||||
limit = int(limit) if limit not in (None, "") else 50
|
||||
|
||||
return request(
|
||||
"GET",
|
||||
"/search/universal/relative",
|
||||
cfg,
|
||||
params={"query": query, "range": range_secs, "limit": limit},
|
||||
)
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,46 @@
|
||||
import json, os, sys, base64, 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 _auth(cfg):
|
||||
raw = str(cfg.get("token", "")) + ":token"
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def request(method, path, cfg, params=None):
|
||||
url = str(cfg.get("base_url", "")).rstrip("/") + "/api" + path
|
||||
if params:
|
||||
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||
if clean:
|
||||
url += "?" + urllib.parse.urlencode(clean)
|
||||
headers = {"Authorization": _auth(cfg), "Accept": "application/json", "X-Requested-By": "riposte"}
|
||||
req = urllib.request.Request(url, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=60) 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", "/system", cfg)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,65 @@
|
||||
id: sumologic
|
||||
name: Sumo Logic
|
||||
version: 1.0.0
|
||||
description: "Sumo Logic (REST API) — log search and collector inventory: run a search job (create, poll, and return messages) and list/read collectors. Access-ID/key (Basic) authentication; stdlib-only, no extra Python dependencies."
|
||||
changelog: "1.0.0 — Initial release: search (job create+poll+messages), list/get collectors."
|
||||
category: siem
|
||||
|
||||
# Per-instance configuration. HTTP Basic auth with the access ID + access key.
|
||||
config_schema:
|
||||
properties:
|
||||
base_url:
|
||||
type: string
|
||||
description: "Sumo Logic API endpoint (region-specific, e.g. https://api.us2.sumologic.com)"
|
||||
access_id:
|
||||
type: string
|
||||
description: "Access ID"
|
||||
access_key:
|
||||
type: string
|
||||
description: "Access key"
|
||||
x-soar-sensitive: true
|
||||
required:
|
||||
- base_url
|
||||
- access_id
|
||||
- access_key
|
||||
|
||||
commands:
|
||||
- id: search
|
||||
name: sumologic-search
|
||||
description: "Run a search: create a search job, poll until complete, and return the messages."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
query: { type: string, description: "Sumo Logic search query" }
|
||||
from_time: { type: string, description: "ISO-8601 start time (e.g. 2024-01-01T00:00:00)" }
|
||||
to_time: { type: string, description: "ISO-8601 end time" }
|
||||
limit: { type: number, description: "Max messages (default 100)" }
|
||||
required: [query, from_time, to_time]
|
||||
outputs_schema: { properties: {} }
|
||||
- id: list_collectors
|
||||
name: sumologic-list-collectors
|
||||
description: "List collectors."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
limit: { type: number, description: "Max collectors (default 100)" }
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
- id: get_collector
|
||||
name: sumologic-get-collector
|
||||
description: "Get a single collector by ID."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
collector_id: { type: string, description: "Collector ID" }
|
||||
required: [collector_id]
|
||||
outputs_schema: { properties: {} }
|
||||
|
||||
- id: test_connection
|
||||
name: sumologic-test-connection
|
||||
description: "Verify connectivity and credentials (used by the Test button)."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties: {}
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
@@ -0,0 +1,65 @@
|
||||
import json, os, sys, time, base64, http.cookiejar
|
||||
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 _auth(cfg):
|
||||
raw = str(cfg.get("access_id", "")) + ":" + str(cfg.get("access_key", ""))
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def _base(cfg):
|
||||
return str(cfg.get("base_url", "")).rstrip("/") + "/api/v1"
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()))
|
||||
|
||||
def call(self, method, path, body=None, params=None):
|
||||
url = _base(self.cfg) + 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": _auth(self.cfg), "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 self.opener.open(req, timeout=60) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def _run(fn):
|
||||
try:
|
||||
client = Client(_cfg())
|
||||
print(json.dumps(fn(client, _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(client, inputs):
|
||||
collector_id = inputs.get("collector_id")
|
||||
if not collector_id:
|
||||
raise Exception("collector_id is required")
|
||||
return client.call("GET", "/collectors/" + q(collector_id))
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,64 @@
|
||||
import json, os, sys, time, base64, http.cookiejar
|
||||
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 _auth(cfg):
|
||||
raw = str(cfg.get("access_id", "")) + ":" + str(cfg.get("access_key", ""))
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def _base(cfg):
|
||||
return str(cfg.get("base_url", "")).rstrip("/") + "/api/v1"
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()))
|
||||
|
||||
def call(self, method, path, body=None, params=None):
|
||||
url = _base(self.cfg) + 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": _auth(self.cfg), "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 self.opener.open(req, timeout=60) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def _run(fn):
|
||||
try:
|
||||
client = Client(_cfg())
|
||||
print(json.dumps(fn(client, _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(client, inputs):
|
||||
limit = inputs.get("limit")
|
||||
limit = int(limit) if limit not in (None, "") else 100
|
||||
return client.call("GET", "/collectors", params={"limit": limit})
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,96 @@
|
||||
import json, os, sys, time, base64, http.cookiejar
|
||||
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 _auth(cfg):
|
||||
raw = str(cfg.get("access_id", "")) + ":" + str(cfg.get("access_key", ""))
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def _base(cfg):
|
||||
return str(cfg.get("base_url", "")).rstrip("/") + "/api/v1"
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()))
|
||||
|
||||
def call(self, method, path, body=None, params=None):
|
||||
url = _base(self.cfg) + 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": _auth(self.cfg), "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 self.opener.open(req, timeout=60) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def _run(fn):
|
||||
try:
|
||||
client = Client(_cfg())
|
||||
print(json.dumps(fn(client, _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(client, inputs):
|
||||
query = inputs.get("query")
|
||||
if not query:
|
||||
raise Exception("query is required")
|
||||
from_time = inputs.get("from_time")
|
||||
if not from_time:
|
||||
raise Exception("from_time is required")
|
||||
to_time = inputs.get("to_time")
|
||||
if not to_time:
|
||||
raise Exception("to_time is required")
|
||||
limit = inputs.get("limit")
|
||||
limit = int(limit) if limit not in (None, "") else 100
|
||||
|
||||
job = client.call("POST", "/search/jobs", body={"query": query, "from": from_time, "to": to_time, "timeZone": "UTC"})
|
||||
job_id = job.get("id")
|
||||
if not job_id:
|
||||
raise Exception("failed to create search job: " + json.dumps(job))
|
||||
|
||||
state = None
|
||||
for _ in range(60):
|
||||
status = client.call("GET", "/search/jobs/" + q(job_id))
|
||||
state = status.get("state")
|
||||
if state == "DONE GATHERING RESULTS":
|
||||
break
|
||||
if state == "CANCELLED":
|
||||
raise Exception("search job cancelled")
|
||||
time.sleep(2)
|
||||
|
||||
messages = client.call("GET", "/search/jobs/" + q(job_id) + "/messages", params={"offset": 0, "limit": limit})
|
||||
|
||||
try:
|
||||
client.call("DELETE", "/search/jobs/" + q(job_id))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {"job_id": job_id, "state": state, "messages": messages}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,60 @@
|
||||
import json, os, sys, time, base64, http.cookiejar
|
||||
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 _auth(cfg):
|
||||
raw = str(cfg.get("access_id", "")) + ":" + str(cfg.get("access_key", ""))
|
||||
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
def _base(cfg):
|
||||
return str(cfg.get("base_url", "")).rstrip("/") + "/api/v1"
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()))
|
||||
|
||||
def call(self, method, path, body=None, params=None):
|
||||
url = _base(self.cfg) + 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": _auth(self.cfg), "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 self.opener.open(req, timeout=60) as r:
|
||||
raw = r.read()
|
||||
return json.loads(raw) if raw else {}
|
||||
|
||||
|
||||
def _run(fn):
|
||||
try:
|
||||
client = Client(_cfg())
|
||||
print(json.dumps(fn(client, _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(client, inputs):
|
||||
client.call("GET", "/collectors", params={"limit": 1})
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
_run(main)
|
||||
Reference in New Issue
Block a user