send a message when alert were not fonud
This commit is contained in:
parent
2359f6ca77
commit
7a273f5072
1 changed files with 27 additions and 1 deletions
|
@ -7,7 +7,11 @@ from nio import AsyncClient, MatrixRoom
|
||||||
from matrix_alertbot.alertmanager import AlertmanagerClient
|
from matrix_alertbot.alertmanager import AlertmanagerClient
|
||||||
from matrix_alertbot.chat_functions import send_text_to_room
|
from matrix_alertbot.chat_functions import send_text_to_room
|
||||||
from matrix_alertbot.config import Config
|
from matrix_alertbot.config import Config
|
||||||
from matrix_alertbot.errors import AlertmanagerError
|
from matrix_alertbot.errors import (
|
||||||
|
AlertNotFoundError,
|
||||||
|
AlertmanagerError,
|
||||||
|
SilenceNotFoundError,
|
||||||
|
)
|
||||||
from matrix_alertbot.matcher import AlertMatcher, AlertRegexMatcher
|
from matrix_alertbot.matcher import AlertMatcher, AlertRegexMatcher
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -95,6 +99,7 @@ class Command:
|
||||||
alert_fingerprints = self.cache[self.event_id]
|
alert_fingerprints = self.cache[self.event_id]
|
||||||
logger.debug(f"Found {len(alert_fingerprints)} in cache")
|
logger.debug(f"Found {len(alert_fingerprints)} in cache")
|
||||||
|
|
||||||
|
count_alert_not_found = 0
|
||||||
count_created_silences = 0
|
count_created_silences = 0
|
||||||
for alert_fingerprint in alert_fingerprints:
|
for alert_fingerprint in alert_fingerprints:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -108,9 +113,19 @@ class Command:
|
||||||
matchers,
|
matchers,
|
||||||
)
|
)
|
||||||
count_created_silences += 1
|
count_created_silences += 1
|
||||||
|
except AlertNotFoundError as e:
|
||||||
|
logger.warning(f"Unable to create silence: {e}")
|
||||||
|
count_alert_not_found += 1
|
||||||
except AlertmanagerError as e:
|
except AlertmanagerError as e:
|
||||||
logger.exception(f"Unable to create silence: {e}", exc_info=e)
|
logger.exception(f"Unable to create silence: {e}", exc_info=e)
|
||||||
|
|
||||||
|
if count_alert_not_found > 0:
|
||||||
|
await send_text_to_room(
|
||||||
|
self.client,
|
||||||
|
self.room.room_id,
|
||||||
|
f"Sorry, I couldn't find {count_alert_not_found} alerts, and thus I couldn't acknowledge them.",
|
||||||
|
)
|
||||||
|
|
||||||
await send_text_to_room(
|
await send_text_to_room(
|
||||||
self.client,
|
self.client,
|
||||||
self.room.room_id,
|
self.room.room_id,
|
||||||
|
@ -140,6 +155,7 @@ class Command:
|
||||||
alert_fingerprints = self.cache[self.event_id]
|
alert_fingerprints = self.cache[self.event_id]
|
||||||
logger.debug(f"Found {len(alert_fingerprints)} in cache")
|
logger.debug(f"Found {len(alert_fingerprints)} in cache")
|
||||||
|
|
||||||
|
count_alert_not_found = 0
|
||||||
count_removed_silences = 0
|
count_removed_silences = 0
|
||||||
for alert_fingerprint in alert_fingerprints:
|
for alert_fingerprint in alert_fingerprints:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -150,9 +166,19 @@ class Command:
|
||||||
alert_fingerprint, matchers
|
alert_fingerprint, matchers
|
||||||
)
|
)
|
||||||
count_removed_silences += len(removed_silences)
|
count_removed_silences += len(removed_silences)
|
||||||
|
except (AlertNotFoundError, SilenceNotFoundError) as e:
|
||||||
|
logger.error(f"Unable to create silence: {e}")
|
||||||
|
count_alert_not_found += 1
|
||||||
except AlertmanagerError as e:
|
except AlertmanagerError as e:
|
||||||
logger.exception(f"Unable to delete silence: {e}", exc_info=e)
|
logger.exception(f"Unable to delete silence: {e}", exc_info=e)
|
||||||
|
|
||||||
|
if count_alert_not_found > 0:
|
||||||
|
await send_text_to_room(
|
||||||
|
self.client,
|
||||||
|
self.room.room_id,
|
||||||
|
f"Sorry, I couldn't find {count_alert_not_found} alerts, and thus I couldn't unacknowledge them.",
|
||||||
|
)
|
||||||
|
|
||||||
await send_text_to_room(
|
await send_text_to_room(
|
||||||
self.client,
|
self.client,
|
||||||
self.room.room_id,
|
self.room.room_id,
|
||||||
|
|
Loading…
Add table
Reference in a new issue