monitoring.silences module

Mongo-backed alert silences for ChatOps.

Goals: - Fail-open: never raise; return safe defaults - Lazy init with env-only config (avoid global config import cycles) - TTL on until_ts so expired silences auto-clean - Active flag to allow manual unsilence before TTL

ENV: - ALERTS_DB_ENABLED or METRICS_DB_ENABLED: enable DB access - MONGODB_URL, DATABASE_NAME - ALERTS_SILENCES_COLLECTION (default: alerts_silences) - SILENCE_MAX_DAYS (default: 7) - SILENCES_MAX_ACTIVE (default: 50)

monitoring.silences.parse_duration_to_seconds(text, *, max_days=7)[מקור]

Parse duration like ”30s“, ”5m“, ”2h“, ”3d“ to seconds, bounded by max_days. Returns None on invalid.

Return type:

Optional[int]

פרמטרים:
monitoring.silences.create_silence(*, pattern, duration_seconds, created_by, reason='', severity=None, force=False)[מקור]

Create a new active silence. Returns stored document on success, else None.

Return type:

Optional[Dict[str, Any]]

פרמטרים:
  • pattern (str)

  • duration_seconds (int)

  • created_by (int)

  • reason (str)

  • severity (str | None)

  • force (bool)

monitoring.silences.is_silenced(name, severity=None)[מקור]

Return (True, silence_doc) if any active silence matches alert name and optional severity.

Return type:

Tuple[bool, Optional[Dict[str, Any]]]

פרמטרים:
  • name (str)

  • severity (str | None)

monitoring.silences.unsilence_by_id(silence_id)[מקור]
Return type:

bool

פרמטרים:

silence_id (str)

monitoring.silences.unsilence_by_pattern(pattern)[מקור]
Return type:

int

פרמטרים:

pattern (str)

monitoring.silences.list_active_silences(limit=50)[מקור]
Return type:

List[Dict[str, Any]]

פרמטרים:

limit (int)