Fixed bogus double log alert sending

This commit is contained in:
deajan 2016-08-26 12:09:22 +02:00
parent cfd76c0c4c
commit 2c55108ba6
1 changed files with 10 additions and 9 deletions

View File

@ -1,6 +1,6 @@
#### MINIMAL-FUNCTION-SET BEGIN ####
## FUNC_BUILD=2016082601
## FUNC_BUILD=2016082602
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -227,6 +227,7 @@ function SendAlert {
local mail_no_attachment=
local attachment_command=
local subject=
local body=
# Windows specific settings
local encryption_string=
@ -256,7 +257,7 @@ function SendAlert {
mail_no_attachment=0
fi
#TODO(low): Change tail -n 50 to end of fil up to last script begin
MAIL_ALERT_MSG="$MAIL_ALERT_MSG"$'\n\n'$(tail -n 50 "$LOG_FILE")
body="$MAIL_ALERT_MSG"$'\n\n'$(tail -n 50 "$LOG_FILE")
if [ $ERROR_ALERT -eq 1 ]; then
subject="Error alert for $INSTANCE_ID"
elif [ $WARN_ALERT -eq 1 ]; then
@ -275,7 +276,7 @@ function SendAlert {
attachment_command="-a $ALERT_LOG_FILE"
fi
if type mutt > /dev/null 2>&1 ; then
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
echo "$body" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
if [ $? != 0 ]; then
Logger "Cannot send alert mail via $(type -p mutt) !!!" "WARN"
else
@ -292,10 +293,10 @@ function SendAlert {
else
attachment_command=""
fi
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
echo "$body" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
if [ $? != 0 ]; then
Logger "Cannot send alert mail via $(type -p mail) with attachments !!!" "WARN"
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
echo "$body" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
if [ $? != 0 ]; then
Logger "Cannot send alert mail via $(type -p mail) without attachments !!!" "WARN"
else
@ -309,7 +310,7 @@ function SendAlert {
fi
if type sendmail > /dev/null 2>&1 ; then
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
echo -e "Subject:$subject\r\n$body" | $(type -p sendmail) $DESTINATION_MAILS
if [ $? != 0 ]; then
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
else
@ -332,7 +333,7 @@ function SendAlert {
if [ "$SMTP_USER" != "" ] && [ "$SMTP_USER" != "" ]; then
auth_string="-auth -user \"$SMTP_USER\" -pass \"$SMTP_PASSWORD\""
fi
$(type mailsend.exe) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -sub "$subject" -M "$MAIL_ALERT_MSG" -attach "$attachment" -smtp "$SMTP_SERVER" -port "$SMTP_PORT" $encryption_string $auth_string
$(type mailsend.exe) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -sub "$subject" -M "$body" -attach "$attachment" -smtp "$SMTP_SERVER" -port "$SMTP_PORT" $encryption_string $auth_string
if [ $? != 0 ]; then
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
else
@ -348,7 +349,7 @@ function SendAlert {
else
SMTP_OPTIONS=""
fi
$(type -p sendemail) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
$(type -p sendemail) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -u "$subject" -m "$body" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
if [ $? != 0 ]; then
Logger "Cannot send alert mail via $(type -p sendemail) !!!" "WARN"
else
@ -359,7 +360,7 @@ function SendAlert {
# pfSense specific
if [ -f /usr/local/bin/mail.php ]; then
echo "$MAIL_ALERT_MSG" | /usr/local/bin/mail.php -s="$subject"
echo "$body" | /usr/local/bin/mail.php -s="$subject"
if [ $? != 0 ]; then
Logger "Cannot send alert mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
else