Example #1
0
func Test_DisplayPage(t *testing.T) {
	eslog.InitSilent()
	ts := httptest.NewServer(http.HandlerFunc(collectorDisplay))
	defer ts.Close()
	initStatsForTests1()
	worker.StartDispatcher(32)

	res, err := http.Get(ts.URL)
	assert.Nil(t, err)
	page, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	assert.Nil(t, err)
	expected := formatQueriesForLayout()
	assert.Equal(t, expected, string(page))
	worker.StopAllWorkers(32)
}
Example #2
0
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 {}
	}
}