コード例 #1
0
ファイル: elastic_test.go プロジェクト: Griesbacher/nagflux
func TestGenIndex(t *testing.T) {
	config.InitConfigFromString(fmt.Sprintf(Config, "monthly"))
	//Do 24. Mär 15:00:44 CET 2016 == 1458828043
	result := GenIndex("index", "1458828043000")
	expected := "index-2016.03"
	if result != expected {
		t.Errorf(`GenIndex("index","1458828043000"): expected:%s, actual:%s`, expected, result)
	}
	config.InitConfigFromString(fmt.Sprintf(Config, "yearly"))
	result = GenIndex("index", "1458828043000")
	expected = "index-2016"
	if result != expected {
		t.Errorf(`GenIndex("index","1458828043000"): expected:%s, actual:%s`, expected, result)
	}
	config.InitConfigFromString(fmt.Sprintf(Config, "foo"))
	if !didThisPanic(GenIndex, "index", "1458828043000") {
		t.Error("The Config was invalid but did not panic!")
	}

}
コード例 #2
0
func TestPrintElasticsearchComment(t *testing.T) {
	logging.InitTestLogger()
	config.InitConfigFromString(fmt.Sprintf(Config, "monthly"))
	comment := CommentData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip", comment: "hallo world", entryTime: "1458988932000"}, entryType: "1"}
	if !didThatPanic(comment.PrintForElasticsearch, "1.0", "index") {
		t.Errorf("This should panic, due to unsuported elasticsearch version")
	}
	for _, data := range PrintCommentData {
		actual := data.input.PrintForElasticsearch("2.0", "index")
		if actual != data.outputElastic {
			t.Errorf("Print(%s): expected: %s, actual: %s", data.input, data.outputElastic, actual)
		}
	}
}
コード例 #3
0
func TestPrintElasticsearchDowntime(t *testing.T) {
	logging.InitTestLogger()
	config.InitConfigFromString(fmt.Sprintf(Config, "monthly"))
	down := DowntimeData{Data: Data{hostName: "host 1", serviceDisplayName: "service 1", author: "philip", entryTime: "1458988932000"}, endTime: "123"}
	if !didThatPanic(down.PrintForElasticsearch, "1.0", "index") {
		t.Errorf("This should panic, due to unsuported elasticsearch version")
	}

	result := down.PrintForElasticsearch("2.0", "index")
	expected := `{"index":{"_index":"index-2016.03","_type":"messages"}}
{"timestamp":1458988932000000,"message":"Downtime start: <br>","author":"philip","host":"host 1","service":"service 1","type":"downtime"}

{"index":{"_index":"index-1970.01","_type":"messages"}}
{"timestamp":123000,"message":"Downtime end: <br>","author":"philip","host":"host 1","service":"service 1","type":"downtime"}
`
	if result != expected {
		t.Errorf("The result did not match the expected. Result: %sExpected: %s", result, expected)
	}
}
コード例 #4
0
ファイル: influx_test.go プロジェクト: Griesbacher/nagflux
func TestSanitizeInfluxInput(t *testing.T) {
	//t.Parallel()
	config.InitConfigFromString(`[Influx]
    Enabled = true
    Version = 0.9
    Address = "http://127.0.0.1:8086"
    Arguments = "precision=ms&u=root&p=root&db=nagflux"
    CreateDatabaseIfNotExists = true
    # leave empty to disable
    NastyString = "§"
    NastyStringToReplace = "SS"
    HostcheckAlias = "hostcheck"
`)
	for _, data := range SanitizeInfluxData {
		actual := SanitizeInfluxInput(data.input)
		if actual != data.output {
			t.Errorf("SanitizeInfluxData(%s): expected: %s, actual: %s", data.input, data.output, actual)
		}
	}
}