Make backup report hostname configurable
This commit is contained in:
1 parent
99da6460d2
commit
64eab1d3c2
7 files changed
+121
-7
No files matched your search
+2
-1
@@ -37,6 +37,7 @@ load_config() {
|
||||
: "${RCLONE_BWLIMIT:=0}" "${ENABLE_MAIL_REPORT:=true}" "${MAIL_TO:=johannes}"
|
||||
# Keep the old report settings; an empty sender uses app-backup@<FQDN>.
|
||||
: "${MAIL_FROM:=}" "${MAIL_SUBJECT_PREFIX:=[app-backup]}" "${MAIL_INCLUDE_LOG_TAIL_LINES:=200}"
|
||||
: "${MAIL_HOSTNAME:=}"
|
||||
: "${MAIL_SENDMAIL_BIN:=/usr/sbin/sendmail}" "${MAIL_SEND_TIMEOUT:=30}"
|
||||
: "${ENABLE_WORDPRESS:=false}" "${ENABLE_NEXTCLOUD:=false}" "${ENABLE_NEXTCLOUD_DATA:=true}"
|
||||
: "${ENABLE_GITEA:=false}" "${ENABLE_MAIL:=false}" "${ENABLE_DB_DUMPS:=true}"
|
||||
@@ -513,7 +514,7 @@ finish() {
|
||||
if [[ ${CHECK:-false} != true && $ENABLE_MAIL_REPORT == true && $OPERATION == backup ]]; then
|
||||
python3 "$LIB_DIR/report.py" deliver --sizes "$report_sizes" --log "$LOG_FILE" \
|
||||
--output "$LOG_DIR/report_$RUN_ID.eml" --to "$MAIL_TO" --sender "$MAIL_FROM" \
|
||||
--subject-prefix "$MAIL_SUBJECT_PREFIX" --run "$RUN_ID" --exit-code "$code" \
|
||||
--hostname="$MAIL_HOSTNAME" --subject-prefix "$MAIL_SUBJECT_PREFIX" --run "$RUN_ID" --exit-code "$code" \
|
||||
--started "$RUN_STARTED_EPOCH" --phase "$BACKUP_PHASE" --upload-status "$UPLOAD_STATUS" \
|
||||
--config "$CONFIG_FILE" --workdir "$WORKDIR" --archive-dir "$ARCHIVE_DIR" \
|
||||
--compression "$COMPRESSOR" --remote "$RCLONE_REMOTE_BASE" --sendmail "$MAIL_SENDMAIL_BIN" \
|
||||
|
||||
+4
-2
@@ -50,7 +50,8 @@ def human(value):
|
||||
|
||||
|
||||
def deliver(args):
|
||||
host = socket.getfqdn()
|
||||
fqdn = socket.getfqdn()
|
||||
host = args.hostname or fqdn
|
||||
now = dt.datetime.now().astimezone()
|
||||
state = 'SUCCESS' if args.exit_code == 0 else 'FAIL'
|
||||
try:
|
||||
@@ -89,7 +90,7 @@ def deliver(args):
|
||||
body.extend(['', f'Log-Auszug (letzte {args.tail_lines} Zeilen)', '-----------------', tail])
|
||||
message = EmailMessage(policy=SMTP)
|
||||
# EmailMessage rejects CR/LF in headers and encodes non-ASCII safely.
|
||||
sender = args.sender or f'app-backup@{host}'
|
||||
sender = args.sender or f'app-backup@{fqdn}'
|
||||
if not args.to.strip() or not sender.strip():
|
||||
raise ValueError('Mail recipient and sender must not be empty')
|
||||
message['From'] = sender
|
||||
@@ -112,6 +113,7 @@ def main():
|
||||
for name in ('output', 'staging', 'archives'):
|
||||
snap.add_argument(name)
|
||||
mail = commands.add_parser('deliver')
|
||||
mail.add_argument('--hostname', default='')
|
||||
for name in ('sizes', 'log', 'output', 'to', 'sender', 'subject-prefix', 'run', 'phase',
|
||||
'upload-status', 'config', 'workdir', 'archive-dir', 'compression', 'remote', 'sendmail'):
|
||||
mail.add_argument('--'+name, required=True)
|
||||
|
||||
Reference in new issue
Block a user