You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
motief/health/__init__.py

42 lines
952 B

from dataclasses import dataclass
from enum import Enum
from typing import List
class HealthStatus(Enum):
OK = "ok"
WARNING = "warning"
CRITICAL = "critical"
@dataclass
class HealthCheck:
name: str
status: HealthStatus
message: str
details: dict
@dataclass
class HealthReport:
checks: List[HealthCheck]
@property
def status(self) -> HealthStatus:
if any(c.status == HealthStatus.CRITICAL for c in self.checks):
return HealthStatus.CRITICAL
if any(c.status == HealthStatus.WARNING for c in self.checks):
return HealthStatus.WARNING
return HealthStatus.OK
@property
def exit_code(self) -> int:
if self.status == HealthStatus.CRITICAL:
return 2
if self.status == HealthStatus.WARNING:
return 1
return 0
def run_checks(checks: List[HealthCheck]) -> HealthReport:
return HealthReport(checks=checks)