backups: notifications to email
This commit is contained in:
@@ -1 +1,2 @@
|
||||
tgram://{{ notifications_tg_bot_token }}/{{ notifications_tg_chat_id }}
|
||||
mailtos://{{ postbox_user }}:{{ postbox_pass }}@{{ postbox_host }}:{{ postbox_port }}/?from=notifications@vakhrushev.me&to={{ notifications_email }}
|
||||
|
||||
@@ -154,7 +154,7 @@ class ResticStorage(Storage):
|
||||
|
||||
|
||||
class Notifier(ABC):
|
||||
def send(self, html_message: str) -> None:
|
||||
def send(self, title: str, html_message: str) -> None:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@@ -170,9 +170,10 @@ class AppriseNotifier(Notifier):
|
||||
f"Missing notification configuration values for backend {name}"
|
||||
)
|
||||
|
||||
def send(self, html_message: str) -> None:
|
||||
def send(self, title: str, html_message: str) -> None:
|
||||
url = f"{self.api_url}/notify/{self.tag}/"
|
||||
payload = {
|
||||
"title": title,
|
||||
"body": html_message,
|
||||
"format": "html",
|
||||
}
|
||||
@@ -340,12 +341,16 @@ class BackupManager:
|
||||
def send_notification(self, success: bool) -> None:
|
||||
"""Send notification to Notifiers"""
|
||||
|
||||
host = self.config.host_name
|
||||
|
||||
if success and not self.errors:
|
||||
message = f"<b>{self.config.host_name}</b>: бекап успешно завершен!"
|
||||
title = f"{host}: бекап успешно завершен"
|
||||
message = f"<b>{host}</b>: бекап успешно завершен!"
|
||||
if self.successful_backups:
|
||||
message += f"\n\nУспешные бекапы: {', '.join(self.successful_backups)}"
|
||||
else:
|
||||
message = f"<b>{self.config.host_name}</b>: бекап завершен с ошибками!"
|
||||
title = f"{host}: бекап завершен с ошибками"
|
||||
message = f"<b>{host}</b>: бекап завершен с ошибками!"
|
||||
|
||||
if self.successful_backups:
|
||||
message += (
|
||||
@@ -360,7 +365,7 @@ class BackupManager:
|
||||
|
||||
for notificator in self.notifiers:
|
||||
try:
|
||||
notificator.send(message)
|
||||
notificator.send(title, message)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send notification: {str(e)}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user