-
Notifications
You must be signed in to change notification settings - Fork 7
/
events.go
196 lines (185 loc) · 4.92 KB
/
events.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package main
/*
#include <stdbool.h>
#include <stdint.h>
*/
import "C"
import (
"runtime/cgo"
"time"
"github.com/gwos/tcg/sdk/transit"
)
// CreateEvent creates an object used in EventsRequest.
// It returns a handle that should be deleted after use with DeleteHandle.
//
//export CreateEvent
func CreateEvent(
appType, host, monStatus *C.char,
sec, nsec C.longlong,
) C.uintptr_t {
p := new(transit.GroundworkEvent)
p.AppType = C.GoString(appType)
p.Host = C.GoString(host)
p.MonitorStatus = C.GoString(monStatus)
p.ReportDate = transit.NewTimestamp()
p.ReportDate.Time = time.Unix(int64(sec), int64(nsec)).UTC()
return C.uintptr_t(cgo.NewHandle(p))
}
// SetEventAttrs sets attributes on target.
// It skips NULL params.
//
//export SetEventAttrs
func SetEventAttrs(target C.uintptr_t,
appType,
host,
monStatus,
// Optional attributes
device,
service,
opStatus,
severity,
appSeverity,
component,
subComponent,
priority,
typeRule,
textMessage,
// Update level attributes
appName,
consolidationName,
errorType,
loggerName,
logType,
monServer *C.char,
) {
attr := func(k *string, v *C.char) {
if v != nil {
*k = C.GoString(v)
}
}
h := cgo.Handle(target)
if hv, ok := h.Value().(*transit.GroundworkEvent); ok {
attr(&hv.AppType, appType)
attr(&hv.Host, host)
attr(&hv.MonitorStatus, monStatus)
// Optional attributes
attr(&hv.Device, device)
attr(&hv.Service, service)
attr(&hv.OperationStatus, opStatus)
attr(&hv.Severity, severity)
attr(&hv.ApplicationSeverity, appSeverity)
attr(&hv.Component, component)
attr(&hv.SubComponent, subComponent)
attr(&hv.Priority, priority)
attr(&hv.TypeRule, typeRule)
attr(&hv.TextMessage, textMessage)
// Update level attributes
attr(&hv.ApplicationName, appName)
attr(&hv.ConsolidationName, consolidationName)
attr(&hv.ErrorType, errorType)
attr(&hv.LoggerName, loggerName)
attr(&hv.LogType, logType)
attr(&hv.MonitorServer, monServer)
}
}
// SetEventDates sets date attributes on target.
// It skips NULL params.
//
//export SetEventDates
func SetEventDates(target C.uintptr_t,
reportDateSec, reportDateNsec,
lastInsertDateSec, lastInsertDateNsec *C.longlong,
) {
attr := func(ts **transit.Timestamp, sec, nsec *C.longlong) {
if sec == nil && nsec == nil {
return
}
s, ns := int64(0), int64(0)
if sec != nil {
s = int64(*sec)
}
if nsec != nil {
ns = int64(*nsec)
}
t := transit.NewTimestamp()
t.Time = time.Unix(s, ns).UTC()
*ts = t
}
h := cgo.Handle(target)
if hv, ok := h.Value().(*transit.GroundworkEvent); ok {
attr(&hv.ReportDate, reportDateSec, reportDateNsec)
attr(&hv.LastInsertDate, lastInsertDateSec, lastInsertDateNsec)
}
}
// CreateEventsRequest creates payload for SendEvents API.
// It returns a handle that should be deleted after use with DeleteHandle.
//
//export CreateEventsRequest
func CreateEventsRequest() C.uintptr_t {
p := new(transit.GroundworkEventsRequest)
p.Events = []transit.GroundworkEvent{}
return C.uintptr_t(cgo.NewHandle(p))
}
// AddEvent appends Event value to target.
//
//export AddEvent
func AddEvent(target C.uintptr_t, value C.uintptr_t) {
h, h2 := cgo.Handle(target), cgo.Handle(value)
if hv, ok := h.Value().(*transit.GroundworkEventsRequest); ok {
if hv2, ok := h2.Value().(*transit.GroundworkEvent); ok {
hv.Events = append(hv.Events, *hv2)
}
}
}
// CreateEventsAckRequest creates payload for SendEventsAck API.
// It returns a handle that should be deleted after use with DeleteHandle.
//
//export CreateEventsAckRequest
func CreateEventsAckRequest() C.uintptr_t {
p := new(transit.GroundworkEventsAckRequest)
p.Acks = []transit.GroundworkEventAck{}
return C.uintptr_t(cgo.NewHandle(p))
}
// AddEventAck appends EventAck value to target.
//
//export AddEventAck
func AddEventAck(
target C.uintptr_t,
appType, host, service, ackBy, ackComment *C.char,
) {
h := cgo.Handle(target)
if hv, ok := h.Value().(*transit.GroundworkEventsAckRequest); ok {
p := new(transit.GroundworkEventAck)
p.AppType = C.GoString(appType)
p.Host = C.GoString(host)
p.Service = C.GoString(service)
p.AcknowledgedBy = C.GoString(ackBy)
p.AcknowledgeComment = C.GoString(ackComment)
hv.Acks = append(hv.Acks, *p)
}
}
// CreateEventsUnackRequest creates payload for SendEventsUnack API.
// It returns a handle that should be deleted after use with DeleteHandle.
//
//export CreateEventsUnackRequest
func CreateEventsUnackRequest() C.uintptr_t {
p := new(transit.GroundworkEventsUnackRequest)
p.Unacks = []transit.GroundworkEventUnack{}
return C.uintptr_t(cgo.NewHandle(p))
}
// AddEventUnack appends EventUnack value to target.
//
//export AddEventUnack
func AddEventUnack(
target C.uintptr_t,
appType, host, service *C.char,
) {
h := cgo.Handle(target)
if hv, ok := h.Value().(*transit.GroundworkEventsUnackRequest); ok {
p := new(transit.GroundworkEventUnack)
p.AppType = C.GoString(appType)
p.Host = C.GoString(host)
p.Service = C.GoString(service)
hv.Unacks = append(hv.Unacks, *p)
}
}