treefmt / nix fmt (pull_request) Successful in 5s
pytest / pytest (pull_request) Successful in 24s
build_systems / build-bob (pull_request) Successful in 45s
build_systems / build-brain (pull_request) Successful in 45s
build_systems / build-rhapsody-in-green (pull_request) Successful in 58s
build_systems / build-jeeves (pull_request) Successful in 2m15s
treefmt / nix fmt (push) Successful in 5s
build_systems / build-jeeves (push) Successful in 9s
pytest / pytest (push) Successful in 24s
build_systems / build-brain (push) Successful in 30s
build_systems / build-bob (push) Successful in 32s
build_systems / build-rhapsody-in-green (push) Successful in 44s
Move signal_alert out of python/common.py into a dedicated python/signal_alert.py module and update its importers (validate_system.py, snapshot_manager.py) to the new path. Relocate the signal_alert tests from tests/test_common.py into tests/test_signal_alert.py, repatching python.signal_alert.logger and python.signal_alert.Apprise to match the new module.
31 lines
769 B
Python
31 lines
769 B
Python
"""signal_alert."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from os import getenv
|
|
|
|
from apprise import Apprise
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def signal_alert(body: str, title: str = "") -> None:
|
|
"""Send a signal alert.
|
|
|
|
Args:
|
|
body (str): The body of the alert.
|
|
title (str, optional): The title of the alert. Defaults to "".
|
|
"""
|
|
apprise_client = Apprise()
|
|
|
|
from_phone = getenv("SIGNAL_ALERT_FROM_PHONE")
|
|
to_phone = getenv("SIGNAL_ALERT_TO_PHONE")
|
|
if not from_phone or not to_phone:
|
|
logger.info("SIGNAL_ALERT_FROM_PHONE or SIGNAL_ALERT_TO_PHONE not set")
|
|
return
|
|
|
|
apprise_client.add(f"signal://localhost:8989/{from_phone}/{to_phone}")
|
|
|
|
apprise_client.notify(title=title, body=body)
|