snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
85
zerver/webhooks/opsgenie/view.py
Normal file
85
zerver/webhooks/opsgenie/view.py
Normal file
@@ -0,0 +1,85 @@
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from pydantic import Json
|
||||
|
||||
from zerver.decorator import webhook_view
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
||||
from zerver.lib.validator import WildValue, check_string
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
from zerver.models import UserProfile
|
||||
|
||||
ALL_EVENT_TYPES = [
|
||||
"AddTeam",
|
||||
"UnAcknowledge",
|
||||
"AddNote",
|
||||
"TestAction",
|
||||
"Close",
|
||||
"Escalate",
|
||||
"AddRecipient",
|
||||
"RemoveTags",
|
||||
"Acknowledge",
|
||||
"Delete",
|
||||
"AddTags",
|
||||
"TakeOwnership",
|
||||
"Create",
|
||||
"AssignOwnership",
|
||||
]
|
||||
|
||||
|
||||
@webhook_view("Opsgenie", all_event_types=ALL_EVENT_TYPES)
|
||||
@typed_endpoint
|
||||
def api_opsgenie_webhook(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
payload: JsonBodyPayload[WildValue],
|
||||
eu_region: Json[bool] = False,
|
||||
) -> HttpResponse:
|
||||
# construct the body of the message
|
||||
info = {
|
||||
"additional_info": "",
|
||||
"url_region": "eu." if eu_region else "",
|
||||
"alert_type": payload["action"].tame(check_string),
|
||||
"alert_id": payload["alert"]["alertId"].tame(check_string),
|
||||
"integration_name": payload["integrationName"].tame(check_string),
|
||||
"tags": ", ".join(
|
||||
"`" + tag.tame(check_string) + "`" for tag in payload["alert"].get("tags", [])
|
||||
),
|
||||
}
|
||||
|
||||
topic_name = info["integration_name"]
|
||||
bullet_template = "* **{key}**: {value}\n"
|
||||
|
||||
fields = {
|
||||
"note": "Note",
|
||||
"recipient": "Recipient",
|
||||
"addedTags": "Tags added",
|
||||
"team": "Team added",
|
||||
"owner": "Assigned owner",
|
||||
"removedTags": "Tags removed",
|
||||
"message": "Message",
|
||||
"tags": "Tags",
|
||||
"escalationName": "Escalation",
|
||||
}
|
||||
|
||||
for field, display_name in fields.items():
|
||||
if field == "tags" and info["tags"]:
|
||||
value = info["tags"]
|
||||
elif field == "escalationName" and field in payload:
|
||||
value = payload[field].tame(check_string)
|
||||
elif field in payload.get("alert", {}) and field != "tags":
|
||||
value = payload["alert"][field].tame(check_string)
|
||||
else:
|
||||
continue
|
||||
info["additional_info"] += bullet_template.format(key=display_name, value=value)
|
||||
|
||||
body_template = """
|
||||
[Opsgenie alert for {integration_name}](https://app.{url_region}opsgenie.com/alert/V2#/show/{alert_id}):
|
||||
* **Type**: {alert_type}
|
||||
{additional_info}
|
||||
""".strip()
|
||||
|
||||
body = body_template.format(**info)
|
||||
check_send_webhook_message(request, user_profile, topic_name, body, info["alert_type"])
|
||||
|
||||
return json_success(request)
|
||||
Reference in New Issue
Block a user