Configure Mail Notification with icinga2

Configuring Mail Notification in Icinga2 is very easy.
We will use third party SMTP to send email notifications using thirdparty tool “sendEmail.pl”.
sendEmail.pl is Perl script which send email to mailserver to send email.

/etc/icinga2/scripts/mail-service-notification.sh : This script actually does work of sending emails. By default it uses inbuild “mail” utility.

/etc/icinga2/users.conf: This conf file has user and group information stored in it.

– Download : sendEmail from http://caspian.dotconf.net/menu/Software/SendEmail/
Create directory “sendEmail” under /opt
Extract it and move sendEmail and sendEmail.pl it under /opt/sendEmail/

– Open /etc/icinga2/scripts/mail-service-notification.sh
Comment mail command line and add below command line to it:


/usr/bin/printf "%b" "$template" | /opt/sendemail/sendEmail.pl -f <From Email address> -t $USEREMAIL -u "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME - $SERVICEDISPLAYNAME is $SERVICESTATE" -s <SMTP Server:Port> -xu <username@domain> -xp <Password>

– Add below lines to your host configuration

vars.notification["mail"] = {
groups = [ "GroupName" ]
}

– Add User defination to /etc/icinga2/users.conf

object User "UserName" {
import "generic-user"

display_name = "Display User Name"
groups = [ "GroupName" ]

email = "<email address to which you want to get notified>"
}

object UserGroup "GroupName" {
display_name = "<Group Display Name>"
}

– Reload icinga2

/etc/init.d/icinga2 reload

 

Neelesh Gurjar has written 122 articles

4 thoughts on “Configure Mail Notification with icinga2

  1. /usr/bin/printf “%b” “$template” | /opt/sendemail/sendEmail.pl -f -t $USEREMAIL -u “$NOTIFICATIONTYPE – $HOSTDISPLAYNAME – $SERVICEDISPLAYNAME is $SERVICESTATE” -s -xu -xp

    here, for , and should I fill these? If so give me an example please.

  2. Pradeep says:

    Hi, i am trying this with Icinga2 and AWS SES. which is not working, is anyone has done similar setup? If so please let me know how to do that. Thanks in advance.

Leave a Reply to Jonha Cancel reply