Initial InfraPulse scaffold
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Background jobs."""
|
||||
@@ -0,0 +1,16 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class AlertEvaluation:
|
||||
should_open_incident: bool
|
||||
should_resolve_incident: bool
|
||||
message: str
|
||||
|
||||
|
||||
def evaluate_status_rule(current_status: str, failure_count: int, threshold: int) -> AlertEvaluation:
|
||||
if current_status == "up":
|
||||
return AlertEvaluation(False, True, "Monitor recovered")
|
||||
if failure_count >= threshold:
|
||||
return AlertEvaluation(True, False, f"Monitor failed {failure_count} times")
|
||||
return AlertEvaluation(False, False, "Failure threshold not reached")
|
||||
@@ -0,0 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
import httpx
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class WebhookNotification:
|
||||
url: str
|
||||
text: str
|
||||
|
||||
|
||||
async def send_generic_webhook(notification: WebhookNotification) -> None:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
await client.post(notification.url, json={"text": notification.text})
|
||||
Reference in New Issue
Block a user