1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mockbeat.go 918 Bytes
一键复制 编辑 原始数据 按行查看 历史
Steffen Siering 提交于 2016-07-12 15:42 . Simplify Beater interface (#2003)
package mock
import (
"time"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/publisher"
)
///*** Mock Beat Setup ***///
var Version = "9.9.9"
var Name = "mockbeat"
type Mockbeat struct {
done chan struct{}
client publisher.Client
}
// Creates beater
func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) {
return &Mockbeat{
done: make(chan struct{}),
}, nil
}
/// *** Beater interface methods ***///
func (mb *Mockbeat) Run(b *beat.Beat) error {
mb.client = b.Publisher.Connect()
// Wait until mockbeat is done
mb.client.PublishEvent(common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "mock",
"message": "Mockbeat is alive!",
})
<-mb.done
return nil
}
func (mb *Mockbeat) Stop() {
logp.Info("Mockbeat Stop")
mb.client.Close()
close(mb.done)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.6.9

搜索帮助