-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (69 loc) · 1.59 KB
/
main.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
package main
import (
"encoding/xml"
"flag"
"log"
"time"
"github.com/agalue/onms-sink-send/client"
"github.com/agalue/onms-sink-send/model"
)
func main() {
cli := new(client.KafkaProducer)
flag.StringVar(&cli.Brokers, "brokers", "127.0.0.1:9092", "The Kafka Brokers to connect to, as a comma separated list")
flag.StringVar(&cli.Topic, "topic", "OpenNMS.Sink.Events", "The Sink API topic for OpenNMS Events")
flag.IntVar(&cli.MaxBufferSize, "bufferSize", 1024, "Maximum Sink Buffer Size")
flag.Parse()
if err := cli.Connect(); err != nil {
panic(err)
}
defer cli.Close()
event := &model.Event{
UEI: "uei.opennms.org/traps/sample",
EventTime: &model.Time{Time: time.Now()},
NodeID: 10,
Interface: "127.0.0.1",
Source: "External",
Severity: "Warning",
Mask: &model.Mask{
Elements: []model.MaskElement{
{
MEname: "id",
MEvalue: []string{".1.2.3.4.5.6.7"},
},
{
MEname: "generic",
MEvalue: []string{"6"},
},
{
MEname: "specific",
MEvalue: []string{"1"},
},
},
},
LogMsg: &model.LogMsg{
Destination: "donotpersist",
Content: "This is a test",
},
Descr: "This is a test",
Parameters: &model.Parms{
Params: []model.Param{
{
Name: "owner",
Value: "agalue",
},
},
},
AlarmData: &model.AlarmData{
ReductionKey: "uei.opennms.org/traps/sample::10",
AlarmType: 3,
},
}
bytes, err := xml.MarshalIndent(event, "", " ")
if err != nil {
panic(err)
}
log.Printf("Event Payload: %s", string(bytes))
if err := cli.Publish(bytes); err != nil {
panic(err)
}
}