コード例 #1
0
ファイル: esslack_test.go プロジェクト: amundi/eschecker
func Test_getRequest(t *testing.T) {
	eslog.Init()
	token := "hellongi123"
	g_slack.token = token
	expectedRequest := "https://slack.com/api/chat.postMessage?username=test&token=" +
		token + "&channel=%23testchannel&pretty=1&text=Salut+les+copains+c%27est+moi"
	p := NewSlackMsg("Salut les copains c'est moi", "test", "#testchannel")
	assert.Equal(t, expectedRequest, p.GetSlackRequest())

	expectedRequest = "https://slack.com/api/chat.postMessage?username=Roberto&token=" +
		token + "&channel=%40lolo&pretty=1&text=Les+sanglots+longs+des+violons"
	p = NewSlackMsg("Les sanglots longs des violons", "Roberto", "@lolo")
	assert.Equal(t, expectedRequest, p.GetSlackRequest())
}
コード例 #2
0
ファイル: main.go プロジェクト: amundi/eschecker
func main() {
	//get flags and config
	env := new(Env)
	env.getFlags()
	env.getConfig()

	//semaphore to queue SendRequest, or else timeout gets wrong
	env.semaphore = make(chan struct{}, 1)

	//init log, if silent, nothing will be printed on stdout
	if *env.flagsilent {
		eslog.InitSilent()
	} else {
		eslog.Init()
	}

	//init rotating log if necessary
	env.initRotatingLog()

	//init slack, mail etc.
	env.initIntegrations()

	//get queries from yaml, if flag -c activated check them and exit
	env.parseQueries()

	//init the stats for every queries and the dispatcher for workers
	initStats()
	worker.StartDispatcher(getNbWorkers())

	//connect to the elasticsearch cluster via env.client
	env.connect()

	for name, check := range g_queryList {
		go launchQuery(check, name, env)
	}

	if isServer() {
		launchServer()
	} else {
		//select to wait forever
		select {}
	}
}
コード例 #3
0
ファイル: autoquery_test.go プロジェクト: amundi/eschecker
func TestAutoQuery_BuildQuery(t *testing.T) {
	eslog.Init()
	test := new(autoQuery)
	test.queryInfo = &config.QueryInfo{
		Type: "boolfilter",
		Clauses: map[string]interface{}{
			"must": []interface{}{
				map[interface{}]interface{}{"term": []interface{}{"Value", 146.5}},
				map[interface{}]interface{}{"term": []interface{}{"othervalue", "testTest"}},
				map[interface{}]interface{}{"range": []interface{}{"Timestamp", "lt", "now-1h"}},
			},
			"must_not": []interface{}{
				map[interface{}]interface{}{"term": []interface{}{"status", "OK"}},
			},
		},
	}
	realQuery := elastic.NewBoolFilter().Must(
		elastic.NewTermFilter("Value", 146.5),
		elastic.NewTermFilter("othervalue", "testTest"),
		elastic.NewRangeFilter("Timestamp").Lt("now-1h"),
	).MustNot(
		elastic.NewTermFilter("status", "OK"),
	)

	myQuery, err := test.BuildQuery()
	assert.Equal(t, nil, err)
	assert.Equal(t, realQuery, myQuery)

	test.queryInfo = &config.QueryInfo{
		Type: "boolfilter",
		Clauses: map[string]interface{}{
			"muts": []interface{}{
				map[interface{}]interface{}{"term": []interface{}{"Value", 146.5}},
				map[interface{}]interface{}{"term": []interface{}{"othervalue", "testTest"}},
			},
		},
	}
	myQuery, err = test.BuildQuery()
	assert.NotNil(t, err)
}