add logs
This commit is contained in:
parent
3705f6c219
commit
1555359e03
1 changed files with 11 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
|
@ -20,6 +21,9 @@ DEFAULT_DURATION = timedelta(hours=3)
|
|||
MAX_DURATION = timedelta(days=3652)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AlertmanagerClient:
|
||||
def __init__(self, url: str, cache: Cache) -> None:
|
||||
self.api_url = f"{url}/api/v2"
|
||||
|
@ -40,6 +44,7 @@ class AlertmanagerClient:
|
|||
) from e
|
||||
|
||||
async def get_alert(self, fingerprint: str) -> Dict:
|
||||
logger.debug(f"Fetching details for alert with fingerprint {fingerprint}")
|
||||
alerts = await self.get_alerts()
|
||||
return self._find_alert(fingerprint, alerts)
|
||||
|
||||
|
@ -54,6 +59,7 @@ class AlertmanagerClient:
|
|||
) from e
|
||||
|
||||
async def get_silence(self, silence_id: str) -> Dict:
|
||||
logger.debug(f"Fetching details for silence with ID {silence_id}")
|
||||
silences = await self.get_silences()
|
||||
return self._find_silence(silence_id, silences)
|
||||
|
||||
|
@ -80,6 +86,9 @@ class AlertmanagerClient:
|
|||
user: Optional[str] = None,
|
||||
duration_seconds: Optional[int] = None,
|
||||
) -> str:
|
||||
logger.debug(
|
||||
f"Reading silence for alert with fingerprint {fingerprint} from cache"
|
||||
)
|
||||
try:
|
||||
silence_id: Optional[str]
|
||||
expire_time: Optional[int]
|
||||
|
@ -92,6 +101,8 @@ class AlertmanagerClient:
|
|||
f"Cannot find silence for alert with fingerprint {fingerprint} in cache."
|
||||
)
|
||||
|
||||
logger.debug(f"Updating silence with ID {silence_id}")
|
||||
|
||||
if duration_seconds is None:
|
||||
if expire_time is not None:
|
||||
raise SilenceExtendError(
|
||||
|
|
Loading…
Reference in a new issue