-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
57 lines (51 loc) · 1.32 KB
/
plugin.go
File metadata and controls
57 lines (51 loc) · 1.32 KB
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 qhandler_log
import (
"fmt"
"github.com/zpatrick/go-config"
"github.com/qframe/types/qchannel"
"github.com/qframe/types/plugin"
"github.com/qframe/types/constants"
"github.com/qframe/types/messages"
"reflect"
"github.com/qframe/cache-inventory"
"strings"
)
const (
version = "0.2.1"
pluginTyp = qtypes_constants.HANDLER
pluginPkg = "log"
)
type Plugin struct {
*qtypes_plugin.Plugin
}
func New(qChan qtypes_qchannel.QChan, cfg *config.Config, name string) (Plugin, error) {
p := Plugin{
Plugin: qtypes_plugin.NewNamedPlugin(qChan, cfg, pluginTyp, pluginPkg, name, version),
}
p.Version = version
p.Name = name
return p, nil
}
// Run fetches everything from the Data channel and flushes it to stdout
func (p *Plugin) Run() {
p.Log("notice", fmt.Sprintf("Start log handler v%s", p.Version))
bg := p.QChan.Data.Join()
for {
select {
case val := <-bg.Read:
switch val.(type) {
// TODO: That has to be an interface!
case qtypes_messages.Message:
qm := val.(qtypes_messages.Message)
if qm.StopProcessing(p.Plugin, false) {
continue
}
p.Log("info" , fmt.Sprintf("%-15s : %s", strings.Join(qm.SourcePath, "->"), qm.Msg))
case qcache_inventory.ContainerRequest:
continue
default:
p.Log("info", fmt.Sprintf("Dunno type '%s': %v", reflect.TypeOf(val), val))
}
}
}
}