Allow for disabling reports by email.

This diff simply adds one line:

`if [ ! -z "$reportemail" ]; then` and then it indents the if block and adds a
final `fi`.

This check used to be there, without it, its not possible to disable report
mails, which might be something desirable if you are getting alerts through the
prometheus method.
This commit is contained in:
Micah Anderson 2021-06-24 10:40:01 -04:00
parent fa2528a083
commit 8f81c85274
No known key found for this signature in database
GPG Key ID: 2D2C65DDB27446E5

View File

@ -661,36 +661,37 @@ EOF
let "errors +-1" let "errors +-1"
fi fi
fi fi
if [ -x "$(which mail 2>/dev/null)" ]; then if [ ! -z "$reportemail" ]; then
debug "send report to $reportemail" if [ -x "$(which mail 2>/dev/null)" ]; then
hostname=`hostname` debug "send report to $reportemail"
[ $warnings == 0 ] || subject="WARNING" hostname=`hostname`
[ $errors == 0 ] || subject="ERROR" [ $warnings == 0 ] || subject="WARNING"
[ $fatals == 0 ] || subject="FAILED" [ $errors == 0 ] || subject="ERROR"
[ $halts == 0 ] || subject="HALTED" [ $fatals == 0 ] || subject="FAILED"
[ $halts == 0 ] || subject="HALTED"
{ {
for ((i=0; i < ${#messages[@]} ; i++)); do for ((i=0; i < ${#messages[@]} ; i++)); do
echo ${messages[$i]} echo ${messages[$i]}
done
echo -e "$errormsg"
if [ "$reportspace" == "yes" ]; then
previous=""
for i in $(ls "$configdirectory"); do
backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}')
if [ "$backuploc" != "$previous" -a -n "$backuploc" -a -d "$backuploc" ]; then
df -h "$backuploc"
previous="$backuploc"
fi
done done
fi echo -e "$errormsg"
} | fold -s -w "$reportwrap" | mail -s "backupninja: $hostname $subject" $reportemail if [ "$reportspace" == "yes" ]; then
else previous=""
error "Unable to locate mail executable, email report not sent!" for i in $(ls "$configdirectory"); do
let "errors += 1" backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}')
if [ "$backuploc" != "$previous" -a -n "$backuploc" -a -d "$backuploc" ]; then
df -h "$backuploc"
previous="$backuploc"
fi
done
fi
} | fold -s -w "$reportwrap" | mail -s "backupninja: $hostname $subject" $reportemail
else
error "Unable to locate mail executable, email report not sent!"
let "errors += 1"
fi
fi fi
fi fi
if [ $actions_run != 0 ]; then if [ $actions_run != 0 ]; then
info "FINISHED: $actions_run actions run. $fatals fatal. $errors error. $warnings warning." info "FINISHED: $actions_run actions run. $fatals fatal. $errors error. $warnings warning."
if [ "$halts" != "0" ]; then if [ "$halts" != "0" ]; then