icinga2-slack-notification
icinga2-slack-notification copied to clipboard
Define channel or user mention per host
I'd like to be able to define a Slack channel name or Slack user for a host (or service) and when a notification is sent, to add @channel
or @username
so a mention is triggered in Slack.
This should alert the right people who are in charge of the specific host/service by mentioning them in the monitoring channel.
Do you have a pointer about the best way to implement it?
Thanks, Stefan
Hi @nicolinux
You could make the notification scripts configurable by removing the channel (or user) assignment: https://github.com/jjethwa/icinga2-slack-notification/blob/master/slack-service-notification.sh#L5
Modify the NotificationCommand:
object NotificationCommand "slack-service-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/slack-service-notification.sh" ]
var slack_channel = "#alerts"
if (notification.vars.slack_channel) {
slack_channel = "$notification.vars.slack_channel$"
}
env = {
"NOTIFICATIONTYPE" = "$notification.type$"
"SERVICEDESC" = "$service.name$"
"HOSTALIAS" = "$host.display_name$",
"HOSTNAME" = "$host.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$",
"SLACK_CHANNEL" = "$slack_channel$",
}
}
then
apply Notification "slack" to Service {
import "slack-service-notification"
user_groups = [ "noc" ]
interval = 5m
var slack_channel = "#noc"
assign where host.vars.sla == "24x7"
}
I didn't test this out fully, it's just off the top of my head, but it should get you close to what you want to accomplish. Let me know if I can help further 😄
Greetings,
I have been trying to implement your method to integrate ICINGA and SLACK. However, i m not seeing any notifications though to slack automatically going if an Event occurs in Icinga.
IF i run #icinga deamon -c
root@sony-VPCEH25EN:/etc/icinga2/conf.d# icinga2 daemon -C
warning/ApplyRule: Apply rule 'slack' (in /etc/icinga2/conf.d/notifications.conf: 29:1-29:37) for type 'Notification' does not match anywhere! warning/ApplyRule: Apply rule 'slack' (in /etc/icinga2/conf.d/notifications.conf: 37:1-37:34) for type 'Notification' does not match anywhere!
Could you please help.
Thanks Aravind
Hi @ananthaa-advisory
This is a different issue than the original poster brought up. Ideally this should be a new issue.
From the error, it looks like you're missing the slack-host-notification.conf or slack-service-notification.conf ?
Yeah. I'm a new user to Github as well. So commented on the post.
I have made lot of double checks and I didn't miss anything. I just copy and pasted whatever you have said. It looks to be a notifications issue Though.
Hi @ananthaa-advisory
Do you mind copy/pasting all of the related configs here? Something is missing 😢