forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockbeat.go
49 lines (38 loc) · 918 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
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)
}