2020-03-13 09:40:00 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"background/config"
|
|
|
|
"background/logs"
|
|
|
|
"gopkg.in/olivere/elastic.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ElkEngine struct {
|
|
|
|
cli *elastic.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var gElkEngine ElkEngine
|
|
|
|
|
|
|
|
func InitELK() {
|
|
|
|
var e error
|
|
|
|
elkconf := config.GetElkConfig()
|
|
|
|
gElkEngine.cli,e = elastic.NewClient(
|
|
|
|
elastic.SetURL(elkconf.Address),
|
|
|
|
// Must turn off sniff in docker
|
|
|
|
elastic.SetSniff(false),)
|
|
|
|
if nil != e{
|
|
|
|
logs.Error(e.Error())
|
|
|
|
gElkEngine.cli = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 15:13:04 +00:00
|
|
|
func (*ElkEngine)Search(index string) (error) {
|
2020-03-13 11:44:32 +00:00
|
|
|
if nil != gElkEngine.cli{
|
2020-03-13 09:40:00 +00:00
|
|
|
|
2020-03-13 11:44:32 +00:00
|
|
|
}
|
2020-03-13 09:40:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|