Ejemplo n.º 1
0
func main() {
	pager.ServiceKey = os.Getenv("PAGERDUTY_KEY")
	log.Println(pager.ServiceKey)
	threshold := os.Getenv("THRESHOLD")
	thresholdInt, err := strconv.ParseInt(threshold, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Starting monitoring loop")
	for {
		stats, err := getStats()
		if err != nil {
			log.Println(err)
		} else {
			log.Printf("%d messages enqueued\n", stats.Sidekiq.Enqueued)
			if stats.Sidekiq.Enqueued > int(thresholdInt) {
				log.Println("Triggering alert")
				key, err := pager.Trigger("Sidekiq queue backed up")
				if err != nil {
					log.Println(err)
				} else {
					log.Println("Incident key: " + key)
				}
			}
		}

		time.Sleep(60 * time.Second)
	}
}
Ejemplo n.º 2
0
//Send sends an alert
func (engine *AlertEngine) Send(triggeredRule Rule) error {
	if len(engine.Config.PagerDutyAPIKey) > 0 {
		pager.ServiceKey = engine.Config.PagerDutyAPIKey
		_, err := pager.Trigger(triggeredRule.Text)
		return err
	}

	if len(engine.Config.EmailServer) > 0 {
		m := gomail.NewMessage()
		m.SetHeader("From", "*****@*****.**")
		m.SetHeader("To", engine.Config.EmailRecipient)
		m.SetHeader("Subject", fmt.Sprintf("ALERT %s as been triggered", triggeredRule.Name))
		m.SetBody("text/plain", triggeredRule.Text)

		dailer := gomail.Dialer{Host: engine.Config.EmailServer, Port: engine.Config.EmailPort}
		if err := dailer.DialAndSend(m); err != nil {
			return err
		}
	}
	return nil
}