alerts: per-support-team webhook + printedparts routing
This commit is contained in:
@@ -225,16 +225,18 @@ def _webhook_payload(fmt, title, text):
|
||||
}
|
||||
|
||||
|
||||
def send_webhook(title, text):
|
||||
"""POST an alert to the configured webhook (Teams, etc.). Best-effort:
|
||||
returns (ok, error); a no-op ((False, None)) when no URL is configured, and
|
||||
never raises so it can never block the caller."""
|
||||
def send_webhook(title, text, url=None):
|
||||
"""POST an alert to a webhook (Teams, etc.). `url` overrides the site
|
||||
alert_webhook_url (e.g. a support team's own webhook); the payload format
|
||||
still follows alert_webhook_format. Best-effort: returns (ok, error), a
|
||||
no-op ((False, None)) when no URL resolves, and never raises."""
|
||||
config = get_webhook_config()
|
||||
if not config['url']:
|
||||
target = (url or '').strip() or config['url']
|
||||
if not target:
|
||||
return False, None
|
||||
try:
|
||||
response = requests.post(
|
||||
config['url'], json=_webhook_payload(config['format'], title, text),
|
||||
target, json=_webhook_payload(config['format'], title, text),
|
||||
timeout=10)
|
||||
if response.status_code >= 400:
|
||||
return False, f'HTTP {response.status_code}'
|
||||
|
||||
Reference in New Issue
Block a user