Apply notification to users stored in host object (custom var)

Hello community :slightly_smiling_face: ,

I’d like to setup a Notification Apply Rule in Director similar to this example in the Icinga2 docs:
https://icinga.com/docs/icinga-2/latest/doc/03-monitoring-basics/#notifications-users-from-hostservice

In short, I have a custom var in my host objects: host.vars.users
(Array of strings with usernames; corresponding to names of user objects; those come from an LDAP import source).

This is the Notification Apply Rule I made in Director:

apply Notification "thd_alert_sysadmins_mail_host" to Host {
    import "thd_alert_tpl_mail_host"

    assign where host.address
    users = [ "myusername" ]
}

I’d actually like to set, users = [ "myusername" ] to users = host.vars.users
Problem is: I can only set concrete usernames or usergroups via the Director UI.

Am I looking in the wrong place? Maybe I need to fiddle with the plain Icinga2 conf & Kickstart?

Or would you know of a better way to assign notifications to users set in custom vars?

Thanks very much! :wave:
/Barney


  • Director version (System - About): 1.10.2
  • Icinga Web 2 version and modules (System - About): 2.11.3
  • Icinga 2 version (icinga2 --version): 2.13.6
  • Operating System and version: Debian 11
  • Webserver, PHP versions: Apache 2.4.54, PHP 7.4.33

Well, I found a “working workaround” :wink: for now:

:point_right: Create a new Notification Apply Rule not in Director, but in plain Icinga2.

Expand here for the boring details
# Create a new Notification Apply Rule not in Director, but in plain Icinga2
editor /etc/icinga2/my.conf
apply Notification "myhostmailalert" to Host {
        command = "myhostmailcmd"
//      [...]
        users = host.vars.users    // Icinga2 accepts this syntax, Director doesn't
        assign where host.address
}
# Append to Icinga2 config, if you haven't done so already
echo 'include "my.conf"' >> /etc/icinga2/icinga2.conf

# Make sure there are no errors, then refresh service
icinga2 daemon -C
systemctl reload icinga2

# Tell Director about it
icingacli director kickstart run

Don’t try to outsmart Director’s UI by going via Icingaweb2’s CLI; doesn’t work (maybe for the better).

Details
# Circumvent Director UI by going via Icingaweb2's command line interface
icingacli director notification set thd_alert_sysadmins_mail_host --users host.vars.users

ERROR: Icinga\Exception\ProgrammingError in /usr/share/icingaweb2/modules/director/library/Director/Objects/IcingaObjectMultiRelations.php:228 with message: The related icinga_user "host.vars.users" doesnt exists: Failed to load icinga_user "host.vars.users"

# Same when trying through JSON notation
icingacli director notification set thd_alert_sysadmins_mail_host --json '{ "users": "host.vars.users" }'

I’m not really happy with this workaround.

(Mixing and matching Icinga2- and Director-Config is bad style and prone to errors.)

Maybe somebody knows of a more elegant solution…? :slightly_smiling_face: