First pass at implemenation with pagerduty webhooks
This commit is contained in:
parent
b71b8d95ff
commit
80c6fbd7bb
15 changed files with 1419 additions and 0 deletions
41
ops_bot/pagerduty.py
Normal file
41
ops_bot/pagerduty.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import json
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
def urgency_color(urgency: str) -> str:
|
||||
if urgency == "high":
|
||||
return "#dc3545"
|
||||
else:
|
||||
return "#17a2b8"
|
||||
|
||||
|
||||
def parse_pagerduty_event(payload: Any) -> Tuple[str, str]:
|
||||
"""
|
||||
Parses a pagerduty webhook v3 event into a human readable message.
|
||||
Returns a tuple where the first item is plain text, and the second item is matrix html formatted text
|
||||
"""
|
||||
event = payload["event"]
|
||||
# evt_id = event["id"]
|
||||
# event_type = event["event_type"]
|
||||
# resource_type = event["resource_type"]
|
||||
# occurred_at = event["occurred_at"]
|
||||
data = event["data"]
|
||||
data_type = data["type"]
|
||||
|
||||
if data_type == "incident":
|
||||
url = data["html_url"]
|
||||
status: str = data["status"]
|
||||
title: str = data["title"]
|
||||
service_name: str = data["service"]["summary"]
|
||||
urgency: str = data.get("urgency", "high")
|
||||
plain = f"{status}: on {service_name}: {title} {url}"
|
||||
formatted = f"<strong><font color={urgency_color(urgency)}>{status.upper()}</font></strong> on {service_name}: [{title}]({url})"
|
||||
return plain, formatted
|
||||
|
||||
payload_str = json.dumps(payload, sort_keys=True, indent=2)
|
||||
return (
|
||||
"unhandled",
|
||||
f"""**unhandled pager duty event**
|
||||
<pre><code class="language-json">{payload_str}</code></pre>
|
||||
""",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue