jamespo
(J.P)
October 17, 2021, 5:27pm
1
If in my object host I have:
vars.check_interval = "5m"
and in my apply service I have:
if (host.vars.check_interval) {
check_interval = host.vars.check_interval
}
But I get a config validation error upon reload.
However hardcoding the value in the apply service works, eg:
if (host.vars.check_interval) {
check_interval = 5m
}
leeclemens
(Lee Clemens)
October 17, 2021, 8:16pm
2
Can you try this?
check_interval = "$host.vars.check_interval$"
Hello everybody, we are currently trying to port our Icinga2 configuration from using configs to using the Director.
At the moment I am trying to configure a Service Apply rule which populates a custom field value with a variable from a host. Using config files, this would be as easy as saying
vars.custom_service_field = host.vars.custom_host_field
But how can I achieve this using the Director, since you can’t define custom field values to be “variables”, only strings. Every input I tried so …
jamespo
(J.P)
October 17, 2021, 8:36pm
3
hmm, still get an error, safe-reload fails.
I figured it must be some delimiting of the variable as you suggest though.
leeclemens
(Lee Clemens)
October 17, 2021, 9:47pm
4
It may help if you share the error you are getting.
1 Like
log1c
October 18, 2021, 6:50am
5
Haven’t tried this myself, but my guess is that setting the variable as the value will result in check_interval = "variable_value"
. But the value for the interval has to be given without the "
.
The only way that comes to my mind to work around that is setting the value like in your second code snippet and have multiple if-conditions to check for the value of the var.
But that is only a working solution if you don’t have many different interval options, I guess.
dgoetz
(Dirk Götz)
October 18, 2021, 7:00am
6
Is this an apply rule or single object? For some strange reasons you can directly access the host object and its attributes in an apply but not an object. To access it from an object you need some code like this one borrowed from the Director:
if (! host) {
var host = get_host(host_name)
}
jamespo
(J.P)
October 18, 2021, 9:47am
7
It’s in an apply (top of section is apply Service for (nrpe_check in host.vars.nrpe_checks))
error looks like this:
Oct 18 09:42:10 jserv safe-reload[1337683]: /etc/icinga2/conf.d/jp/svc-tmpl.conf(180): if (host.vars.check_interval) {
Oct 18 09:42:10 jserv safe-reload[1337683]: /etc/icinga2/conf.d/jp/svc-tmpl.conf(181): // check_interval = 5m
Oct 18 09:42:10 jserv safe-reload[1337683]: /etc/icinga2/conf.d/jp/svc-tmpl.conf(182): check_interval = "$host.vars.check_interval$"
Oct 18 09:42:10 jserv safe-reload[1337683]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 18 09:42:10 jserv safe-reload[1337683]: /etc/icinga2/conf.d/jp/svc-tmpl.conf(183): }
Oct 18 09:42:10 jserv safe-reload[1337683]: [2021-10-18 09:42:10 +0000] critical/config: 1 error
Oct 18 09:42:10 jserv safe-reload[1337683]: [2021-10-18 09:42:10 +0000] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.
Oct 18 09:42:10 jserv systemd[1]: icinga2.service: Control process exited, code=exited, status=1/FAILURE
Oct 18 09:42:10 jserv systemd[1]: Reload failed for Icinga host/service/network monitoring system.