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.
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.)