Exemple #1
0
// NewConfig returns an instance of Config with reasonable defaults.
func NewConfig() *Config {
	c := &Config{
		Hostname: "localhost",
	}

	c.HTTP = httpd.NewConfig()
	c.Storage = storage.NewConfig()
	c.Replay = replay.NewConfig()
	c.Task = task_store.NewConfig()
	c.Logging = logging.NewConfig()

	c.Collectd = collectd.NewConfig()
	c.OpenTSDB = opentsdb.NewConfig()
	c.SMTP = smtp.NewConfig()
	c.OpsGenie = opsgenie.NewConfig()
	c.VictorOps = victorops.NewConfig()
	c.PagerDuty = pagerduty.NewConfig()
	c.Sensu = sensu.NewConfig()
	c.Slack = slack.NewConfig()
	c.Telegram = telegram.NewConfig()
	c.HipChat = hipchat.NewConfig()
	c.Alerta = alerta.NewConfig()
	c.Reporting = reporting.NewConfig()
	c.Stats = stats.NewConfig()
	c.UDF = udf.NewConfig()
	c.Deadman = deadman.NewConfig()
	c.Talk = talk.NewConfig()

	return c
}
Exemple #2
0
// NewConfig returns an instance of Config with reasonable defaults.
func NewConfig() *Config {
	c := &Config{
		Hostname: "localhost",
	}
	c.HTTP = httpd.NewConfig()
	c.Replay = replay.NewConfig()
	c.Task = task_store.NewConfig()
	c.InfluxDB = influxdb.NewConfig()
	c.Logging = logging.NewConfig()

	c.Collectd = collectd.NewConfig()
	c.OpenTSDB = opentsdb.NewConfig()
	c.SMTP = smtp.NewConfig()
	c.OpsGenie = opsgenie.NewConfig()
	c.VictorOps = victorops.NewConfig()
	c.PagerDuty = pagerduty.NewConfig()
	c.Slack = slack.NewConfig()
	c.HipChat = hipchat.NewConfig()
	c.Reporting = reporting.NewConfig()
	c.Stats = stats.NewConfig()

	return c
}
Exemple #3
0
func TestStream_AlertVictorOps(t *testing.T) {
	requestCount := 0
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		requestCount++
		if requestCount == 1 {
			if exp, got := "/api_key/test_key", r.URL.String(); got != exp {
				t.Errorf("unexpected VO url got %s exp %s", got, exp)
			}
		} else if requestCount == 2 {
			if exp, got := "/api_key/test_key2", r.URL.String(); got != exp {
				t.Errorf("unexpected VO url got %s exp %s", got, exp)
			}
		}
		type postData struct {
			MessageType       string      `json:"message_type"`
			EntityID          string      `json:"entity_id"`
			EntityDisplayName string      `json:"entity_display_name"`
			Timestamp         int         `json:"timestamp"`
			MonitoringTool    string      `json:"monitoring_tool"`
			Data              interface{} `json:"data"`
		}
		pd := postData{}
		dec := json.NewDecoder(r.Body)
		dec.Decode(&pd)
		if exp := "CRITICAL"; pd.MessageType != exp {
			t.Errorf("unexpected message type got %s exp %s", pd.MessageType, exp)
		}
		if exp := "kapacitor/cpu/serverA"; pd.EntityID != exp {
			t.Errorf("unexpected entity id got %s exp %s", pd.EntityID, exp)
		}
		if exp := "kapacitor/cpu/serverA is CRITICAL"; pd.EntityDisplayName != exp {
			t.Errorf("unexpected entity id got %s exp %s", pd.EntityDisplayName, exp)
		}
		if exp := "kapacitor"; pd.MonitoringTool != exp {
			t.Errorf("unexpected monitoring tool got %s exp %s", pd.MonitoringTool, exp)
		}
		if exp := 31536010; pd.Timestamp != exp {
			t.Errorf("unexpected timestamp got %d exp %d", pd.Timestamp, exp)
		}
		if pd.Data == nil {
			t.Error("unexpected data got nil")
		}
	}))
	defer ts.Close()

	var script = `
stream
	.from().measurement('cpu')
	.where(lambda: "host" == 'serverA')
	.groupBy('host')
	.window()
		.period(10s)
		.every(10s)
	.mapReduce(influxql.count('idle'))
	.alert()
		.id('kapacitor/{{ .Name }}/{{ index .Tags "host" }}')
		.info(lambda: "count" > 6.0)
		.warn(lambda: "count" > 7.0)
		.crit(lambda: "count" > 8.0)
		.victorOps()
			.routingKey('test_key')
		.victorOps()
			.routingKey('test_key2')
`

	clock, et, replayErr, tm := testStreamer(t, "TestStream_Alert", script)
	defer tm.Close()
	c := victorops.NewConfig()
	c.URL = ts.URL
	c.APIKey = "api_key"
	c.RoutingKey = "routing_key"
	vo := victorops.NewService(c, logService.NewLogger("[test_vo] ", log.LstdFlags))
	tm.VictorOpsService = vo

	err := fastForwardTask(clock, et, replayErr, tm, 13*time.Second)
	if err != nil {
		t.Error(err)
	}

	if requestCount != 2 {
		t.Errorf("unexpected requestCount got %d exp 1", requestCount)
	}
}