Icinga automated Mail

Hello, i set everything up so that i receive Emails, but only when i trigger them over the IcingaWeb.
But if I set up a Host, connect it and cut it from the network, Icinga registered it but it doesnt send an email.
This is the users.conf

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

  display_name = "Icinga 2 Admin"
  groups = [ "icingaadmins" ]

  email = "root@localhost"
}

object User "kaemper" {
  display_name = "Julius Kaemper"
  email = "this is the correct email"
  groups = [ "icingaadmins" ]
}

object UserGroup "icingaadmins" {
  display_name = "Icinga 2 Admin Group"
}

This is notifications.conf

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
}

This is commands.conf

object NotificationCommand "mail-host-notification" {
  command = [ ConfigDir + "/scripts/mail-host-notification.sh" ]

  arguments += {
    "-4" = "$notification_address$"
    "-6" = "$notification_address6$"
    "-b" = "$notification_author$"
    "-c" = "$notification_comment$"
    "-d" = {
      required = true
      value = "$notification_date$"
    }
    "-f" = {
      value = "$notification_from$"
      description = "Set from address. Requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SU>
    }
    "-i" = "$notification_icingaweb2url$"
    "-l" = {
      required = true
      value = "$notification_hostname$"
    }
    "-n" = {
      required = true
      value = "$notification_hostdisplayname$"
    }
    "-o" = {
      required = true
      value = "$notification_hostoutput$"
    }
    "-r" = {
      required = true
      value = "$notification_useremail$"
    }
    "-s" = {
      required = true
      value = "$notification_hoststate$"
    }
    "-X" = "$notification_hostnotes$"

This is templates.conf

template Host "generic-host" {
  max_check_attempts = 3
  check_interval = 1m
  retry_interval = 30s

  check_command = "hostalive"
}

/**
 * Provides default settings for services. By convention
 * all services should import this template.
*/
template Service "generic-service" {
  max_check_attempts = 5
  check_interval = 1m
  retry_interval = 30s
}

/**
 * Provides default settings for users. By convention
 * all users should inherit from this template.
*/

template User "generic-user" {

}

/**
 * Provides default settings for host notifications.
 * By convention all host notifications should import
 * this template.
*/
template Notification "mail-host-notification" {
  command = "mail-host-notification"

  states = [ Up, Down ]
  types = [ Problem, Acknowledgement, Recovery, Custom,
            FlappingStart, FlappingEnd,
            DowntimeStart, DowntimeEnd, DowntimeRemoved ]

 vars += {
    // notification_icingaweb2url = "https://www.example.com/icingaweb2"
    // notification_from = "Icinga 2 Host Monitoring <icinga@example.com>"
    notification_logtosyslog = false
  }

  period = "24x7"
}

/*
 * Provides default settings for service notifications.
 * By convention all service notifications should import
 * this template.
*/
template Notification "mail-service-notification" {
  command = "mail-service-notification"

  states = [ OK, Warning, Critical, Unknown ]
  types = [ Problem, Acknowledgement, Recovery, Custom,
                 FlappingStart, FlappingEnd,
                 DowntimeStart, DowntimeEnd, DowntimeRemoved ]

  vars += {
    // notification_icingaweb2url = "https://www.example.com/icingaweb2"
    // notification_from = "Icinga 2 Service Monitoring <icinga@example.com>"
    notification_logtosyslog = false
  }

  period = "24x7"

}

I appreciate some help, if you have any questions let me know!

did you wait long enough for all the retries so the host is actually in a hard state?

You can see this in the history of the service or hostobject in icingaweb2

Hello thank you for your advice!
Yes i checked again. It is in Hard State rn and i dont get a notification.

I used How to configure notifications in Icinga2 Director | Andreas ‘ads’ Scherbaum
this tutorial and it worked!

1 Like