<commit_before>// Take well-formed json from either stdin or an input file and create an attachment notification for Slack
//
// LICENSE:
//   Copyright 2015 Yieldbot. <<EMAIL>>
//   Released under the MIT License; see LICENSE
//   for details.

package main

import (
	"flag"
	"fmt"
	"github.com/nlopes/slack"
	"github.com/yieldbot/sensuplugin/sensuhandler"
	"github.com/yieldbot/sensuplugin/sensuutil"
	//"github.com/yieldbot/sensuslack/lib"
	"strconv"
	"strings"
	"time"
)

func setColor(status int) string {
	switch status {
	case 0:
		return "#33CC33"
	case 1:
		return "warning"
	case 2:
		return "#FF0000"
	case 3:
		return "#FF6600"
	default:
		return "#FF6600"
	}
}

func cleanOutput(output string) string {
	return strings.Split(output, ":")[0]
}

func main() {

	slackTokenPtr := flag.String("token", "", "the slack integration token")
	channelPtr := flag.String("channel", "monitoring-test", "the channel to post notifications to")

	flag.Parse()

	slackToken := *slackTokenPtr
	channelName := *channelPtr
	channelID := "C09JY7W0P"

	sensuEvent := new(sensuhandler.SensuEvent)
	sensuEvent = sensuEvent.AcquireSensuEvent()

	// YELLOW
	// this is ugly, needs to be a better way to do this
	if slackToken == "" {
		fmt.Print("Please enter a slack integration token")
		sensuutil.Exit("CONFIGERROR")
	}

	fmt.Printf(channelName)

	// for k, v := range lib.SlackChannels {
	// 	if channelName == k {
	// 		channelID = v
	// 	}
	// }

	if channelID == "000000" {
		fmt.Printf("%v is not mapped, please see the infra team")
		sensuutil.Exit("CONFIGERROR")
	}

	// api := slack.New(slackToken)
	// // If you set debugging, it will log all requests to the console
	// // Useful when encountering issues
	// // api.SetDebug(true)
	// groups, err := api.GetChannelInfo(channelID)
	// if err != nil {
	// 	fmt.Printf("%s\n", err)
	// 	return
	// }
	// fmt.Printf("%v", groups)

	api := slack.New(slackToken)
	params := slack.PostMessageParameters{}
	attachment := slack.Attachment{
		Color: setColor(sensuEvent.Check.Status),

		Fields: []slack.AttachmentField{
			slack.AttachmentField{
				Title: "Monitored Instance",<commit_msg>working on channelid issue<commit_after>// Take well-formed json from either stdin or an input file and create an attachment notification for Slack
//
// LICENSE:
//   Copyright 2015 Yieldbot. <<EMAIL>>
//   Released under the MIT License; see LICENSE
//   for details.

package main

import (
	"flag"
	"fmt"
	"github.com/nlopes/slack"
	"github.com/yieldbot/sensuplugin/sensuhandler"
	"github.com/yieldbot/sensuplugin/sensuutil"
	//"github.com/yieldbot/sensuslack/lib"
	"strconv"
	"strings"
	"time"
)

func setColor(status int) string {
	switch status {
	case 0:
		return "#33CC33"
	case 1:
		return "warning"
	case 2:
		return "#FF0000"
	case 3:
		return "#FF6600"
	default:
		return "#FF6600"
	}
}

func cleanOutput(output string) string {
	return strings.Split(output, ":")[0]
}

func main() {

	slackTokenPtr := flag.String("token", "", "the slack integration token")
	channelPtr := flag.String("channel", "monitoring-test", "the channel to post notifications to")

	flag.Parse()

	slackToken := *slackTokenPtr
	channelName := *channelPtr
	channelID := "C09JY7W0P"

	sensuEvent := new(sensuhandler.SensuEvent)
	sensuEvent = sensuEvent.AcquireSensuEvent()

	// YELLOW
	// this is ugly, needs to be a better way to do this
	if slackToken == "" {
		fmt.Print("Please enter a slack integration token")
		sensuutil.Exit("CONFIGERROR")
	}

	fmt.Printf(channelName)

	// for k, v := range lib.SlackChannels {
	// 	if channelName == k {
	// 		channelID = v
	// 	}
	// }

	// if channelID == "000000" {
	// 	fmt.Printf("%v is not mapped, please see the infra team")
	// 	sensuutil.Exit("CONFIGERROR")
	// }

	// api := slack.New(slackToken)
	// // If you set debugging, it will log all requests to the console
	// // Useful when encountering issues
	// // api.SetDebug(true)
	// groups, err := api.GetChannelInfo(channelID)
	// if err != nil {
	// 	fmt.Printf("%s\n", err)
	// 	return
	// }
	// fmt.Printf("%v", groups)

	api := slack.New(slackToken)
	params := slack.PostMessageParameters{}
	attachment := slack.Attachment{
		Color: setColor(sensuEvent.Check.Status),

		Fields: []slack.AttachmentField{
			slack.AttachmentField{
				Title: "Monitored Instance",
{'fraction_non_alphanumeric': 0.14402237240736426, 'fraction_numerical': 0.01631321370309951, 'mean_word_length': 3.5659574468085107, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '788171', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1508, 'n_words': 390}