-
Notifications
You must be signed in to change notification settings - Fork 3
/
stdout.go
49 lines (41 loc) · 1.01 KB
/
stdout.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 sinks
import (
"encoding/json"
"github.com/Pirionfr/goDcCrypto/crypto"
"github.com/Pirionfr/lookatch-agent/events"
log "github.com/sirupsen/logrus"
)
// Stdout representation of sink
type Stdout struct {
*Sink
}
// StdoutType type of sink
const StdoutType = "Stdout"
// NewStdout create new stdout sink
func NewStdout(s *Sink) (SinkI, error) {
return &Stdout{s}, nil
}
// Start stdout sink
func (s *Stdout) Start(i ...interface{}) (err error) {
go func(messages chan events.LookatchEvent) {
for message := range messages {
var bytes []byte
bytes, err = json.Marshal(message.Payload)
if err != nil {
log.WithError(err).Error("json.Marshal()")
return
}
msg := string(bytes)
if s.EncryptionKey != "" {
msg, err = crypto.EncryptString(string(bytes), s.EncryptionKey)
if err != nil {
log.WithError(err).Error("error while encrypting event")
return
}
}
log.WithField("message", msg).Info("Stdout Sink")
s.SendCommit(message.Payload)
}
}(s.In)
return
}