Mail notification with high priority

For some of the critical hosts I would like to send the mail notification with high priority when the host is down/up. Need some help to configure this. After some research I found that /etc/icinga2/scripts/mail-host-notification.sh needs to be modified but not sure what/where to change.

Also, I am thinking about assigning a custom variable to these critical hosts and apply a notification apply rule but could not find such assignment filter. So the issue is how to send notification emails with high priority to certain critical hosts.

ICINGA version: r2.10.5-1
Director version: 1.6.2

If you need the high priority flag only for specific hosts, then you have to add a custom variable to these hosts. You also have to change the notification script in a way that it takes the variable as additional parameter and sets the mail priority in desired way. Further add the additional parameter into Icinga’s command definition - can be done by cloning the default host mail notification command and add the new parameter to the clone, use the clone command for notifications. Another way is to use different scripts for notification - one with normal prio and one with high prio - and apply the notfication scripts appropriate.

Depending on your OS and mail tool you have add the needed mail headers for priority tagging.
I.e. with Linux and mailx with -a support use the form -a "X-Priority:1"

Common used headers:

Importance: high
X-Priority: 1 (Highest)
X-MSMail-Priority: High

1 Like

Thanks Manfred.

I have tested by modifying the default host mail notification (etc/icinga2/scripts/mail-host-notification.sh) as highlighted below and sending custom notification but the email is being received with normal priority.

Could you please advise?

Different email clients need different headers, try out different headers or add all of them. Check within your email client if the header is present - maybe the are filtered out by upstream mail relays or security devices.
Tests with mailx can be done directly from shell :wink:

Thanks Manfred.

I have done all of the settings but struggling with change in notification script. I am using Linux 7 and Mailx and the notification script is as below which is giving syntax error.

SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!" “X-Priority: 1 (Highest)”

I tried the below from console and I can receive the email with high priority.

mailx -v -s$(echo -e “This is a subject v4\nContent-Type: text/html\nX-Priority: 1 (Highest)”)" 1 test@abc.com

-a parameter is asking for the input file. Could you please advise the exact parameter to be added to the list. I can share the complete notification file if you require it.

Thanks.

I’ve found this info on the internet as workaround for mailx which does not support parameter -a, but I’m not shure if this really works. Seems that it depends on the linux distibution and the used mailx version.
Adding the header to subject line will not work (syntax error came from assigning 2 strings without concatenation to one variable).

Just try commands without (shell) variables like this:
echo "My message..." | mailx -s "My Subject" -a "X-Priority:1" my@mail.address

Alternative switch to sendmail command, but IMHO this requires to prepare the complete mail header.

Thanks Manfred.

After spending several hours the issue has been resolved as below.
SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!"

SUB="\nX-Priority: 1"
SUBJECT1="$(echo -e $SUBJECT $SUB)"

/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | $MAILBIN -a “From: $MAILFROM” -s “$SUBJECT1” $USEREMAIL