예제 #1
0
파일: es.go 프로젝트: nwilkens/graphite-ng
func IsEsMetric(name string) (found bool, err error) {
	out, err := core.SearchUri("carbon-es", "datapoint", fmt.Sprintf("metric:%s&size=1", name), "", 0)
	if err != nil {
		return false, errors.New(fmt.Sprintf("error checking ES for %s: %s", name, err.Error()))
	}
	return (out.Hits.Total > 0), nil
}
예제 #2
0
파일: publish.go 프로젝트: Bengt/packetbeat
func (publisher *PublisherType) UpdateTopology() {

	DEBUG("publish", "Updating Topology")

	// get all agents IPs from Elasticsearch
	TopologyMapTmp := make(map[string]string)
	res, err := core.SearchUri("packetbeat-topology", "server-ip", nil)
	if err == nil {
		for _, server := range res.Hits.Hits {
			var top Topology
			err = json.Unmarshal([]byte(*server.Source), &top)
			if err != nil {
				ERR("json.Unmarshal fails with: %s", err)
			}
			// add mapping
			TopologyMapTmp[top.Ip] = top.Name
		}
	} else {
		ERR("core.SearchRequest fails with: %s", err)
	}

	// update topology map
	publisher.TopologyMap = TopologyMapTmp

	DEBUG("publish", "[%s] Map: %s", publisher.name, publisher.TopologyMap)
}
예제 #3
0
파일: es.go 프로젝트: simonz05/graphite-ng
func (e Es) Has(name string) (found bool, err error) {
	out, err := core.SearchUri("carbon-es", "datapoint", map[string]interface{}{"q": fmt.Sprintf("metric:%s", name), "size": "1"})
	if err != nil {
		return false, errors.New(fmt.Sprintf("error checking ES for %s: %s", name, err.Error()))
	}
	return (out.Hits.Total > 0), nil
}
예제 #4
0
// GetLog returns a whole Log line corresponding to ES :logid
func GetLog(logid string) Log {
	var log Log
	out, err := core.SearchUri("logs", "log", fmt.Sprintf("_id:%s", logid), "", 0)
	if err != nil {
		fmt.Println("Error: ", err)
		panic(err)
	}
	hits := out.Hits.Hits
	for _, hit := range hits {
		json.Unmarshal(hit.Source, &log)
		log.Id = hit.Id
	}
	return log
}
func TestSearchRequestQueryString(t *testing.T) {
	out, err := core.SearchUri("github", "", map[string]interface{}{"q": "actor:a*"})
	expectedHits := 621
	assert.T(t, &out != nil && err == nil, "Should get docs")
	assert.T(t, out.Hits.Total == expectedHits, fmt.Sprintf("Should have %v hits but was %v", expectedHits, out.Hits.Total))
}
예제 #6
0
func TestSearchRequestQueryString(t *testing.T) {
	out, err := core.SearchUri("github", "", "actor:a*", "", 0)
	//log.Println(out)
	assert.T(t, &out != nil && err == nil, "Should get docs")
	assert.T(t, out.Hits.Total == 616, fmt.Sprintf("Should have 616 hits but was %v", out.Hits.Total))
}