I want to create an Apply for rule for certificate checks, but want to assign where the http_ssl key is set to true or just simply exists. The problem here is though, that we’re running against a nested dictionaries so the following won’t work:
assign where host.vars.http.http_ssl
To handle the different entries, (I suppose) a wildcard or something similar would be needed:
assign where host.vars.http[*].http_ssl
But obviously that doesn’t work.
I hope you see what I am trying to do.
Is this the right approach or am I over-complicating things? Maybe there’s an easier solution to this?
@jbrost I was trying an alternative, which would use a variable retrieved from the dictionary in the assign where part. However this doesn’t seem to work (only works for host.vars ?):
Looks like I found a way
By using config as dictionary identifier and then followed by the actual variable, I can create an apply rule which is only applied when certain variables are set in the dictionary.
apply Service "http " for (servername => config in host.vars.http) {
import "generic-service"
check_command = "http"
vars.http_vhost = servername
vars += config
assign where host.vars.http && config.http_string
}
Works fine in my test environment with Icinga 2 2.13.2.