Notifications with Icinga2
Now that I’ve set up Icinga2 and Icingaweb2 using the guide here, I wanted to get notifications working as I don’t want to be sitting looking at a dashboard all day long!
On previous installations (icinga v1), I had installed ssmtp to send emails from a specific email address. This time around, I thought I’d just try and send email directly from server without any SMTP. It turns out it’s really easy!
Testing the mail service
If you check the mail-service-notification.sh or mail-host-notification.sh file in your icinga2 scripts directory (/etc/icinga2/scripts), you can see that it’s just using the plain old mail command to send emails:
template=`cat < < TEMPLATE ***** Icinga ***** Notification Type: $NOTIFICATIONTYPE Host: $HOSTALIAS Address: $HOSTADDRESS State: $HOSTSTATE Date/Time: $LONGDATETIME Additional Info: $HOSTOUTPUT Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT TEMPLATE ` /usr/bin/printf "%b" "$template" | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME is $HOSTSTATE" $USEREMAIL
You can try sending an email directly from the command line.
mail firstname.lastname@example.orgSubject: test testing . Cc:
If you don’t see any emails coming through, check the mail log (/var/log/mail.log) and look for any errors. If it looks like it sent ok, make sure the email hasn’t been caught by your spam filter (The test email above got caught by mine, maybe try putting something more meaningful in your test email…)
Once you’re sure that mail is configured correctly on your server, all you need to do is make sure that the email address is correctly set for each user in your user config file (/etc/icinga2/conf.d/user.conf). Once that’s done, Icinga2 will send out notifications to any email address specified for the Icinga Admins group out of the box. You can customise away to your hearts content using the docs as a guide.