feat(bot): show actual response, flap threshold, pause/rename/baseline, komodo fleet and alerts
This commit is contained in:
+41
-5
@@ -1,4 +1,4 @@
|
||||
from pydantic import Field, SecretStr
|
||||
from pydantic import Field, SecretStr, computed_field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@@ -7,9 +7,36 @@ class BotSettings(BaseSettings):
|
||||
|
||||
|
||||
class MonitorSettings(BaseSettings):
|
||||
check_interval: int = 30 # как часто пинговать сервисы, сек
|
||||
reminder_interval: int = 1800 # как часто напоминать что всё ещё лежит, сек
|
||||
request_timeout: int = 10 # таймаут одного запроса, сек
|
||||
check_interval: int = 30
|
||||
reminder_interval: int = 1800
|
||||
request_timeout: int = 10
|
||||
|
||||
failure_threshold: int = 2
|
||||
|
||||
body_preview: int = 400
|
||||
|
||||
|
||||
class KomodoSettings(BaseSettings):
|
||||
"""Связь с Komodo. Всё опционально - без неё бот работает как раньше."""
|
||||
|
||||
url: str = ""
|
||||
key: SecretStr = SecretStr("")
|
||||
secret: SecretStr = SecretStr("")
|
||||
timeout: int = 20
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def enabled(self) -> bool:
|
||||
return bool(self.url and self.key.get_secret_value())
|
||||
|
||||
|
||||
class WebSettings(BaseSettings):
|
||||
"""Приёмник входящих алертов (Komodo Alerter с endpoint type Custom)."""
|
||||
|
||||
enabled: bool = False
|
||||
host: str = "0.0.0.0" # noqa: S104
|
||||
port: int = 8080
|
||||
token: SecretStr = SecretStr("")
|
||||
|
||||
|
||||
class DbSettings(BaseSettings):
|
||||
@@ -24,9 +51,13 @@ class LogSettings(BaseSettings):
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
admin_id: int
|
||||
admin_id: int = 0
|
||||
admin_ids: list[int] = Field(default_factory=list)
|
||||
|
||||
bot: BotSettings = Field(default_factory=BotSettings)
|
||||
monitor: MonitorSettings = Field(default_factory=MonitorSettings)
|
||||
komodo: KomodoSettings = Field(default_factory=KomodoSettings)
|
||||
web: WebSettings = Field(default_factory=WebSettings)
|
||||
db: DbSettings = Field(default_factory=DbSettings)
|
||||
log: LogSettings = Field(default_factory=LogSettings)
|
||||
|
||||
@@ -34,5 +65,10 @@ class Settings(BaseSettings):
|
||||
case_sensitive=False, env_file=".env", env_nested_delimiter="__", extra="ignore"
|
||||
)
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def admins(self) -> set[int]:
|
||||
return {i for i in (self.admin_id, *self.admin_ids) if i}
|
||||
|
||||
|
||||
env = Settings()
|
||||
|
||||
Reference in New Issue
Block a user