ttionya / vaultwarden-backup

Backup vaultwarden (formerly known as bitwarden_rs) SQLite3/PostgreSQL/MySQL/MariaDB database by rclone. (Docker)
MIT License
1.04k stars 119 forks source link

Adding Ntfy.sh notification support #161

Closed tom-keim closed 1 month ago

tom-keim commented 2 months ago

Ntfy,sh is a selfhostable notification service. As I use ntfy.sh for notifications about my homelab, I missed the integration in vaultwarden-backup as that only supports PING and MAIL.

This PR will add Ntfy,sh support, it supports 3 different authentication modes: No authentication, username + password and token based authentication.

Also the priority of the notifications are configurable, so that a backup failure results in a more urgent notification on the subscribed clients.

ttionya commented 1 month ago

Thank you for your contribution.

Recently, I have been engrossed in the game "Black Myth: Wukong". Now that I have completed it, I just saw this PR and apologize for the delay.

Ntfy.sh is an excellent push notification system. The existing environment variables PING_URL, PING_URL_WHEN_SUCCESS, and PING_URL_WHEN_FAILURE already provide minimal support.

Ntfy.sh supports GET requests, as detailed in the documentation. If the environment variable PING_URL_WHEN_SUCCESS: 'ntfy.sh/mywebhook/publish?message=Webhook+triggered&priority=high&tags=warning,skull&auth=xxx' is configured, a PING message will be sent to this address when the backup is successful. The minimal support is due to the need for users to set the message themselves, rather than using content provided by the tool.

Ntfy.sh offers a wide range of features, and I do not believe it is wise to provide an environment variable for each feature. The PR added 10 new environment variables, and in the future, we might need to add environment variables for setting X-Tags, X-Email, etc. This requires the tool to continuously adapt to specific notification tools, which is what I am trying to avoid.

ttionya commented 1 month ago

My current plan is to add corresponding curl options environment variables for the existing PING_URL prefixed environment variables, such as PING_URL_CURL_OPTIONS. This way, users can configure them as needed.

For Ntfy.sh, you can set PING_URL_CURL_OPTIONS: '-H "X-Priority: high" -H "X-Tags: warning,skull" -H "Authorization: Bearer xxx"'. It is equivalent to the GET request mentioned earlier.

Additionally, I will add placeholders for these environment variables, such as %{title} and %{content} in PING_URL and PING_URL_CURL_OPTIONS, which can be replaced with actual titles and content.

This approach allows for more functionality with fewer environment variables and avoids continuous adaptation to specific tools, similar to the MAIL_SMTP_VARIABLES environment variable.

I will add the above features as soon as possible.

tom-keim commented 1 month ago

Thank you for your reply, that indeed sounds like a better option.

If I can help in any way please let me know.

I'll close this PR

ttionya commented 1 month ago

Released v1.21.0