Define service check notifications independently from host notification defintions

Hi,

is it possible somehow to define service check notification definitions, which aren´t related to already defined host notification definitions? For example: all services at one host use per default mail and group definitions, which are set at the host globally for all underlying service checks.

Now I need one service check at this host, which uses it´s own notification group and method, which should not be additionally to the host notification definition, but independently.

Thanks and best,

Ben

Hi,

you’ll need to define a pattern or attribute then which identifies this exception.

apply Service "..." {
   vars.custom_notification_users = [ "u1", "u2" ]
   ...
}

Then modify the default notification rules for the to Service parts and add an ignore where expression after the assign where expression. custom_notification_users is an array, and if there are some elements in it, we don’t want a notification object being generated (length > 0).

 ignore where service.vars.custom_notification_users.len() > 0

Then add a new notification apply rule which exclusively targets the service with custom notification types.

apply Notification "custom-service-notification" to Service {
  ...
  users = service.vars.custom_notification_users
  

  assign where service.vars.custom_notification_users.len() > 0
}

This is a simplified example with storing the custom_notification_users on the service object/apply. It may need a more fine granular approach with multiple attribute providers and notification apply rules.

A different approach would be conditions inside the original notification apply rule, like so:

apply Notification "..." to Service {
  //original content
  //modified users based on what the service itself provides
  if (service.vars.notification.mail.contains("users")) {
    users = service.vars.notification.mail.users
  } else {
    users = host.vars.notification.mail.users
  }

}

Cheers,
Michael

1 Like