Service: set re-notification time

Hi,

for now I´m getting a mail from a service´s warning state every 30 minutes. Is there a way to define, in which time frame a re-notification should be sent?

My service is defined like:

apply Service "ssl" {
    import "ssl-service"
    vars.ssl_port                     = "443"
    vars.ssl_cert_valid_days_warn     = "30"
    vars.notification.interval = 0
    check_command                     = "ssl"
    assign where host.vars.ssl_proxy
}

template:

template Service "ssl-service" {
  max_check_attempts = 3
  check_interval = 1440m
  retry_interval = 1440m
}

I´m trying to achieve a re-notification every / once a day.

You need to configure the notification interval within your notification object. Details are documented here

With your current config, you (re-)check only every 24h but send notification about this check result every 30min, which is the default notification interval.

3 Likes

Thanks, do you know, how I can use this object notification for one single service via apply rule only? I´ve tried the following, but the default service notification is executed also:

apply Notification "ssl-notification" to Service {
  import "mail-service-notification"
  types = [ Problem, Recovery ]
  states = [ OK, Warning, Critical, Unknown ]

  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  interval = 86400
  assign where service.name == "ssl"
}

You can get conditional about it in the parent template there:

if (service.name == "ssl") {
  interval = 86400
}

Something else I do since my notifications also tend to blanket a ton of things is this:

  assign where host.vars.notification.bto.pagerduty == true
  assign where service.vars.notification.bto.pagerduty == true
  ignore where service.vars.nopagerduty == true

That’s from my pagerduty notification object. I just toss service.vars.nopagerduty on any service object I don’t want to page me since it’s far less common than the ones that should.

2 Likes

If you prefer to affect a single service object tied to a host object, the assign where expression is pretty expensive, like

assign where host.name == "bla" && service.name == "ssl"

Instead, use the object notation here which defines host_name and service_name as Notification object attributes:

object Notification "ssl-notification" {
  ...
  host_name = "bla"
  service_name = "ssl"
}

These two attributes automatically identify this a service notification.

Cheers,
Michael

1 Like

Thanks, ah, I think I´ven´t explained it very well: every ssl service check should have this notification type. I think the if condition from @blakehartshorn works!

1 Like

Ah. Yeah, then something from the hidden germs: You can also just go for the check_command attribute, instead of the naming parts :slight_smile:

assign where service.check_command == "ssl"

That way your services can use a different name (renaming can happen) and your notifications are still intact.

Cheers,
Michael

1 Like

Thanks - so if two notifications are assigned (the general and the notification for ssl only), how does icinga know, which notification rule is the right one or has priority?

Neither has, they will generate colliding objects. You’ll need to take advantage and define the exceptions inside the assign where parts. There’s also the possibility to use ignore where for instance.

That’s the thing with two or more notification apply rules. The solution from @blakehartshorn is far more advanced with only having one notification apply rule but inline conditions.

We invented conditions with if-then-else for exactly solving such questions asked on the community channels :wink: Still, you may need to reconsider for many apply rules, especially when you are going the Icinga Director route at some point, where inline DSL doesn’t work.

Something like this, combined into one generic notification apply rule:

apply Notification "notification" to Service {
  import "mail-service-notification"
  types = [ Problem, Recovery ]
  states = [ OK, Warning, Critical, Unknown ]

  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  if (service.check_command == "ssl") {
    interval = 86400
  } else if (...) {
    // a different handling again?
  } else {
    // a default maybe, overriding the default of 30m?
  }
  assign where ... //previous one for general notifications
}

Cheers,
Michael