E-Mail Notification Setup

Hello everyone,
I‘m really new to icinga (and tech stuff in general) and I‘m struggling to understand how notifications work. I‘ve read the docs, yes, but everything is a little bit confusing to me.

What I understood so far:

  • I need to install and setup postfix first (icinga is running on an Ubuntu server)
  • There should be an user and group object, for example like this:
object User “icingaadmin“ {
   import „generic-user“
   display_name = “Icinga Admin“
   groups = [“icingaadmins”]
   enable_notifications = true
   states = [Warning, Critical]
   types = [Recovery, Problem]
   email = “test@icinga.com“
}
object UserGroup “icingaadmins” {
   display_name = “Icinga Admin Group”
}
  • I need notification objects for hosts and services (I think I will use the default objects):
apply Notification "mail-icingaadmin" to Host {
  import "mail-host-notification"
  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  //interval = 2h

  //vars.notification_logtosyslog = true

  assign where host.vars.notification.mail
}

apply Notification "mail-icingaadmin" to Service {
  import "mail-service-notification"
  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  //interval = 2h

  //vars.notification_logtosyslog = true

  assign where host.vars.notification.mail
}
  • user and groups need to be specified on every host object for example like this:
object Host “icinga2-agent.localdomain” {
   import “generic-host”
   address = “000.000.000”
   vars.os = “Linux”
   vars.agent_endpoint = name
   vars.notification[“mail”] = {
   groups = [ “icingaadmins” ]
   users = [ “icingaadmin” ]
   }
}

Am I missing something out?

Looking forward to any suggestions!

No - you can use Notification apply rules:

https://icinga.com/docs/icinga-2/latest/doc/03-monitoring-basics/#apply-rules

@bberg I think you may have misread some of the question.
The configuration provided by @vplm already contains apply rules.
I think the question is whether or not each host must contain the custom variable noticification.mail with the users and/or groups values.

Strictly speaking, the answer in your current setup is “yes”, but what you probably want to do is to put the

   vars.notification[“mail”] = {
   groups = [ “icingaadmins” ]
   users = [ “icingaadmin” ]
   }

part in the generic-host object (there should be some line like template Host "generic-host" somewhere).
This way, every Host object which imports the generic-host has these values already set (but could overwrite them).

Regarding postfix etc.:
The default mail scripts (in /etc/icinga2/scripts for some reason) rely on the mail command, which again relies on some weird old school email magic.
You can use Postfix for that (and it works and probably would be my recommendation IF you can send mails internally in your setup via SMTP).

The tricky part is to configure Postfix “correctly”, most of the time the “local Postfix is just a relay/satellite and forwards everything to a proper mail server” configuration is what you want (but I don’t know your setup).

Now, you don’t have to use the default scripts, effectively icinga2 just executes some executable with some parameters (which contain the message content), so you could use other channels to communicate problems (XMPP/Matrix/Telegram/…) as long as you find a fitting program to do that (search for “icinga notification XMPP” or something like that).

I hope this helps, feel free to ask more if not.

Sorry for the late answer. Thanks for your help, it worked!