From 2abf1b9738565f0c266d1998310c723253b89c83 Mon Sep 17 00:00:00 2001 From: shukon <> Date: Mon, 8 May 2023 11:01:26 +0200 Subject: [PATCH 1/5] Add configurable healthchecks.io URL option --- conf/backup-with-borg | 12 ++++++++++++ config_panel.toml | 7 ++++++- manifest.json | 10 +++++++++- scripts/config | 5 +++++ scripts/install | 4 ++-- scripts/upgrade | 1 + 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/conf/backup-with-borg b/conf/backup-with-borg index 33aaf1f..c9f9f98 100644 --- a/conf/backup-with-borg +++ b/conf/backup-with-borg @@ -25,6 +25,11 @@ fail_if_partially_failed() { sudo yunohost app setting ${borg_id} last_run -v "${current_date}" sudo yunohost app setting ${borg_id} state -v "ongoing" +# Start healthcheck if configured +if [[ ! -z "$healthcheck_url" ]]; then + curl -s -m 10 -o /dev/null "$healthcheck_url/start" +fi + # Backup system part conf conf=$(sudo yunohost app setting ${borg_id} conf) if [[ "$conf" = "1" ]] @@ -76,10 +81,17 @@ fi domain=$(hostname) repository="$(sudo yunohost app setting ${borg_id} repository)" mailalert="$(sudo yunohost app setting ${borg_id} mailalert)" +healthcheck_url="$(sudo yunohost app setting ${borg_id} healthcheck_url)" if [[ ! -z "$errors" ]]; then sudo yunohost app setting ${borg_id} state -v "failed" + if [[ ! -z "$healthcheck_url" ]]; then + curl -s -m 10 -o /dev/null --data-raw "$(tail --bytes=10000 $errors)" "$healthcheck_url/fail" + fi else sudo yunohost app setting ${borg_id} state -v "successful" + if [[ ! -z "$healthcheck_url" ]]; then + curl -s -m 10 -o /dev/null "$healthcheck_url" + fi fi if [[ ! -z "$errors" && $mailalert != "never" ]]; then diff --git a/config_panel.toml b/config_panel.toml index b5b4d41..f1a70fa 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -45,7 +45,12 @@ services = [] choices.errors_only = "Only if an error occured" choices.never = "Never alert me" help = "Alerts are sent to the first user of this server" - + + [main.general.healthcheck_url] + ask.en = "Healthcheck URL" + type = "string" + help = "Using a healthcheck will allow you to detect silent failures. If you don't know what it is, just leave it blank or look it up: https://healthchecks.io" + [main.content] name = "What should be backuped ?" optional = false diff --git a/manifest.json b/manifest.json index 8fc19ef..cf53c5b 100644 --- a/manifest.json +++ b/manifest.json @@ -94,7 +94,15 @@ "fr": "Souhaitez-vous recevoir des notifications par mail à chaque sauvegarde ?" }, "choices": ["always", "errors_only", "never"] - } + }, + { + "name": "healthcheck_url", + "type": "string", + "ask": { + "en": "Specify a healthchecks.io URL to ping on successful backup (leave blank to skip):", + "fr": "Indiquez une URL healthchecks.io à pinger en cas de sauvegarde réussie (laissez vide pour ignorer):" + } + } ] } } diff --git a/scripts/config b/scripts/config index 4578046..7d89121 100644 --- a/scripts/config +++ b/scripts/config @@ -60,6 +60,11 @@ validate__on_calendar() { echo 'Please follow systemd OnCalendar format: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS' } +validate__healthcheck_url() { + [[ $healthcheck_url =~ ^https?://[^/]+(/.*)?$ ]] || + echo 'Please enter a valid URL' +} + #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= diff --git a/scripts/install b/scripts/install index e89ba36..f7fe921 100755 --- a/scripts/install +++ b/scripts/install @@ -22,7 +22,7 @@ ynh_abort_if_errors export app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -ynh_export repository passphrase on_calendar conf data apps mailalert +ynh_export repository passphrase on_calendar conf data apps mailalert healthcheck_url #================================================= # STORE SETTINGS FROM MANIFEST @@ -37,7 +37,7 @@ if [[ $repository == *"@"* ]]; then fi state="repository uncreated" last_run="-" -ynh_save_args repository server passphrase on_calendar conf data apps mailalert state last_run +ynh_save_args repository server passphrase on_calendar conf data apps mailalert healthcheck_url state last_run #================================================= # INSTALL DEPENDENCIES diff --git a/scripts/upgrade b/scripts/upgrade index 5d7c41c..9e4c573 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,6 +23,7 @@ export on_calendar="$(ynh_app_setting_get $app on_calendar)" export conf="$(ynh_app_setting_get $app conf)" export data="$(ynh_app_setting_get $app data)" export apps="$(ynh_app_setting_get $app apps)" +export healthcheck_url="$(ynh_app_setting_get $app healthcheck_url)" export mailalert="$(ynh_app_setting_get $app mailalert)" if [[ $mailalert != "always" && $mailalert != "errors_only" && $mailalert != "never" ]]; then ynh_app_setting_set --app=$app --key="mailalert" --value="errors_only" From 91e038f01f8d3fcae82c942a1bcb9e8221641e71 Mon Sep 17 00:00:00 2001 From: shukon <> Date: Mon, 8 May 2023 16:06:15 +0200 Subject: [PATCH 2/5] Make healthcheck URL optional --- config_panel.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/config_panel.toml b/config_panel.toml index f1a70fa..330c823 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -50,6 +50,7 @@ services = [] ask.en = "Healthcheck URL" type = "string" help = "Using a healthcheck will allow you to detect silent failures. If you don't know what it is, just leave it blank or look it up: https://healthchecks.io" + optional = "true" [main.content] name = "What should be backuped ?" From 699e7703f97cb38d2aa69acc2df68a206bd48b90 Mon Sep 17 00:00:00 2001 From: shukon <> Date: Wed, 10 May 2023 08:59:58 +0200 Subject: [PATCH 3/5] Fix logs not properly escaped when sending sometimes --- conf/backup-with-borg | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/conf/backup-with-borg b/conf/backup-with-borg index c9f9f98..9fc5ac3 100644 --- a/conf/backup-with-borg +++ b/conf/backup-with-borg @@ -19,16 +19,20 @@ filter_hooks() { sudo ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq 2>> $err_file } +healthcheck_url="$(sudo yunohost app setting ${borg_id} healthcheck_url)" +healthcheck() { + if [[ ! -z "$healthcheck_url" ]]; then + curl -s -m 10 -o /dev/null --data-raw "$(echo tail --bytes=10000 $2)" "$healthcheck_url/$1" + fi +} + fail_if_partially_failed() { grep Skipped|Error } sudo yunohost app setting ${borg_id} last_run -v "${current_date}" sudo yunohost app setting ${borg_id} state -v "ongoing" -# Start healthcheck if configured -if [[ ! -z "$healthcheck_url" ]]; then - curl -s -m 10 -o /dev/null "$healthcheck_url/start" -fi +healthcheck_url "start" # Backup system part conf conf=$(sudo yunohost app setting ${borg_id} conf) @@ -81,17 +85,12 @@ fi domain=$(hostname) repository="$(sudo yunohost app setting ${borg_id} repository)" mailalert="$(sudo yunohost app setting ${borg_id} mailalert)" -healthcheck_url="$(sudo yunohost app setting ${borg_id} healthcheck_url)" if [[ ! -z "$errors" ]]; then sudo yunohost app setting ${borg_id} state -v "failed" - if [[ ! -z "$healthcheck_url" ]]; then - curl -s -m 10 -o /dev/null --data-raw "$(tail --bytes=10000 $errors)" "$healthcheck_url/fail" - fi + healthcheck_url "fail" $errors else sudo yunohost app setting ${borg_id} state -v "successful" - if [[ ! -z "$healthcheck_url" ]]; then - curl -s -m 10 -o /dev/null "$healthcheck_url" - fi + healthcheck_url fi if [[ ! -z "$errors" && $mailalert != "never" ]]; then From 30bc25acb26b4814c82708cd5a8b3d310266673a Mon Sep 17 00:00:00 2001 From: shukon <> Date: Wed, 10 May 2023 10:49:08 +0200 Subject: [PATCH 4/5] Merge healthchecks --- conf/backup-with-borg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/backup-with-borg b/conf/backup-with-borg index 9fc5ac3..c831fca 100644 --- a/conf/backup-with-borg +++ b/conf/backup-with-borg @@ -22,7 +22,7 @@ filter_hooks() { healthcheck_url="$(sudo yunohost app setting ${borg_id} healthcheck_url)" healthcheck() { if [[ ! -z "$healthcheck_url" ]]; then - curl -s -m 10 -o /dev/null --data-raw "$(echo tail --bytes=10000 $2)" "$healthcheck_url/$1" + curl -s -m 10 -o /dev/null --data-raw "$(echo $2 | tail --bytes=10000)" "$healthcheck_url/$1" fi } @@ -32,7 +32,7 @@ fail_if_partially_failed() { sudo yunohost app setting ${borg_id} last_run -v "${current_date}" sudo yunohost app setting ${borg_id} state -v "ongoing" -healthcheck_url "start" +healthcheck "start" # Backup system part conf conf=$(sudo yunohost app setting ${borg_id} conf) @@ -87,10 +87,10 @@ repository="$(sudo yunohost app setting ${borg_id} repository)" mailalert="$(sudo yunohost app setting ${borg_id} mailalert)" if [[ ! -z "$errors" ]]; then sudo yunohost app setting ${borg_id} state -v "failed" - healthcheck_url "fail" $errors + healthcheck "fail" "$errors" else sudo yunohost app setting ${borg_id} state -v "successful" - healthcheck_url + healthcheck fi if [[ ! -z "$errors" && $mailalert != "never" ]]; then From 159bd111c63fcce0a1b8b3d589b517aa15007a21 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Tue, 21 May 2024 20:33:03 +0000 Subject: [PATCH 5/5] Auto-update READMEs --- ALL_README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ALL_README.md b/ALL_README.md index 8938aae..152f2e7 100644 --- a/ALL_README.md +++ b/ALL_README.md @@ -1,7 +1,7 @@ # All available README files by language - [Read the README in English](README.md) -- [Lee el README en español](README_es.md) +- [Lea el README en español](README_es.md) - [Irakurri README euskaraz](README_eu.md) - [Lire le README en français](README_fr.md) - [Le o README en galego](README_gl.md)