Skip to content

Commit

Permalink
Strip '\r' in notification messages to avoid 'Content-Type: applicati…
Browse files Browse the repository at this point in the history
…on/octet-stream'

Without this patch, an accidential `\r` in e.g. `$NOTIFICATIONCOMMENT`
leads to a `Content-Type: application/octet-stream` header in e-mails.
The accidential `\r` might slip in usually using Icinga/Nagios apps...
  • Loading branch information
robert-scheck authored and Al2Klimov committed May 15, 2024
1 parent cb945fe commit 90d08fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions etc/icinga2/scripts/mail-host-notification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ if [ -n "$MAILFROM" ] ; then

## Debian/Ubuntu use mailutils which requires `-a` to append the header
if [ -f /etc/debian_version ]; then
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' \
| $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL
## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r`
else
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' \
| $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL
fi

else
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' \
| $MAILBIN -s "$SUBJECT" $USEREMAIL
fi
8 changes: 5 additions & 3 deletions etc/icinga2/scripts/mail-service-notification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ if [ -n "$MAILFROM" ] ; then

## Debian/Ubuntu use mailutils which requires `-a` to append the header
if [ -f /etc/debian_version ]; then
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' \
| $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL
## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r`
else
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' \
| $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL
fi

else
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | tr -d '\015' \
| $MAILBIN -s "$SUBJECT" $USEREMAIL
fi

0 comments on commit 90d08fa

Please sign in to comment.