Ejemplo n.º 1
0
func configureSenders() error {
	sendersList, ok := config.GetInterface("notifier", "senders").([]interface{})
	if ok == false {
		return fmt.Errorf("Failed parse senders")
	}
	for _, senderSettingsI := range sendersList {
		senderSettings := make(map[string]string)
		for k, v := range senderSettingsI.(map[interface{}]interface{}) {
			senderSettings[to.String(k)] = to.String(v)
		}
		senderSettings["front_uri"] = config.Get("front", "uri")
		switch senderSettings["type"] {
		case "pushover":
			if err := notifier.RegisterSender(senderSettings, &pushover.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		case "slack":
			if err := notifier.RegisterSender(senderSettings, &slack.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		case "mail":
			if err := notifier.RegisterSender(senderSettings, &mail.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		case "script":
			if err := notifier.RegisterSender(senderSettings, &script.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		case "telegram":
			if err := notifier.RegisterSender(senderSettings, &telegram.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		case "twilio sms":
			if err := notifier.RegisterSender(senderSettings, &twilio.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		case "twilio voice":
			if err := notifier.RegisterSender(senderSettings, &twilio.Sender{}); err != nil {
				log.Fatalf("Can not register sender %s: %s", senderSettings["type"], err)
			}
		// case "email":
		// 	if err := notifier.RegisterSender(senderSettings, &kontur.MailSender{}); err != nil {
		// 	}
		// case "phone":
		// 	if err := notifier.RegisterSender(senderSettings, &kontur.SmsSender{}); err != nil {
		// 	}
		default:
			return fmt.Errorf("Unknown sender type [%s]", senderSettings["type"])
		}
	}
	return nil
}
Ejemplo n.º 2
0
				Dial: func() (redis.Conn, error) {
					return c, nil
				},
			}
		} else {
			testDb.conn.Pool = notifier.NewRedisPool("localhost:6379")
		}
		testDb.init()
		notifier.SetDb(testDb.conn)

		notifier.GetNow = func() time.Time {
			return time.Unix(1441188915, 0) // 2 Сентябрь 2015 г. 15:15:15 (GMT +5)
		}
		senderSettings := make(map[string]string)
		senderSettings["type"] = "email"
		notifier.RegisterSender(senderSettings, &badSender{})
		senderSettings["type"] = "slack"
		notifier.RegisterSender(senderSettings, &timeoutSender{})
		sendersRunning = true
	})

	Context("When one invalid event arrives", func() {
		BeforeEach(func() {
			event = notifier.EventData{
				Metric:    "test1",
				State:     "OK",
				OldState:  "WARN",
				TriggerID: "",
			}
			err = notifier.ProcessEvent(event)
		})