Add one group in notifications for one service only

Hi all,

I have my host defined as follow

object Host "server12" {
  import "generic-host"

  address     = "1.2.3.4"
  vars.os     = "Windows"
  vars.distro = "Server 2019"
  vars.group  = "other servers"
  vars.raid   = "yes"
  vars.checkdisk = "yes"
  vars.checkosversion = "yes"

  vars.notification["mail"] = { groups = [ "IT-Admins" ]  }
}

I have 5 services defined for this host and everything works well.

Now, for one service only, I need to add a group where the notification are sent.
Here is the service definition

apply Service "Check Microscope Sync" {
  import "generic-service"
  check_command = "by_nrpe_microscope_sync"
  vars.host = host.address

  check_interval  = 20m
  retry_interval  = 10m

  vars.notification["mail"] = { groups += [ "Other-IT-Admins" ]  }

  assign where (host.name == "server12")
}

I tried this += assignment on the variable but it’s not doing the job.
Tried also the += in the host definition thinking it’s overwriting the var bur it’s not working either.

Is there a way to simply add a user or group in notifications for a service only?

Thanks for your help.

Hello @darxmurf!

Have you tried:

vars.notification["mail"] = { groups = host.vars.notification.mail.groups + [ "Other-IT-Admins" ]  }

Best,
AK

Hello @darxmurf
You could use an apply rule for the notification for the service only.

apply Notification "mail-service-notification-Other-IT-Admins" to Service {
  import "mail-service-notification"

  groups = [ "Other-IT-Admins" ]

  assign where match ( "Check Microscope Sync", service.name )
}

Regards
Alex

Hi, @aclark6996
Thanks, this is working. The variable name was user_groups instead of groups but it’s working.

New question then as this notification definition added my group to the existing list but is there also possible to replace completely the defined groups for a service?

Notifications for this server will go to the IT-Admins and General-Mail but for a specific service, I want to send notif only to one group.

Thanks!

Hello @darxmurf,
You can try this.

object Host "server12" {
  import "generic-host"

  address     = "1.2.3.4"
  vars.os     = "Windows"
  vars.distro = "Server 2019"
  vars.group  = "other servers"
  vars.raid   = "yes"
  vars.checkdisk = "yes"
  vars.checkosversion = "yes"

// vars.notification.mail.groups += [ "" ]       
}

apply Notification "mail-service-notification-IT-Admins" to Host {
  import "mail-host-notification"

  user_groups = [ "IT-Admins" ]

  assign where host.vars.os == "Windows"
}

apply Notification "mail-service-notification-IT-Admins" to Service {
  import "mail-service-notification"

  user_groups = [ "IT-Admins" ]

  assign where host.vars.os == "Windows"
  ignore where match ( "Check Microscope Sync", service.name )
}

apply Notification "mail-service-notification-Other-IT-Admins" to Service {
  import "mail-service-notification"

  groups = [ "Other-IT-Admins" ]

  assign where match ( "Check Microscope Sync", service.name )
}

Regards
Alex