Report.push_webhook()

This commit is contained in:
Jörn-Michael Miehe 2023-09-01 22:56:20 +00:00
parent cc45e8d02a
commit 627edab9e9
3 changed files with 17 additions and 17 deletions

View file

@ -1,9 +1,6 @@
#!/usr/bin/python3
import asyncio
import urllib.parse
import requests
from . import metrics
from .settings import SETTINGS
@ -22,14 +19,8 @@ def handle_report() -> None:
if SETTINGS.log.enabled:
print(report)
# maybe push this to a webhook
if (url := SETTINGS.webhook.get_url(failed=report.failed)) is not None:
requests.get(
url=str(url).format(
urllib.parse.quote_plus(report.result)
),
verify=not SETTINGS.webhook.insecure,
)
# maybe push this to the configured webhook
report.push_webhook()
async def run_metrics() -> None:

View file

@ -1,6 +1,9 @@
import urllib.parse
from dataclasses import dataclass
from typing import Any, Callable, Iterator, Self
import requests
from ..settings import SETTINGS, MetricSettings
@ -112,3 +115,15 @@ class Report:
for report in reports
),
)
def push_webhook(self) -> None:
if (url := SETTINGS.webhook.url if not self.failed
else SETTINGS.webhook.fail) is None:
return
requests.get(
url=str(url).format(
urllib.parse.quote_plus(self.result)
),
verify=not SETTINGS.webhook.insecure,
)

View file

@ -16,9 +16,3 @@ class WebhookSettings(BaseModel):
# allow insecure/self-signed webhook targets
insecure: bool = False
def get_url(self, failed: bool) -> AnyUrl | None:
if failed:
return self.fail
return self.url