Creating ServiceGroups from custom tags

This isn’t limited to this one particular type of service, but I’ll use it to explain my problem. I have services created for interfaces on network gear using the common

apply Service “interface-usage” for (interface_name => int_name in host.vars.interfaces) {

Under the host config I have

vars.interfaces[“GigabitEthernet1/1”] = {
description = “GigabitEthernet1/1”
display_name = “Some trunk”
tags = [ “some-switch” , “another-tag” ]

When I view the service object definition with
icinga object list | less
I can see

  • vars
    • tags = [ “some-switch” , “another-tag” ]

Where I run into an issue is when I try to assign the services to a service group:

object ServiceGroup “another-tag” {
import “generic-servicegroup”
display_name = “Another tag test”

for ( var tag in service.vars.tags ) {
assign where match(“another-tag”, tag)


This causes

> critical/config: Error: Error while evaluating expression: Tried to access undefined script variable 'service'
> /etc/icinga2/zones.d/global-templates/groups.conf(147):   for ( var tag in service.vars.tags ) {
>                                                                            ^^^^^^^

I can access other vars in the service definition using your typical “assign where match(“foo”, service.vars.somevar”, but I can’t seem to figure out how to iterate over a list in the same manner.

Is this even possible?

Hi @lonelyadmin,

maybe you could try to use the ‘in operator’.

The assign rule would look something like this:
assign where "another-tag" in service.vars.tags

Kind regards,