forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockbeat.go
51 lines (40 loc) · 864 Bytes
/
mockbeat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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{}
}
// 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 {
client, err := b.Publisher.Connect()
if err != nil {
return err
}
// Wait until mockbeat is done
go 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")
close(mb.done)
}