1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mockbeat.go 923 Bytes
一键复制 编辑 原始数据 按行查看 历史
package mock
import (
"time"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
///*** Mock Beat Setup ***///
var Version = "9.9.9"
var Name = "mockbeat"
type Mockbeat struct {
done chan struct{}
client beat.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 {
var err error
mb.client, err = b.Publisher.Connect()
if err != nil {
return err
}
// Wait until mockbeat is done
mb.client.Publish(beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"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/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.0.0-rc1

搜索帮助