I need to add notifications to teams (via webhook).
Sadly the only reasonably good plugin for that seems to be GitHub - william-sy/icinga2-adaptive-teams-notification and since it’s written in icingaDSL i’m not quite sure how to best use it with director …
any suggestions?
I did it like this:
Data Fields
Host Template
Service Template
User Template
and then there are the files:
/etc/icinga2/zones.d/master/teams-notifications-command.conf
/etc/icinga2/zones.d/master/teams-notifications-configuration.conf
apply Notification "teams-notifications-notification-hosts" to Host {
import "teams-notifications-user-configuration-hosts"
interval = (host.vars.notification.interval) || 0
assign where host.vars.enable_teams_notifications == true
}
apply Notification "teams-notifications-notification-services" to Service {
import "teams-notifications-user-configuration-services"
interval = (service.vars.notification.interval) || 0
# enable globaly for all services on host but not if disabled for this service
assign where host.vars.enable_teams_notifications == true && service.vars.enable_teams_notifications != false
}
apply Notification "teams-notifications-notification-services" to Service {
import "teams-notifications-user-configuration-services"
interval = (service.vars.notification.interval) || 0
# only if not enabled globaly for host
assign where service.vars.enable_teams_notifications == true && host.vars.enable_teams_notifications != true
}
I guess that works. I want at least the apply rules in director though …
tried just adding the command and using kickstart to make director aware of it, that works. But i can’t do the same for the notification template it seems and i can’t just rebuild it in director either with those vars …
I’ll try to merke those into the command, there’s no good reason for those to be in a template anyway.
Yes, I added the variables in the command file and I see no reason why you couldn’t put the apply rules in the director.
Info: I tried to added the webhook url and icinga2 base url as arguments and no matter what i did icinga2 didn’t parse the config anymore.
I can only add apply rules in director if it knows the notification
I ended up using another plugin (GitHub - NeverUsedID/icinga2-msteams: Icinga2 notifications for MS teams) where adding was more “as usual”.
In my config the webhook key is a variable of the user in the director and gets used in the notification template:
template Notification "teams-notifications-user-configuration" {
import "teams-notifications-default-configuration"
users = (host.vars.notify_teams_bots) || (service.vars.notify_teams_bots) || vars.users_fallback
vars.teams_notifications_webhook_url = "$user.vars.teams_webhook_url$"
vars.teams_notifications_icinga2_base_url = "https://example.com/icingaweb2"
}