Files
LLM-Zabbix-HABR/alert-receiver/app/config.py
T

48 lines
1.2 KiB
Python

from __future__ import annotations
import os
from dataclasses import dataclass
from dotenv import load_dotenv
load_dotenv()
def _parse_bool(value: str | None, default: bool = False) -> bool:
if value is None:
return default
return value.strip().lower() in {"1", "true", "yes", "on"}
@dataclass(frozen=True)
class Settings:
app_name: str = os.getenv("APP_NAME", "alert-receiver")
app_host: str = os.getenv("APP_HOST", "0.0.0.0")
app_port: int = int(os.getenv("APP_PORT", "8080"))
webhook_token: str = os.getenv("WEBHOOK_TOKEN", "").strip()
require_webhook_token: bool = _parse_bool(
os.getenv("REQUIRE_WEBHOOK_TOKEN", "true"),
default=True,
)
forward_to_processor: bool = _parse_bool(
os.getenv("FORWARD_TO_PROCESSOR", "false"),
default=False,
)
alert_processor_url: str = os.getenv(
"ALERT_PROCESSOR_URL",
"http://alert-processor:8081/internal/events",
)
alert_processor_token: str = os.getenv(
"ALERT_PROCESSOR_TOKEN",
"",
).strip()
forward_timeout_seconds: float = float(
os.getenv("FORWARD_TIMEOUT_SECONDS", "5")
)
alert_processor_token: str = os.getenv("ALERT_PROCESSOR_TOKEN", "").strip()
settings = Settings()