add reportwrap config parameter

set to wrap at 1000 columns by default to avoid MTA rejection allowed by
SMTP RFC2821
This commit is contained in:
Jerome Charaoui 2021-01-23 22:50:15 -05:00
parent 76b457cc4d
commit ede337dbcd
5 changed files with 35 additions and 2 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- [core] implement reportwrap configuration parameter
### Changed ### Changed
- [core] raise error if mail isn't found in $PATH and reportemail = yes - [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) - [build] make build reproducible regardless of usrmerge (DEBBUG-915222)
- [core] silence exit code message unless --debug is used - [core] silence exit code message unless --debug is used
- [core] backup halt should trigger email report if enabled - [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 ## [1.2.0] - 2021-01-21

View File

@ -46,6 +46,9 @@ reportuser = ninja
# use a globally unique name, preferably the hostname # use a globally unique name, preferably the hostname
reportdirectory = /var/lib/backupninja/reports 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 # set to the administration group that is allowed to
# read/write configuration files in /etc/backup.d # read/write configuration files in /etc/backup.d
admingroup = root admingroup = root

View File

@ -54,6 +54,10 @@ If set to 'yes', a report email will be generated even if all modules reported s
.B reportwarning .B reportwarning
If set to 'yes', a report email will be generated even if there was no error. 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 .TP
.B logfile .B logfile
The path of the logfile. The path of the logfile.
@ -107,6 +111,8 @@ reportsuccess = yes
.br .br
reportwarning = yes reportwarning = yes
.br .br
reportwrap = 1000
.br
logfile = /var/log/backupninja.log logfile = /var/log/backupninja.log
.br .br
configdirectory = /etc/backup.d configdirectory = /etc/backup.d

View File

@ -543,6 +543,7 @@ getconf RSYNC /usr/bin/rsync
getconf DSYNC /usr/bin/dsync getconf DSYNC /usr/bin/dsync
getconf DOVEADM /usr/bin/doveadm getconf DOVEADM /usr/bin/doveadm
getconf admingroup root getconf admingroup root
getconf reportwrap 1000
if [ ! -d "$configdirectory" ]; then if [ ! -d "$configdirectory" ]; then
echo "Configuration directory '$configdirectory' not found." echo "Configuration directory '$configdirectory' not found."
@ -636,7 +637,7 @@ if [ $doit == 1 ]; then
fi fi
done done
fi fi
} | mail -s "backupninja: $hostname $subject" $reportemail } | fold -s -w "$reportwrap" | mail -s "backupninja: $hostname $subject" $reportemail
else else
error "Unable to locate mail executable, email report not sent!" error "Unable to locate mail executable, email report not sent!"
let "errors += 1" let "errors += 1"

View File

@ -128,7 +128,25 @@ create_test_action() {
mv /usr/bin/mail /usr/bin/mail.moved mv /usr/bin/mail /usr/bin/mail.moved
run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh" run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
[ "$status" -eq 1 ] [ "$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" { @test "scheduling: runs when = 'everyday at 01' and time matches" {