backups: use apprise for notifications
Linting / YAML Lint (push) Successful in 9s
Linting / Ansible Lint (push) Failing after 29s

This commit is contained in:
2026-04-04 11:30:53 +03:00
parent 362d6d8710
commit 5f619eaccc
3 changed files with 20 additions and 25 deletions
+15 -21
View File
@@ -158,38 +158,32 @@ class Notifier(ABC):
raise NotImplementedError() raise NotImplementedError()
class TelegramNotifier(Notifier): class AppriseNotifier(Notifier):
TYPE_NAME = "telegram" TYPE_NAME = "apprise"
def __init__(self, name: str, params: Dict[str, Any]): def __init__(self, name: str, params: Dict[str, Any]):
self.name = name self.name = name
self.telegram_bot_token = str(params.get("telegram_bot_token", "")) self.api_url = str(params.get("api_url", "")).rstrip("/")
self.telegram_chat_id = str(params.get("telegram_chat_id", "")) self.tag = str(params.get("tag", ""))
if not all( if not self.api_url or not self.tag:
[
self.telegram_bot_token,
self.telegram_chat_id,
]
):
raise ValueError( raise ValueError(
f"Missing notification configuration values for backend {name}" f"Missing notification configuration values for backend {name}"
) )
def send(self, html_message: str) -> None: def send(self, html_message: str) -> None:
url = f"https://api.telegram.org/bot{self.telegram_bot_token}/sendMessage" url = f"{self.api_url}/notify/{self.tag}/"
data = { payload = {
"chat_id": self.telegram_chat_id, "body": html_message,
"parse_mode": "HTML", "format": "html",
"text": html_message,
} }
response = requests.post(url, data=data, timeout=30) response = requests.post(url, json=payload, timeout=30)
if response.status_code == 200: if response.ok:
logger.info("Telegram notification sent successfully") logger.info("Apprise notification sent successfully")
else: else:
logger.error( logger.error(
f"Failed to send Telegram notification: {response.status_code} - {response.text}" f"Failed to send Apprise notification: {response.status_code} - {response.text}"
) )
@@ -459,8 +453,8 @@ def initialize(config_path: Path) -> BackupManager:
if not isinstance(params, dict): if not isinstance(params, dict):
raise ValueError(f"Notificator config for {name} must be a table") raise ValueError(f"Notificator config for {name} must be a table")
notifier_type = params.get("type", "") notifier_type = params.get("type", "")
if notifier_type == TelegramNotifier.TYPE_NAME: if notifier_type == AppriseNotifier.TYPE_NAME:
notifiers.append(TelegramNotifier(name, params)) notifiers.append(AppriseNotifier(name, params))
if not notifiers: if not notifiers:
raise ValueError("At least one notification backend must be configured") raise ValueError("At least one notification backend must be configured")
+4 -4
View File
@@ -12,7 +12,7 @@ aws_access_key_id = "{{ restic_s3_access_key }}"
aws_secret_access_key = "{{ restic_s3_access_secret }}" aws_secret_access_key = "{{ restic_s3_access_secret }}"
aws_default_region = "{{ restic_s3_region }}" aws_default_region = "{{ restic_s3_region }}"
[notifier.server_notifications_channel] [notifier.apprise]
type = "telegram" type = "apprise"
telegram_bot_token = "{{ notifications_tg_bot_token }}" api_url = "{{ apprise_external_url }}"
telegram_chat_id = "{{ notifications_tg_chat_id }}" tag = "server"
+1
View File
@@ -4,6 +4,7 @@
vars_files: vars_files:
- vars/secrets.yml - vars/secrets.yml
- vars/vars.yml
vars: vars:
backup_config_dir: "/etc/backup" backup_config_dir: "/etc/backup"