forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mockbeat.go
57 lines (45 loc) · 993 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
52
53
54
55
56
57
package mock
import (
"time"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"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() *Mockbeat {
return &Mockbeat{
done: make(chan struct{}),
}
}
/// *** Beater interface methods ***///
func (mb *Mockbeat) Config(b *beat.Beat) error {
return nil
}
func (mb *Mockbeat) Setup(b *beat.Beat) error {
mb.client = b.Publisher.Connect()
return nil
}
func (mb *Mockbeat) Run(b *beat.Beat) error {
// 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) Cleanup(b *beat.Beat) error {
return nil
}
func (mb *Mockbeat) Stop() {
close(mb.done)
mb.client.Close()
}