Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define channel or user mention per host #6

Open
nicolinux opened this issue Mar 20, 2017 · 5 comments
Open

Define channel or user mention per host #6

nicolinux opened this issue Mar 20, 2017 · 5 comments

Comments

@nicolinux
Copy link

nicolinux commented Mar 20, 2017

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

@jjethwa
Copy link
Owner

jjethwa commented Mar 20, 2017

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 😄

@ananthaa-advisory
Copy link

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

@jjethwa
Copy link
Owner

jjethwa commented Jul 11, 2017

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 ?

@ananthaa-advisory
Copy link

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.

@jjethwa
Copy link
Owner

jjethwa commented Jul 11, 2017

Hi @ananthaa-advisory

Do you mind copy/pasting all of the related configs here? Something is missing 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants