Host vars override service vars?

Hi all,

I am having trouble understanding the way icinga defines some vars with apply rules. I read a lot before writing here so please excuse if I missed something essential which solves my problem.

My problem is regarding notifications:

I am using the default config:

notifications.conf

apply Notification “mail-icingaadmin” to Host {
import “mail-host-notification”

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

assign where host.vars.notification.mail
interval = 24h
}

apply Notification “mail-icingaadmin” to Service {
import “mail-service-notification”

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

assign where host.vars.notification.mail
interval = 24h
}

I am asigning the notification targets as follows:

templates.conf

template Service “generic-service-sharepoint” {
max_check_attempts = 10
check_interval = 1m
retry_interval = 30s
vars.notification[“mail”] = {
users = [ “sharepointadmin” ]
}
}

template Host “generic-host-test” {
max_check_attempts = 5
check_interval = 2m
retry_interval = 30s
check_command = “hostalive”
vars.notification[“mail”] = {
users = [ “testadmin” ]
}
}

The problem I am having is that no matter which service template I include in my config, the var of the host tempate always overrides:

object Host “sm01” {
import “generic-host-test”
display_name = “sm01 dev”
address = “172.21.1.174”
vars.os = “Windows”
vars.type = “sharepoint”
vars.sla = “24x7”
vars.virtual = “true”
}
object Service “DISK_E” {
import “generic-service-sharepoint”
host_name = “sm01”
check_command = “nscp”
vars.nscp_variable = “USEDDISKSPACE”
vars.nscp_params = “e”
vars.nscp_warn = 85
vars.nscp_crit = 90
}

The Service now has “testadmin” as Notification user (as defined for the host). I want the Service to send to (and only to) “sharepointadmin” as defined in its template.
grafik

Does the host var somehow override the var of my service template or do I have a wrong understanding of the configuration?

Thanks for any help in advance.

Hi,

welcome to the community! I guess this is a classic one that just confused you a bit. :slight_smile:

It actually works as configured. The issue is that you refer to the host.vars in both cases.

So, you should refer to service.vars.users for the mail-icingaadmin notification applied to services and not to host.vars.notification.mail.users.

Oh man. Thank you a lot. Of course this is the issue…

I already assumed that it was something with host/service distinction but I didn’t realize it :man_facepalming:.
Thank you very much!

1 Like