This repository has been archived by the owner on Jun 19, 2019. It is now read-only.
/
scamp_requester.go
78 lines (63 loc) · 1.68 KB
/
scamp_requester.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package heka_scamp
import (
"fmt"
"errors"
)
import "github.com/gudtech/scamp-go/scamp"
import "github.com/mozilla-services/heka/pipeline"
type SCAMPOutputPluginConfig struct {
Service string `toml:"service"`
Action string `toml:"action"`
}
type SCAMPOutputPlugin struct {
conf *SCAMPOutputPluginConfig
client *scamp.Client
}
func (sop *SCAMPOutputPlugin) ConfigStruct() interface{} {
fmt.Println("ConfigStruct")
return &SCAMPOutputPluginConfig {
Service: ":30101",
Action: "Test.test", // TODO no smart default for this
}
}
func (sop *SCAMPOutputPlugin) Init(config interface{}) (err error) {
scamp.Initialize(scamp.DefaultConfigPath)
sop.conf = config.(*SCAMPOutputPluginConfig)
scamp.Info.Printf( "Connecting to %s\n", sop.conf.Service )
sop.client,err = scamp.Dial(sop.conf.Service)
if err != nil {
return
}
return
}
func (sop *SCAMPOutputPlugin) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error){
var pack *pipeline.PipelinePack
// We have no default encoder
if or.Encoder() == nil {
return errors.New("Encoder required.")
}
for pack = range or.InChan() {
scamp.Info.Printf("received pipeline pack")
encoded,err := or.Encode(pack) // pack.Message.GetPayload()
if err == nil {
scamp.Info.Printf("payload: %s", encoded)
msg := scamp.NewMessage()
msg.SetEnvelope(scamp.ENVELOPE_JSON)
msg.SetAction(sop.conf.Action)
msg.SetVersion(1)
msg.Write(encoded)
}
pack.Recycle(err)
}
fmt.Println("sup from end of for loop in Run")
return
}
func (sop *SCAMPOutputPlugin) CleanUp() {
fmt.Println("sup from cleanup")
return
}
func init(){
pipeline.RegisterPlugin("ScampOutput", func() interface{} {
return new(SCAMPOutputPlugin)
})
}