Compare commits

...

4 Commits

Author SHA1 Message Date
Guillaume BOURGEOIS e88805ccab feat(opsgenie): new Opsgenie alerting integration
Alert API v2, 13 commands: alert create/close/acknowledge/get/list, add note/tags,
assign, snooze, delete, list schedules, on-calls. GenieKey auth (US/EU), stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:28:26 +02:00
Guillaume BOURGEOIS a279b58290 feat(pagerduty): new PagerDuty alerting integration
Events API v2 + REST API v2, 10 commands: trigger/acknowledge/resolve incident,
list/get incident, add note, list on-calls/users/services. Token + routing-key
auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:28:26 +02:00
Guillaume BOURGEOIS df4cd98a9e feat(microsoft-teams): new Microsoft Teams notification integration
Incoming-webhook / Power Automate Workflows, 3 commands: send message,
send Adaptive Card (title/text/facts/action button). Webhook-URL auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:28:25 +02:00
Guillaume BOURGEOIS e3c15ae972 feat(slack): new Slack notification/ChatOps integration
Slack Web API, 8 commands: send message (text/Block Kit), list/create channel,
invite to channel, set topic, get user, add reaction. Bot-token auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 23:28:25 +02:00
38 changed files with 2523 additions and 0 deletions
@@ -0,0 +1,49 @@
id: microsoft_teams
name: Microsoft Teams
version: 1.0.0
description: "Microsoft Teams (incoming webhook / Power Automate Workflows) — SOC notification: post plain messages and rich Adaptive Cards (title, text, facts, optional action button) to a Teams channel. Webhook-URL authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: send message, send Adaptive Card."
category: notification
# Per-instance configuration. The webhook URL is created in Teams
# (Workflows / 'Post to a channel when a webhook request is received', or a
# classic Incoming Webhook connector). All messages POST to this URL.
config_schema:
properties:
webhook_url:
type: string
description: "Teams incoming webhook / Workflows URL"
x-soar-sensitive: true
required:
- webhook_url
commands:
- id: send_message
name: teams-send-message
description: "Post a plain-text message to the Teams channel."
inputs_schema:
properties:
text: { type: string, description: "Message text (Markdown supported)" }
required: [text]
outputs_schema: { properties: {} }
- id: send_card
name: teams-send-card
description: "Post an Adaptive Card built from a title, body text, optional facts, and an optional action button."
inputs_schema:
properties:
title: { type: string, description: "Card title" }
text: { type: string, description: "Card body text" }
facts: { type: string, description: "Optional key=value pairs, comma-separated (e.g. 'Severity=High,Host=web01')" }
action_title: { type: string, description: "Optional button label" }
action_url: { type: string, description: "Optional button URL (required if action_title is set)" }
required: [title]
outputs_schema: { properties: {} }
- id: test_connection
name: teams-test-connection
description: "Post a small connection-test message to verify the webhook (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,89 @@
import json, os, sys, 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 post(cfg, payload):
url = str(cfg.get("webhook_url", ""))
if not url:
raise Exception("webhook_url is not configured")
data = json.dumps(payload).encode("utf-8")
headers = {"Content-Type": "application/json"}
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
r.read()
return r.status
def adaptive_card(body_blocks, actions=None):
card = {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4",
"body": body_blocks,
}
if actions:
card["actions"] = actions
return {
"type": "message",
"attachments": [
{"contentType": "application/vnd.microsoft.card.adaptive", "content": card}
],
}
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 = str(inputs.get("title", "")).strip()
if not title:
raise Exception("title is required")
text = str(inputs.get("text", "")).strip()
facts_raw = str(inputs.get("facts", "")).strip()
action_title = str(inputs.get("action_title", "")).strip()
action_url = str(inputs.get("action_url", "")).strip()
if action_title and not action_url:
raise Exception("action_url is required when action_title is set")
blocks = [{"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Large", "wrap": True}]
if text:
blocks.append({"type": "TextBlock", "text": text, "wrap": True})
if facts_raw:
facts = []
for pair in facts_raw.split(","):
if "=" not in pair:
continue
k, v = pair.split("=", 1)
facts.append({"title": k.strip(), "value": v.strip()})
if facts:
blocks.append({"type": "FactSet", "facts": facts})
actions = None
if action_title and action_url:
actions = [{"type": "Action.OpenUrl", "title": action_title, "url": action_url}]
payload = adaptive_card(blocks, actions)
status = post(cfg, payload)
return {"ok": True, "status": status}
_run(main)
@@ -0,0 +1,62 @@
import json, os, sys, 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 post(cfg, payload):
url = str(cfg.get("webhook_url", ""))
if not url:
raise Exception("webhook_url is not configured")
data = json.dumps(payload).encode("utf-8")
headers = {"Content-Type": "application/json"}
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
r.read()
return r.status
def adaptive_card(body_blocks, actions=None):
card = {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4",
"body": body_blocks,
}
if actions:
card["actions"] = actions
return {
"type": "message",
"attachments": [
{"contentType": "application/vnd.microsoft.card.adaptive", "content": card}
],
}
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):
text = str(inputs.get("text", "")).strip()
if not text:
raise Exception("text is required")
payload = adaptive_card([{"type": "TextBlock", "text": text, "wrap": True}])
status = post(cfg, payload)
return {"ok": True, "status": status}
_run(main)
@@ -0,0 +1,58 @@
import json, os, sys, 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 post(cfg, payload):
url = str(cfg.get("webhook_url", ""))
if not url:
raise Exception("webhook_url is not configured")
data = json.dumps(payload).encode("utf-8")
headers = {"Content-Type": "application/json"}
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
r.read()
return r.status
def adaptive_card(body_blocks, actions=None):
card = {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4",
"body": body_blocks,
}
if actions:
card["actions"] = actions
return {
"type": "message",
"attachments": [
{"contentType": "application/vnd.microsoft.card.adaptive", "content": card}
],
}
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):
payload = adaptive_card([{"type": "TextBlock", "text": "Riposte SOAR connection test", "wrap": True}])
status = post(cfg, payload)
return {"ok": True, "status": status}
_run(main)
+152
View File
@@ -0,0 +1,152 @@
id: opsgenie
name: Opsgenie
version: 1.0.0
description: "Atlassian Opsgenie (Alert API v2) — SOC alerting and on-call: create, close, acknowledge, get, and list alerts; add notes and tags; assign, snooze, and delete alerts; and read schedules and on-calls. GenieKey authentication (US/EU regions); stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: alert create/close/acknowledge/get/list, add note/tags, assign, snooze, delete, list schedules, on-calls."
category: notification
# Per-instance configuration. The API key is sent as 'Authorization: GenieKey <api_key>'.
# region selects the base URL: US -> api.opsgenie.com, EU -> api.eu.opsgenie.com.
config_schema:
properties:
api_key:
type: string
description: "Opsgenie API key"
x-soar-sensitive: true
region:
type: string
description: "Opsgenie region: US or EU (default US)"
default: "US"
required:
- api_key
commands:
- id: create_alert
name: opsgenie-create-alert
description: "Create a new alert."
inputs_schema:
properties:
message: { type: string, description: "Alert message (title)" }
description: { type: string, description: "Alert description" }
priority: { type: string, description: "P1..P5 (default P3)" }
alias: { type: string, description: "Client-defined alias for de-duplication" }
tags: { type: string, description: "Comma-separated tags" }
responders: { type: string, description: "Comma-separated team names to notify" }
required: [message]
outputs_schema: { properties: {} }
- id: close_alert
name: opsgenie-close-alert
description: "Close an alert."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
note: { type: string, description: "Optional close note" }
required: [identifier]
outputs_schema: { properties: {} }
- id: acknowledge_alert
name: opsgenie-acknowledge-alert
description: "Acknowledge an alert."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
note: { type: string, description: "Optional note" }
required: [identifier]
outputs_schema: { properties: {} }
- id: get_alert
name: opsgenie-get-alert
description: "Get a single alert."
risk: read
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
required: [identifier]
outputs_schema: { properties: {} }
- id: list_alerts
name: opsgenie-list-alerts
description: "List/search alerts."
risk: read
inputs_schema:
properties:
query: { type: string, description: "Opsgenie search query (e.g. 'status: open')" }
limit: { type: number, description: "Max alerts (default 20, max 100)" }
required: []
outputs_schema: { properties: {} }
- id: add_note
name: opsgenie-add-note
description: "Add a note to an alert."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
note: { type: string, description: "Note content" }
required: [identifier, note]
outputs_schema: { properties: {} }
- id: add_tags
name: opsgenie-add-tags
description: "Add tags to an alert."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
tags: { type: string, description: "Comma-separated tags to add" }
required: [identifier, tags]
outputs_schema: { properties: {} }
- id: assign_alert
name: opsgenie-assign-alert
description: "Assign an alert to a user."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
owner: { type: string, description: "Username (email) of the assignee" }
required: [identifier, owner]
outputs_schema: { properties: {} }
- id: snooze_alert
name: opsgenie-snooze-alert
description: "Snooze an alert until a given time."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
end_time: { type: string, description: "ISO-8601 time to snooze until" }
required: [identifier, end_time]
outputs_schema: { properties: {} }
- id: delete_alert
name: opsgenie-delete-alert
description: "Delete an alert."
inputs_schema:
properties:
identifier: { type: string, description: "Alert id, tiny id, or alias" }
identifier_type: { type: string, description: "id | tiny | alias (default id)" }
required: [identifier]
outputs_schema: { properties: {} }
- id: list_schedules
name: opsgenie-list-schedules
description: "List on-call schedules."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
- id: get_on_calls
name: opsgenie-get-on-calls
description: "Get the current on-call participants for a schedule."
risk: read
inputs_schema:
properties:
schedule_identifier: { type: string, description: "Schedule id or name" }
identifier_type: { type: string, description: "id | name (default id)" }
required: [schedule_identifier]
outputs_schema: { properties: {} }
- id: test_connection
name: opsgenie-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,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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
note = str(inputs.get("note") or "").strip()
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="") + "/acknowledge"
params = {"identifierType": identifier_type}
body = {"note": note} if note else {}
return request("POST", path, cfg, body=body, params=params)
_run(main)
+60
View File
@@ -0,0 +1,60 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
note = str(inputs.get("note") or "").strip()
if not note:
raise Exception("note is required")
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="") + "/notes"
params = {"identifierType": identifier_type}
body = {"note": note}
return request("POST", path, cfg, body=body, params=params)
_run(main)
+60
View File
@@ -0,0 +1,60 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
tags = [s.strip() for s in str(inputs.get("tags") or "").split(",") if s.strip()]
if not tags:
raise Exception("tags is required")
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="") + "/tags"
params = {"identifierType": identifier_type}
body = {"tags": tags}
return request("POST", path, cfg, body=body, params=params)
_run(main)
@@ -0,0 +1,60 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
owner = str(inputs.get("owner") or "").strip()
if not owner:
raise Exception("owner is required")
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="") + "/assign"
params = {"identifierType": identifier_type}
body = {"owner": {"username": owner}}
return request("POST", path, cfg, body=body, params=params)
_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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
note = str(inputs.get("note") or "").strip()
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="") + "/close"
params = {"identifierType": identifier_type}
body = {"note": note} if note else {}
return request("POST", path, cfg, body=body, params=params)
_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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
message = str(inputs.get("message") or "").strip()
if not message:
raise Exception("message is required")
description = str(inputs.get("description") or "").strip()
priority = str(inputs.get("priority") or "P3").strip() or "P3"
alias = str(inputs.get("alias") or "").strip()
tags = [s.strip() for s in str(inputs.get("tags") or "").split(",") if s.strip()]
responders = [s.strip() for s in str(inputs.get("responders") or "").split(",") if s.strip()]
body = {"message": message, "priority": priority}
if description:
body["description"] = description
if alias:
body["alias"] = alias
if tags:
body["tags"] = tags
if responders:
body["responders"] = [{"type": "team", "name": t} for t in responders]
return request("POST", "/v2/alerts", cfg, body=body)
_run(main)
@@ -0,0 +1,56 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="")
params = {"identifierType": identifier_type}
return request("DELETE", path, cfg, params=params)
_run(main)
@@ -0,0 +1,56 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="")
params = {"identifierType": identifier_type}
return request("GET", path, cfg, params=params)
_run(main)
@@ -0,0 +1,56 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
schedule_identifier = str(inputs.get("schedule_identifier") or "").strip()
if not schedule_identifier:
raise Exception("schedule_identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
path = "/v2/schedules/" + urllib.parse.quote(schedule_identifier, safe="") + "/on-calls"
params = {"scheduleIdentifierType": identifier_type}
return request("GET", path, cfg, params=params)
_run(main)
@@ -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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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 = str(inputs.get("query") or "").strip()
limit = inputs.get("limit")
try:
limit = int(limit) if limit not in (None, "") else 20
except Exception:
limit = 20
params = {"query": query, "limit": limit}
return request("GET", "/v2/alerts", cfg, params=params)
_run(main)
@@ -0,0 +1,48 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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", "/v2/schedules", cfg)
_run(main)
@@ -0,0 +1,60 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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):
identifier = str(inputs.get("identifier") or "").strip()
if not identifier:
raise Exception("identifier is required")
identifier_type = str(inputs.get("identifier_type") or "id").strip() or "id"
end_time = str(inputs.get("end_time") or "").strip()
if not end_time:
raise Exception("end_time is required")
path = "/v2/alerts/" + urllib.parse.quote(identifier, safe="") + "/snooze"
params = {"identifierType": identifier_type}
body = {"endTime": end_time}
return request("POST", path, cfg, body=body, params=params)
_run(main)
@@ -0,0 +1,49 @@
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):
region = str(cfg.get("region") or "US").strip().upper()
return "https://api.eu.opsgenie.com" if region == "EU" else "https://api.opsgenie.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 = {"Authorization": "GenieKey " + 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) 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", "/v2/alerts", cfg, params={"limit": 1})
return {"ok": True}
_run(main)
+126
View File
@@ -0,0 +1,126 @@
id: pagerduty
name: PagerDuty
version: 1.0.0
description: "PagerDuty (Events API v2 + REST API v2) — SOC alerting and on-call: trigger/acknowledge/resolve incidents via the routing key, list and read incidents, add notes, and read on-calls, users, and services. Token + routing-key authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: trigger/acknowledge/resolve incident, list/get incident, add note, list on-calls/users/services."
category: notification
# Per-instance configuration. api_token authenticates the REST API
# ('Authorization: Token token=<api_token>'); routing_key is the Events API v2
# integration key used to trigger/acknowledge/resolve. from_email is the
# PagerDuty user email required by the REST API for writes such as add-note.
config_schema:
properties:
api_token:
type: string
description: "PagerDuty REST API token"
x-soar-sensitive: true
routing_key:
type: string
description: "Events API v2 integration/routing key (for trigger/ack/resolve)"
x-soar-sensitive: true
from_email:
type: string
description: "A valid PagerDuty user email (required for add-note and other REST writes)"
required:
- api_token
commands:
- id: trigger_incident
name: pagerduty-trigger-incident
description: "Trigger an incident through the Events API v2. Returns a dedup_key used to acknowledge/resolve it."
inputs_schema:
properties:
summary: { type: string, description: "Short incident summary" }
source: { type: string, description: "Affected source (host, service, IP)" }
severity: { type: string, description: "critical | error | warning | info (default critical)" }
dedup_key: { type: string, description: "Optional dedup key (auto-generated if omitted)" }
component: { type: string, description: "Optional component" }
required: [summary, source]
outputs_schema: { properties: {} }
- id: acknowledge_incident
name: pagerduty-acknowledge-incident
description: "Acknowledge an incident by its dedup_key (Events API v2)."
inputs_schema:
properties:
dedup_key: { type: string, description: "The incident dedup_key" }
required: [dedup_key]
outputs_schema: { properties: {} }
- id: resolve_incident
name: pagerduty-resolve-incident
description: "Resolve an incident by its dedup_key (Events API v2)."
inputs_schema:
properties:
dedup_key: { type: string, description: "The incident dedup_key" }
required: [dedup_key]
outputs_schema: { properties: {} }
- id: list_incidents
name: pagerduty-list-incidents
description: "List incidents (filter by status, urgency, and time window)."
risk: read
inputs_schema:
properties:
statuses: { type: string, description: "Comma-separated: triggered,acknowledged,resolved" }
urgencies: { type: string, description: "Comma-separated: high,low" }
since: { type: string, description: "ISO-8601 start time" }
until: { type: string, description: "ISO-8601 end time" }
limit: { type: number, description: "Max incidents (default 25)" }
required: []
outputs_schema: { properties: {} }
- id: get_incident
name: pagerduty-get-incident
description: "Get a single incident by ID."
risk: read
inputs_schema:
properties:
incident_id: { type: string, description: "Incident ID" }
required: [incident_id]
outputs_schema: { properties: {} }
- id: add_note
name: pagerduty-add-note
description: "Add a note to an incident (requires from_email in the configuration)."
inputs_schema:
properties:
incident_id: { type: string, description: "Incident ID" }
note: { type: string, description: "Note content" }
required: [incident_id, note]
outputs_schema: { properties: {} }
- id: list_oncalls
name: pagerduty-list-oncalls
description: "List current on-call assignments."
risk: read
inputs_schema:
properties:
schedule_ids: { type: string, description: "Optional comma-separated schedule IDs to filter" }
limit: { type: number, description: "Max entries (default 25)" }
required: []
outputs_schema: { properties: {} }
- id: list_users
name: pagerduty-list-users
description: "List users (optionally filter by a search query)."
risk: read
inputs_schema:
properties:
query: { type: string, description: "Optional name/email search filter" }
limit: { type: number, description: "Max users (default 25)" }
required: []
outputs_schema: { properties: {} }
- id: list_services
name: pagerduty-list-services
description: "List services (optionally filter by a search query)."
risk: read
inputs_schema:
properties:
query: { type: string, description: "Optional name search filter" }
limit: { type: number, description: "Max services (default 25)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: pagerduty-test-connection
description: "Verify connectivity and the REST API token (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,70 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
if not cfg.get("routing_key"):
raise Exception("routing_key is not configured")
dedup_key = str(inputs.get("dedup_key", "") or "").strip()
if not dedup_key:
raise Exception("dedup_key is required")
return events_enqueue(cfg, {
"routing_key": cfg["routing_key"],
"event_action": "acknowledge",
"dedup_key": dedup_key,
})
_run(main)
@@ -0,0 +1,77 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
incident_id = str(inputs.get("incident_id", "") or "").strip()
if not incident_id:
raise Exception("incident_id is required")
note = str(inputs.get("note", "") or "").strip()
if not note:
raise Exception("note is required")
from_email = str(cfg.get("from_email", "") or "").strip()
if not from_email:
raise Exception("from_email must be configured to add notes")
return rest(
"POST",
"/incidents/" + urllib.parse.quote(incident_id, safe="") + "/notes",
cfg,
body={"note": {"content": note}},
extra_headers={"From": from_email},
)
_run(main)
@@ -0,0 +1,63 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
incident_id = str(inputs.get("incident_id", "") or "").strip()
if not incident_id:
raise Exception("incident_id is required")
return rest("GET", "/incidents/" + urllib.parse.quote(incident_id, safe=""), cfg)
_run(main)
@@ -0,0 +1,75 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
statuses = [s.strip() for s in str(inputs.get("statuses", "") or "").split(",") if s.strip()]
urgencies = [s.strip() for s in str(inputs.get("urgencies", "") or "").split(",") if s.strip()]
since = str(inputs.get("since", "") or "").strip()
until = str(inputs.get("until", "") or "").strip()
try:
limit = int(inputs.get("limit", 25) or 25)
except (TypeError, ValueError):
limit = 25
return rest("GET", "/incidents", cfg, params={
"statuses[]": statuses or None,
"urgencies[]": urgencies or None,
"since": since,
"until": until,
"limit": limit,
})
_run(main)
@@ -0,0 +1,69 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
schedule_ids = [s.strip() for s in str(inputs.get("schedule_ids", "") or "").split(",") if s.strip()]
try:
limit = int(inputs.get("limit", 25) or 25)
except (TypeError, ValueError):
limit = 25
return rest("GET", "/oncalls", cfg, params={
"schedule_ids[]": schedule_ids or None,
"limit": limit,
})
_run(main)
@@ -0,0 +1,69 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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 = str(inputs.get("query", "") or "").strip()
try:
limit = int(inputs.get("limit", 25) or 25)
except (TypeError, ValueError):
limit = 25
return rest("GET", "/services", cfg, params={
"query": query,
"limit": limit,
})
_run(main)
@@ -0,0 +1,69 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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 = str(inputs.get("query", "") or "").strip()
try:
limit = int(inputs.get("limit", 25) or 25)
except (TypeError, ValueError):
limit = 25
return rest("GET", "/users", cfg, params={
"query": query,
"limit": limit,
})
_run(main)
@@ -0,0 +1,70 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
if not cfg.get("routing_key"):
raise Exception("routing_key is not configured")
dedup_key = str(inputs.get("dedup_key", "") or "").strip()
if not dedup_key:
raise Exception("dedup_key is required")
return events_enqueue(cfg, {
"routing_key": cfg["routing_key"],
"event_action": "resolve",
"dedup_key": dedup_key,
})
_run(main)
@@ -0,0 +1,60 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
rest("GET", "/users", cfg, params={"limit": 1})
return {"ok": True}
_run(main)
@@ -0,0 +1,93 @@
import json, os, sys, uuid, urllib.parse, urllib.request, urllib.error
REST = "https://api.pagerduty.com"
EVENTS = "https://events.pagerduty.com/v2/enqueue"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def rest(method, path, cfg, body=None, params=None, extra_headers=None):
url = REST + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {
"Authorization": "Token token=" + str(cfg.get("api_token", "")),
"Accept": "application/vnd.pagerduty+json;version=2",
}
if data is not None:
headers["Content-Type"] = "application/json"
if extra_headers:
headers.update(extra_headers)
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 events_enqueue(cfg, payload):
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(EVENTS, data=data, headers={"Content-Type": "application/json"}, method="POST")
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):
if not cfg.get("routing_key"):
raise Exception("routing_key is not configured")
summary = str(inputs.get("summary", "")).strip()
if not summary:
raise Exception("summary is required")
source = str(inputs.get("source", "")).strip()
if not source:
raise Exception("source is required")
severity = str(inputs.get("severity", "") or "critical").strip()
if severity not in ("critical", "error", "warning", "info"):
severity = "critical"
dedup_key = str(inputs.get("dedup_key", "") or "").strip()
component = str(inputs.get("component", "") or "").strip()
payload = {
"summary": summary,
"source": source,
"severity": severity,
}
if component:
payload["component"] = component
event = {
"routing_key": cfg["routing_key"],
"event_action": "trigger",
"payload": payload,
}
if dedup_key:
event["dedup_key"] = dedup_key
return events_enqueue(cfg, event)
_run(main)
+97
View File
@@ -0,0 +1,97 @@
id: slack
name: Slack
version: 1.0.0
description: "Slack (Web API) — SOC notification and ChatOps: post messages (text or Block Kit), list/create channels, invite users, set channel topics, look up users, and add reactions. Bot-token authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: send message, list/create channel, invite to channel, set topic, get user, add reaction."
category: notification
# Per-instance configuration. The bot token (xoxb-...) is sent as
# 'Authorization: Bearer <bot_token>'. Needs scopes such as chat:write,
# channels:read, channels:manage, users:read, users:read.email, reactions:write.
config_schema:
properties:
bot_token:
type: string
description: "Slack bot token (xoxb-...)"
x-soar-sensitive: true
required:
- bot_token
commands:
- id: send_message
name: slack-send-message
description: "Post a message to a channel or user (text and/or Block Kit blocks)."
inputs_schema:
properties:
channel: { type: string, description: "Channel ID, channel name (#alerts), or user ID for a DM" }
text: { type: string, description: "Message text (fallback text when blocks are used)" }
blocks: { type: string, description: "Optional Block Kit blocks as a JSON array string" }
thread_ts: { type: string, description: "Optional parent message ts to reply in a thread" }
required: [channel]
outputs_schema: { properties: {} }
- id: list_channels
name: slack-list-channels
description: "List channels (public and private the bot can see)."
risk: read
inputs_schema:
properties:
types: { type: string, description: "Comma-separated channel types (default 'public_channel,private_channel')" }
limit: { type: number, description: "Max channels (default 200)" }
required: []
outputs_schema: { properties: {} }
- id: create_channel
name: slack-create-channel
description: "Create a new channel."
inputs_schema:
properties:
name: { type: string, description: "Channel name (lowercase, no spaces)" }
is_private: { type: boolean, description: "Create a private channel (default false)" }
required: [name]
outputs_schema: { properties: {} }
- id: invite_to_channel
name: slack-invite-to-channel
description: "Invite one or more users to a channel."
inputs_schema:
properties:
channel: { type: string, description: "Channel ID" }
users: { type: string, description: "Comma-separated user IDs to invite" }
required: [channel, users]
outputs_schema: { properties: {} }
- id: set_channel_topic
name: slack-set-channel-topic
description: "Set a channel's topic."
inputs_schema:
properties:
channel: { type: string, description: "Channel ID" }
topic: { type: string, description: "New topic text" }
required: [channel, topic]
outputs_schema: { properties: {} }
- id: get_user
name: slack-get-user
description: "Look up a user by ID or email address."
risk: read
inputs_schema:
properties:
user_id: { type: string, description: "User ID (provide this or email)" }
email: { type: string, description: "Email address (provide this or user_id)" }
required: []
outputs_schema: { properties: {} }
- id: add_reaction
name: slack-add-reaction
description: "Add an emoji reaction to a message."
inputs_schema:
properties:
channel: { type: string, description: "Channel ID of the message" }
timestamp: { type: string, description: "Message ts" }
emoji: { type: string, description: "Emoji name without colons (e.g. eyes)" }
required: [channel, timestamp, emoji]
outputs_schema: { properties: {} }
- id: test_connection
name: slack-test-connection
description: "Verify connectivity and the bot token (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
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
channel = str(inputs.get("channel") or "").strip()
if not channel:
raise Exception("channel is required")
timestamp = str(inputs.get("timestamp") or "").strip()
if not timestamp:
raise Exception("timestamp is required")
emoji = str(inputs.get("emoji") or "").strip()
if not emoji:
raise Exception("emoji is required")
return call("reactions.add", cfg, body={"channel": channel, "timestamp": timestamp, "name": emoji})
_run(main)
@@ -0,0 +1,51 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
name = str(inputs.get("name") or "").strip()
if not name:
raise Exception("name is required")
is_private = bool(inputs.get("is_private") or False)
return call("conversations.create", cfg, body={"name": name, "is_private": is_private})
_run(main)
+53
View File
@@ -0,0 +1,53 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
user_id = str(inputs.get("user_id") or "").strip()
email = str(inputs.get("email") or "").strip()
if email:
return call("users.lookupByEmail", cfg, params={"email": email}, http="GET")
elif user_id:
return call("users.info", cfg, params={"user": user_id}, http="GET")
else:
raise Exception("user_id or email is required")
_run(main)
@@ -0,0 +1,54 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
channel = str(inputs.get("channel") or "").strip()
if not channel:
raise Exception("channel is required")
users_raw = inputs.get("users")
users_list = [s.strip() for s in str(users_raw or "").split(",") if s.strip()]
if not users_list:
raise Exception("users is required")
return call("conversations.invite", cfg, body={"channel": channel, "users": ",".join(users_list)})
_run(main)
@@ -0,0 +1,48 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
types = str(inputs.get("types") or "public_channel,private_channel").strip()
limit = inputs.get("limit") or 200
return call("conversations.list", cfg, params={"types": types, "limit": int(limit)}, http="GET")
_run(main)
@@ -0,0 +1,67 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
channel = str(inputs.get("channel") or "").strip()
if not channel:
raise Exception("channel is required")
text = str(inputs.get("text") or "").strip()
blocks_raw = str(inputs.get("blocks") or "").strip()
thread_ts = str(inputs.get("thread_ts") or "").strip()
if not text and not blocks_raw:
raise Exception("text or blocks is required")
body = {"channel": channel}
if text:
body["text"] = text
if blocks_raw:
try:
body["blocks"] = json.loads(blocks_raw)
except Exception:
raise Exception("blocks must be a valid JSON array")
if thread_ts:
body["thread_ts"] = thread_ts
return call("chat.postMessage", cfg, body=body)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
channel = str(inputs.get("channel") or "").strip()
if not channel:
raise Exception("channel is required")
topic = str(inputs.get("topic") or "").strip()
if not topic:
raise Exception("topic is required")
return call("conversations.setTopic", cfg, body={"channel": channel, "topic": topic})
_run(main)
@@ -0,0 +1,46 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
BASE = "https://slack.com/api"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def call(method_name, cfg, body=None, params=None, http="POST"):
url = BASE + "/" + method_name
if params:
url += "?" + urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")})
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("bot_token", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json; charset=utf-8"
req = urllib.request.Request(url, data=data, headers=headers, method=http)
with urllib.request.urlopen(req, timeout=60) as r:
resp = json.loads(r.read() or "{}")
if not resp.get("ok"):
raise Exception("Slack error: " + str(resp.get("error") or resp))
return resp
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):
resp = call("auth.test", cfg)
return {"ok": True, "team": resp.get("team"), "user": resp.get("user")}
_run(main)