I’m trying to convince Icinga to handle things slightly more intelligently, however this has me stumped:
object Host "some.host.name" {
// other config lines here
groups += ["windows"]
vars.winsvcs += [
"A Windows Service",
"Another Windows Service",
]
}
// 7 lines of header comments
apply Service "winsvc" for (winsvc in host.vars.winsvcs) {
import "generic-service"
check_command ="snmp-service"
display_name = winsvc
vars.snmp_service_name = winsvc
vars.snmp_retries = 2
vars.snmp_timeout = 15
var knownServices = get_services(host.name).map(X=>X.name)
assign where match("*"+winsvc, this.knownServices, MatchAny) == false
ignore where match("*"+winsvc, this.knownServices, MatchAny)
}
the result:
[2024-02-05 15:35:44 +0100] critical/config: Error: An object with type 'Service' and name 'some.host.name!winsvcA Windows Service' already exists (in /etc/icinga2/zones.d/global-templates/Services/winsvcs.conf: 9:1-9:56), new declaration: in /etc/icinga2/zones.d/global-templates/Services/winsvcs.conf: 9:1-9:56
Location: in /etc/icinga2/zones.d/global-templates/Services/winsvcs.conf: 9:1-9:56
/etc/icinga2/zones.d/global-templates/Services/winsvcs.conf(7): #=- ---------------------------------------------------------------------------
/etc/icinga2/zones.d/global-templates/Services/winsvcs.conf(8):
/etc/icinga2/zones.d/global-templates/Services/winsvcs.conf(9): apply Service "winsvc" for (winsvc in host.vars.winsvcs) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-templates/Services/winsvcs.conf(10): import "generic-service"
/etc/icinga2/zones.d/global-templates/Services/winsvcs.conf(11): check_command ="snmp-service"
Expected result: no complaints about services already being defined as the assign/ignore clauses were expected to take care of that issue.
I pulled the get_services(…) call into a separate var as I was unsure whether or not match(…) could handle it.
Using the console I’ve verified that the get_services(…) call indeed returns an array, which I’d expect was fine:
<1> => match("*A Windows Service",get_services("some.host.name").map(X=>X.__name),MatchAny)
true
<2> =>
and
<1> => winsvc="A Windows Service"
null
<2> => match("*"+winsvc,get_services("some.host.name").map(X=>X.__name),MatchAny)
true
Have I missed something or am I simply expecting too much of DSL?