Join host.groups to a string for a notification

Hi,

I’d like to put the list of host groups a host is in into the e-mail notification. Here is what I have:

object NotificationCommand "foo" {
  command = [
    "/path/to/my/script",
    "host.groups=$host.groups$"
  ]

which of course doesn’t work because an array of strings doesn’t implicitly convert to a string.

I tried

"host.groups="+host.groups.join(",")

but that doesn’t work in different syntax variants (validation error “Invalid Field Access”). I also cannot pull host.groups into a local variable with the same error message.

What am I doing wrong? What is the correct syntax?

Greetings
Marc

Ok,

this was considerably more advanced. After grilling my head inside runtime macros, configuration varables, scopes, functions and the excellent docs I came up with this working solution:

    command = [
            "/etc/icinga2/bin/notify",
            ...
            "host_groups=$notification_hostgroups$",
            ...
    ]

    vars.notification_hostgroups = {{
            var groups = macro("$host.groups$")
            return groups.join(", ")
    }}

The idea was pulled from the “functions as custom variables” section in the “Monitoring Basics” chapter of the docs. I fail to see why this is “basic” in any form, but ymmv :wink:

Greetings
Marc

1 Like