feat(datadog): new Datadog observability integration
Datadog API v1/v2, 6 commands: search logs, list/get monitors, submit event, list events. API-key + Application-key auth, stdlib-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user