Example #1
0
func (i *Filter) AlertSlack(alertChan chan *AlertMessage) {
	slackConf := i.options.AlerterConf.SlackConf
	alerter := slackhook.New(slackConf["slackHookURL"])

	for p := range alertChan {
		//log.Warnf("Alerting Slack: %#v", p)
		hname, _ := os.Hostname()
		layers := *p.Layers
		msgTxt := fmt.Sprintf("wherefore detected anomylous traffic: %s Probability: %f\n", hname, layers["anomaly_probability"])
		msgTxt += DecodeLayersInfo(p.P.lastPM)
		msgTxt += fmt.Sprintf("%#v\n", p.P.gv)

		message := &slackhook.Message{
			Text:      msgTxt,
			Channel:   slackConf["slackChannel"],
			IconEmoji: slackConf["slackIconEmoji"],
		}
		log.Debugf("SlackMsg: %#v", message)
		//err := alerter.Simple(fmt.Sprintf("wherefore detected anomylous traffic: %#v", p.String()))
		err := alerter.Send(message)
		//TODO: Debug why invalid args don't return an error here
		if err != nil {
			log.Errorf("Error alerting to slack: %#v", err)
		}
	}
}
Example #2
0
func notifySlack(msg string, config slackConfig) {

	if config.Emoji == "" {
		config.Emoji = slackDefaultEmoji
	}

	if config.WebhookURL == "" {
		fmt.Println("WebhookUrl is missing, Slack notification will not be sent.")
		return
	}

	if config.Channel == "" {
		fmt.Println("Channel is missing, Slack notification will not be sent.")
		return
	}

	fmt.Println("Notifying Slack")
	c := slackhook.New(config.WebhookURL)

	m := &slackhook.Message{
		Text:      fmt.Sprintf("```%s```", msg),
		Channel:   config.Channel,
		IconEmoji: config.Emoji,
	}
	c.Send(m)
}
Example #3
0
// NewSlackNotifier creates a new SlackNotifier.
func NewSlackNotifier(url string) Notifier {
	return &SlackNotifier{slackhook.New(url)}
}