Skip to content

Commit

Permalink
Issue #59 - New Feature: Enable/Disable mail notification
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascbeyeler committed Apr 7, 2018
1 parent 1c433a6 commit a1a7a46
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 37 deletions.
11 changes: 11 additions & 0 deletions project/config/zmbackup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ LDAPPASS={OSE_INSTALL_LDAPPASS}

LOGFILE=/opt/zimbra/log/zmbackup.log

# ENABLE_EMAIL_NOTIFY - Enable or disable mail notification during a backup routine.
# OPTIONS:
# - all: Enable all the mail notification
# - start: Enable only the start mail notification
# - finish: Enable only the finish mail notification
# - error: Enable only for error messages
# - none: Disable mail notification
# DEFAULT: all

ENABLE_EMAIL_NOTIFY=all

# EMAIL_NOTIFY - After each zmbackup execution, going everything okay or not, a mail
# is sended to someone to inform that the process is concluded, and
# show a report of each account backed up.
Expand Down
2 changes: 1 addition & 1 deletion project/lib/bash/MiscAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function on_exit(){
if [[ $ERRCODE -eq 1 ]]; then
notify_finish $SESSION $STYPE "FAILURE"
elif [[ $ERRCODE -eq 0 && ! -z $SESSION ]]; then
notify_finish $SESSION $STYPE "SUCCESS"
notify_finish $SESSION "$STYPE" "SUCCESS"
fi
fi
rm -rf $TEMPSESSION $TEMPACCOUNT $TEMPINCACCOUNT $TEMPDIR $MESSAGE $TEMPSQL $FAILURE
Expand Down
77 changes: 41 additions & 36 deletions project/lib/bash/NotifyAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
################################################################################
function notify_begin()
{
printf "Subject: Zmbackup - Backup routine for $1 start at $(date)" > $MESSAGE
printf "\nGreetings Administrator," >> $MESSAGE
printf "\n\nThis is an automatic message to inform you that the process for $2 BACKUP that you scheduled started right now." >> $MESSAGE
printf " Depending on the ammount of accounts and/or data to be backed up, this process can take some hours before conclude." >> $MESSAGE
printf "\nDon't worry, we will inform you when the process finish." >> $MESSAGE
printf "\n\nRegards," >> $MESSAGE
printf "\nZmbackup Team" >> $MESSAGE
sendmail $EMAIL_NOTIFY < $MESSAGE
if [[ $? -eq 0 ]]; then
logger -i -p local7.info "Zmbackup: Mail sended to $EMAIL_NOTIFY to notify about the backup routine begin."
else
logger -i -p local7.info "Zmbackup: Cannot send mail for $EMAIL_NOTIFY - $ERR."
if [[ "$ENABLE_EMAIL_NOTIFY" == "all" || "$ENABLE_EMAIL_NOTIFY" == "start" ]]; then
printf "Subject: Zmbackup - Backup routine for $1 start at $(date)" > $MESSAGE
printf "\nGreetings Administrator," >> $MESSAGE
printf "\n\nThis is an automatic message to inform you that the process for $2 BACKUP that you scheduled started right now." >> $MESSAGE
printf " Depending on the ammount of accounts and/or data to be backed up, this process can take some hours before conclude." >> $MESSAGE
printf "\nDon't worry, we will inform you when the process finish." >> $MESSAGE
printf "\n\nRegards," >> $MESSAGE
printf "\nZmbackup Team" >> $MESSAGE
sendmail $EMAIL_NOTIFY < $MESSAGE
if [[ $? -eq 0 ]]; then
logger -i -p local7.info "Zmbackup: Mail sended to $EMAIL_NOTIFY to notify about the backup routine begin."
else
logger -i -p local7.info "Zmbackup: Cannot send mail for $EMAIL_NOTIFY - $ERR."
fi
fi
}

Expand All @@ -39,30 +41,33 @@ function notify_begin()
################################################################################
function notify_finish()
{
# Loading the variables
SIZE=$(du -h $WORKDIR/$1 | awk {'print $1'})
if [[ "$1" == "mbox"* ]]; then
QTDE=$(ls $WORKDIR/$1/*.tgz | wc -l)
else
QTDE=$(ls $WORKDIR/$1/*.ldiff | wc -l)
fi
if [[ "$ENABLE_EMAIL_NOTIFY" == "all" ]] || [[ "$ENABLE_EMAIL_NOTIFY" == "finish" && "$3" == "SUCCESS" ]] || [[ "$ENABLE_EMAIL_NOTIFY" == "error" && "$3" == "FAILURE" ]] ; then

# Loading the variables
SIZE=$(du -h $WORKDIR/$1 | awk {'print $1'})
if [[ "$1" == "mbox"* ]]; then
QTDE=$(ls $WORKDIR/$1/*.tgz | wc -l)
else
QTDE=$(ls $WORKDIR/$1/*.ldiff | wc -l)
fi

# The message
printf "Subject: Zmbackup - Backup routine for $1 complete at $(date) - $3" > $MESSAGE
printf "\nGreetings Administrator," >> $MESSAGE
printf "\n\nThis is an automatic message to inform you that the process for $2 BACKUP that you scheduled ended right now." >> $MESSAGE
printf "\nHere some information about this session:" >> $MESSAGE
printf "\n\nSize: $SIZE" >> $MESSAGE
printf "\nAccounts: $QTDE" >> $MESSAGE
printf "\nStatus: $3" >> $MESSAGE
printf "\n\nRegards," >> $MESSAGE
printf "\nZmbackup Team" >> $MESSAGE
printf "\n\nSummary of files:\n" >> $MESSAGE
cat $TEMPSESSION >> $MESSAGE
ERR=$((sendmail $EMAIL_NOTIFY < $MESSAGE ) 2>&1)
if [[ $? -eq 0 ]]; then
logger -i -p local7.info "Zmbackup: Mail sended to $EMAIL_NOTIFY to notify about the backup routine conclusion."
else
logger -i -p local7.info "Zmbackup: Cannot send mail for $EMAIL_NOTIFY - $ERR."
# The message
printf "Subject: Zmbackup - Backup routine for $1 complete at $(date) - $3" > $MESSAGE
printf "\nGreetings Administrator," >> $MESSAGE
printf "\n\nThis is an automatic message to inform you that the process for $2 BACKUP that you scheduled ended right now." >> $MESSAGE
printf "\nHere some information about this session:" >> $MESSAGE
printf "\n\nSize: $SIZE" >> $MESSAGE
printf "\nAccounts: $QTDE" >> $MESSAGE
printf "\nStatus: $3" >> $MESSAGE
printf "\n\nRegards," >> $MESSAGE
printf "\nZmbackup Team" >> $MESSAGE
printf "\n\nSummary of files:\n" >> $MESSAGE
cat $TEMPSESSION >> $MESSAGE
ERR=$((sendmail $EMAIL_NOTIFY < $MESSAGE ) 2>&1)
if [[ $? -eq 0 ]]; then
logger -i -p local7.info "Zmbackup: Mail sended to $EMAIL_NOTIFY to notify about the backup routine conclusion."
else
logger -i -p local7.info "Zmbackup: Cannot send mail for $EMAIL_NOTIFY - $ERR."
fi
fi
}

0 comments on commit a1a7a46

Please sign in to comment.