andyb2000
(Andy Brown)
November 24, 2020, 1:54pm
1
Hi folks,
I’m implementing a new icinga2 setup and in the notificationcommand I’d like to pass an env variable that will allow me to generate icingaweb2 url direct to the notification.
In icingaweb2 if I choose “History” > “Notifications” I get a list of all notifications. To view one I click on it and the url shown is:
/icingaweb2/monitoring/event/show?id=21905&type=notify
So the id is specific to this notification. Where/how do I get that ID and pass it in my NotificationCommand as I cannot find it in an environmental variable or value that I’ve searched for?
i.e. I want to add it to:
env = {
NOTIFICATIONTYPE = “$notification.type$”
SERVICEDESC = “$service.name$”
HOSTNAME = “$host.name$”
HOSTALIAS = “$host.display_name$”
HOSTADDRESS = “$address$”
SERVICESTATE = “$service.state$”
LONGDATETIME = “$icinga.long_date_time$”
SERVICEOUTPUT = “$service.output$”
NOTIFICATIONAUTHORNAME = “$notification.author$”
NOTIFICATIONCOMMENT = “$notification.comment$”
HOSTDISPLAYNAME = “$host.display_name$”
SERVICEDISPLAYNAME = “$service.display_name$”
USEREMAIL = “$user.email$”
NOTES = “$service.notes$”
}
Thank you
Hi @andyb2000 ,
For that you can use something like this:
# Host:
var host_name_with_link = "<" + icinga2_base_url + "/monitoring/host/show?host=" + host_name + "|" + host_display_name + ">"
# Service:
service_name_with_link = "<" + icinga2_base_url + "/monitoring/service/show?host=" + host_name + "&service=" + service_name + "|" + service_display_name + ">"
#Where:
var service_display_name = macro("$service.display_name$")
Stolen from:
object NotificationCommand "slack-notifications-command" {
import "plugin-notification-command"
command = {{
log(LogDebug, "slack-notifications", "Sending notification...reading user configuration")
var plugin_output_max_length_from_config = macro("$slack_notifications_plugin_output_max_length$")
var plugin_output_max_length = Math.round(plugin_output_max_length_from_config)
var slack_webhook_url = macro("$slack_notifications_webhook_url$")
var slack_proxy = macro("$slack_notifications_proxy$")
var slack_channel = macro("$slack_notifications_channel$")
var slack_botname = macro("$slack_notifications_botname$")
var icinga2_base_url = macro("$slack_notifications_icinga2_base_url$")
var slack_icon_dictionary = macro("$slack_notifications_icon_dictionary$")
var slack_color_dictionary = macro("$slack_notifications_color_dictionary$")
var configuration = {
"vars.slack_notifications_plugin_output_max_length" = plugin_output_max_length,
"vars.slack_notifications_webhook_url" = slack_webhook_url,
"vars.slack_notifications_channel" = slack_channel,
"vars.slack_notifications_proxy" = slack_proxy,
This file has been truncated. show original
Hope it will help you in good direction