Send notifications only when the state of a service changes

Hello everyone.
I would like to be notified when a service changes state. I did some research and saw that notifications don’t apply to services but to hosts. I use icingadb for monitoring so the configurations are done directly in the files. Maybe I did my research wrong, but I would like to know if it’s possible.

Monitoring without service notification would not make much sense. Of course icinga can send state changes of any service. You need to define some notification objects using apply Notification "..." to Service

I’m new to icinga so i use the default notification object with apply Notification "..." to service. The documentation is sometimes difficult to understand. This is the notification object that i created

apply Notification "mail-service-notification-specific-service" to Service {
  import "mail-service-notification"
  user_groups = host.vars.notification.mail.groups
  assign where service.name == "ping4"
}

and the service

apply Service "ping4" {
  import "generic-service"
  check_command = "ping4"
  check_interval = 5m
  retry_interval = 10m
  vars.ping_crta = "600000"
  vars.ping_wpl = "100"
  vars.ping_wrta = "300000"
  vars.ping_cpl = "100"
  vars.notification["mail"] = {
    groups = ["icingaadmins"]
  }
  assign where host.address
}

I just want to be warned when a specific host is offline for more than 5 minutes and if it is offline for more than 10 minutes, i get a critical notification.

If my explanation is not clear, please tell me.

Please check States to understand when you will get notifications.

Your definition defines check_interval as 5min and retry_interval as 10min. If your’re using the default generic-service than max_check_attempts is 5. With that you’ll get informed in 40 - 45min after the host went offline:

  • 0 - 5 min for the first execution, turns into soft state and check_attempt is 1/5
  • 10min for first retry and check_attempt is 2/5
  • 10min for second retry and check_attempt is 3/5
  • 10min for third retry and check_attempt is 4/5
  • 10min for fourth retry and check_attempt is 5/5, turns into hard state and notification is triggered
1 Like

I made some changes. This is what the host look like

object Host "redcapserver" {
  check_command = "hostalive" //check is executed on the master
  address = "192.168.5.21"
  vars.ping_crta = "600000"
  vars.ping_wpl = "100"
  vars.ping_wrta = "300000"
  vars.ping_cpl = "100"
  vars.max_check_attempts = "2"
  vars.agent_endpoint = "redcapserver" 
  vars.os = "Linux"
  vars.disks["basic-partitions"] = {
    disk_partitions = [ "/", "/tmp", "/var/lib", "/home" ]
  }
  vars.http_vhosts["http"] = {
    http_uri = "/redcap/"
  }
  vars.geolocation = "-0.67443049,10.2284864"
  vars.notification["mail"] = {
    groups = ["icingaadmins"]
  }

}

and this is the servive

apply Service "ping4" {
  import "generic-service"
  check_command = "ping4"
  check_interval = 5m
  retry_interval = 5m
  vars.notification["mail"] = {
    groups = ["icingaadmins"]
  }
  assign where host.address
}

and the notification object

apply Notification "mail-service-notification-specific-service" to Service {
  import "mail-service-notification"
  user_groups = host.vars.notification.mail.groups
  assign where service.name == "ping4"
}

By default, when I turn off the server to test, I am informed that all the different services are down, except ping which is the service I want to be notified about.