Data Fields : assign host custom variable value to service custom variable

Hi !
We have a notification setup where the custom var. host.vars.notif_mail_users (array type) is defined on the host instance.
When we create a new host, there are several services checks that are enabled by assign rules for Hosts Groups in Service Sets. All these services also have a notif_mail_users custom variable defined. Per default, we would like to set the service var. to the same value that the one from the host.
In the service template, we tried to set mail_notif_users = host.vars.notif_mail_users with not luck. The variable value will not be substituted.
Is there a way/workaround to achieve this ?
Thanks,
Dominique

Hi and welcome to the community.

I think you want to set the same service notification as your host notification?

We realize it in the notification command:

apply Notification "mail-service-24x7" to Service {
  import "service-24x7"

   if (service.vars.notification.mail.users) {
          users = service.vars.notification.mail.users
   } else {
          users = host.vars.notification.mail.users
   }

   if (service.vars.notification.mail.groups) {
          user_groups = service.vars.notification.mail.groups
   } else {
          user_groups = host.vars.notification.mail.groups
   }
   
  assign where service.vars.sla == "24x7" && host.vars.notification.mail
  ignore where host.vars.sla == "never"
}

Thanks Hendrik for replying.
We are using the director and I don’t see a way to embed if/else in the code.
Or am I missing something?
Dominique

My fault. :roll_eyes:

I think there is a similar solution for directors config, but I dont use the director.

Try
‘’’
$host.vars.notifi…$
‘’’

Hi Carsten,

Thanks or the tip, but this makes no difference:

Next check in 1m 59s Reschedule
Check attempts 1/3 (hard state)
Check execution time 2.024s
Check latency 0.000297s
Custom Variables
Mail Users

'''$host.vars.mail_notif_users$'''

The host.vars.mail_notif_users (array type) is not substituted
Am I doing something wrong?

Dominique

Forgot to mention that I did try $host.vars.mail_notif_users$ (without quotes) before asking here

Iam too far away from my system to do sone tests. But if you have no solution until sunday, i will test it and post it here

Thank you for your time, Carsten.
BTW: I have to take this opportunity to thank you for you awesome Grafana Module!

Dominique

1 Like

We were trying to find a way to implement the same DSL logic and could not see how to do this with the Director.

Let me share how we solved it.

You should have first defined Notification Users/Contacts and/or User Groups.
Then create a data field like notif_mail_users of data type DirectorObject and object Users.

Add this field to your Host and Service templates.
When you add a new host, you’ll now be able to fill a list of users who should get notified by mail.

Craft your notification apply rules with the appropriate assign where logic.

For example, we want that the list of notified users assigned to a host are
by default the same for each service defined for that host.
We also want to be able to override this configuration for each service.

The notification apply rule for the myself user would be:

("myself" in host.vars.notif_mail_users && "myself" in service.vars.notif_mail_users) || ("myself" in host.vars.notif_mail_users && ! service.vars.notif_mail_users) || "myself" in service.vars.notif_mail_users

HTH,
Dominique

2 Likes