diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e6c548e874fa089556cf9e31e03caf481f46823..e5b030a0f06dc9a4b72c09eb75104fd375b84b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- [core] implement reportwrap configuration parameter + ### Changed - [core] raise error if mail isn't found in $PATH and reportemail = yes @@ -16,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [build] make build reproducible regardless of usrmerge (DEBBUG-915222) - [core] silence exit code message unless --debug is used - [core] backup halt should trigger email report if enabled +- [core] wrap report email body to 1000 characters by default (DEBBUG-871793) ## [1.2.0] - 2021-01-21 diff --git a/etc/backupninja.conf.in b/etc/backupninja.conf.in index a350fc849450e01a00ba9e3735ce1295bc6d6cef..f2366a32b782c8bf8e00d3dcd4b54209729cd29f 100644 --- a/etc/backupninja.conf.in +++ b/etc/backupninja.conf.in @@ -46,6 +46,9 @@ reportuser = ninja # use a globally unique name, preferably the hostname reportdirectory = /var/lib/backupninja/reports +# number of columns the report email body should wrap to +#reportwrap = 80 + # set to the administration group that is allowed to # read/write configuration files in /etc/backup.d admingroup = root diff --git a/man/backupninja.conf.5 b/man/backupninja.conf.5 index 72de35af9532a7d7b96b4eb92bb9adec8356076f..b4f56023dabd92a611a7dbde53d03ae856c45639 100644 --- a/man/backupninja.conf.5 +++ b/man/backupninja.conf.5 @@ -54,6 +54,10 @@ If set to 'yes', a report email will be generated even if all modules reported s .B reportwarning If set to 'yes', a report email will be generated even if there was no error. +.TP +.B reportwrap +Number of columns the email report body should wrap to. + .TP .B logfile The path of the logfile. @@ -107,6 +111,8 @@ reportsuccess = yes .br reportwarning = yes .br +reportwrap = 1000 +.br logfile = /var/log/backupninja.log .br configdirectory = /etc/backup.d diff --git a/src/backupninja.in b/src/backupninja.in index c8ba5d4883fac5aa2436139842fb737b26f83463..635d12749c050e79f1d71d20a1fbc424a5dea21b 100755 --- a/src/backupninja.in +++ b/src/backupninja.in @@ -543,6 +543,7 @@ getconf RSYNC /usr/bin/rsync getconf DSYNC /usr/bin/dsync getconf DOVEADM /usr/bin/doveadm getconf admingroup root +getconf reportwrap 1000 if [ ! -d "$configdirectory" ]; then echo "Configuration directory '$configdirectory' not found." @@ -636,7 +637,7 @@ if [ $doit == 1 ]; then fi done fi - } | mail -s "backupninja: $hostname $subject" $reportemail + } | fold -s -w "$reportwrap" | mail -s "backupninja: $hostname $subject" $reportemail else error "Unable to locate mail executable, email report not sent!" let "errors += 1" diff --git a/test/backupninja.bats b/test/backupninja.bats index 7d66150c52769f183f2dc2702703a15c45e94cf3..083beaec167eedd34edb9c2c2081b4383d39655d 100644 --- a/test/backupninja.bats +++ b/test/backupninja.bats @@ -128,7 +128,25 @@ create_test_action() { mv /usr/bin/mail /usr/bin/mail.moved run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh" [ "$status" -eq 1 ] - false +} + +@test "reports: wraps report text to 1000 columns by default" { + create_test_action info "$(printf \'=%.0s\' {1..2000})" + setconfig backupninja.conf reportsuccess yes + setconfig backupninja.conf reportinfo yes + run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh" + sleep 0.1 + grep -q '^=\{1000\}$' /var/mail/vagrant +} + +@test "reports: wraps report text according to reportwrap" { + create_test_action info "$(printf \'=%.0s\' {1..2000})" + setconfig backupninja.conf reportsuccess yes + setconfig backupninja.conf reportinfo yes + setconfig backupninja.conf reportwrap 100 + run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh" + sleep 0.1 + grep -q '^=\{100\}$' /var/mail/vagrant } @test "scheduling: runs when = 'everyday at 01' and time matches" {