This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.go
349 lines (290 loc) · 7.54 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package libwimark
import (
"encoding/json"
"errors"
"github.com/globalsign/mgo/bson"
)
type SystemEvent struct {
SystemEventObject
Timestamp int64 `json:"timestamp"`
Subject_id string `json:"subject_id"`
Level SystemEventLevel `json:"level"`
Description string `json:"description"`
}
func (event *SystemEvent) MarshalJSON() ([]byte, error) {
var b []byte
{
var err error
b, err = json.Marshal(event.SystemEventObject)
if err != nil {
return nil, err
}
}
var doc Document
{
var err = json.Unmarshal(b, &doc)
if err != nil {
return nil, err
}
}
doc["timestamp"] = event.Timestamp
doc["subject_id"] = event.Subject_id
doc["level"] = event.Level
doc["description"] = event.Description
return json.Marshal(doc)
}
func (event *SystemEvent) UnmarshalJSON(b []byte) error {
var doc map[string]json.RawMessage
var err = json.Unmarshal(b, &doc)
if err != nil {
return err
}
if doc == nil {
return nil
}
// may be there is a way how to make code more reusable
// don't have time to figure out
var tsRaw, tsExists = doc["timestamp"]
if tsExists {
var ts int64
var tsErr = json.Unmarshal(tsRaw, &ts)
if tsErr == nil {
event.Timestamp = ts
} else {
return tsErr
}
}
delete(doc, "timestamp")
var subRaw, subExists = doc["subject_id"]
if subExists {
var subject_id string
var subErr = json.Unmarshal(subRaw, &subject_id)
if subErr == nil {
event.Subject_id = subject_id
} else {
return subErr
}
}
delete(doc, "subject_id")
var levelRaw, levelExists = doc["level"]
if levelExists {
var level SystemEventLevel
var levErr = json.Unmarshal(levelRaw, &level)
if levErr == nil {
event.Level = level
} else {
return levErr
}
}
delete(doc, "level")
var descRaw, descExists = doc["description"]
if descExists {
var desc string
var desErr = json.Unmarshal(descRaw, &desc)
if desErr == nil {
event.Description = desc
} else {
return desErr
}
}
delete(doc, "description")
var v, _ = json.Marshal(doc)
return event.SystemEventObject.UnmarshalJSON(v)
}
func (event *SystemEvent) GetBSON() (interface{}, error) {
var out bson.M
levelBson, err := event.Level.GetBSON()
if err != nil {
return nil, err
}
var obj_b []byte
{
var err error
obj_b, err = bson.Marshal(event.SystemEventObject)
if err != nil {
return nil, err
}
}
var obj bson.M
{
var err = bson.Unmarshal(obj_b, &obj)
if err != nil {
return nil, err
}
}
out = obj
out["timestamp"] = event.Timestamp
out["subject_id"] = event.Subject_id
out["level"] = levelBson
out["description"] = event.Description
return out, nil
}
func (event *SystemEvent) SetBSON(raw bson.Raw) error {
var in = map[string]bson.Raw{}
{
if err := raw.Unmarshal(&in); err != nil {
return err
}
}
//timestamp
{
var v, k_found = in["timestamp"]
if !k_found {
return errors.New("no timestamp found")
}
if err := v.Unmarshal(&event.Timestamp); err != nil {
return err
}
delete(in, "timestamp")
}
//subject_id
{
var v, k_found = in["subject_id"]
if !k_found {
return errors.New("no subject_id found")
}
if err := v.Unmarshal(&event.Subject_id); err != nil {
return err
}
delete(in, "subject_id")
}
//subject_id
{
var v, k_found = in["level"]
if !k_found {
return errors.New("no subject_id found")
}
if err := v.Unmarshal(&event.Level); err != nil {
return err
}
delete(in, "level")
}
//description
{
var v, k_found = in["description"]
if k_found {
if err := v.Unmarshal(&event.Description); err != nil {
return err
}
delete(in, "description")
}
}
var obj_b, mErr = bson.Marshal(in)
if mErr != nil {
return mErr
}
if err := bson.Unmarshal(obj_b, &event.SystemEventObject); err != nil {
return err
}
return nil
}
type CPEConnectedData struct {
Version
Template UUID `json:"template,omitempty"`
}
type MonitorRuleViolationData struct {
Cpe_id UUID `json:"cpe_id"`
Stat_id UUID `json:"stat_id"`
}
type ClientConnectedData struct {
Session_id string `json:"session_id"`
Cpe_id UUID `json:"cpe_id"`
Wlan_id UUID `json:"wlan_id"`
Radio_id string `json:"radio_id"`
//Freq string `json:"freq"`
}
type ClientDisconnectedData struct {
Session_id string `json:"session_id"`
Cpe_id UUID `json:"cpe_id"`
Wlan_id UUID `json:"wlan_id"`
Radio_id string `json:"radio_id"`
//Freq string `json:"freq"`
}
type CPEInterfaceStateData struct {
Interface string `json:"radio_id"`
State CPEInterfaceState `json:"state"`
}
type WLANCentrAccChangeData struct {
IsDeleted bool `json:"is_deleted"`
Radiuses []UUID `json:"radiuses"`
}
type ServiceFatalErrorData struct {
Sw_version string `json:"sw_version"`
Description string `json:"description"`
}
type ServiceConnectedData Version
type RRMStatusData struct {
Cpes []RRMCpeStatus `json:"cpes"`
}
type RRMCpeStatus struct {
CpeID UUID `json:"cpe_id"`
Radio string `json:"radio"`
Channel RRMChannel `json:"channel"`
Power int `json:"power"`
Error bool `json:"error"`
}
type FirmwareUploadedData struct {
CpeIDs []UUID `json:"cpe_ids"`
Url string `json:"url"`
Md5Sum string `json:"md5sum"`
Mode FirmwareUpdateMode `json:"mode"`
}
type CpeFirmwareData struct {
AvailableMd5 string `json:"available_md5"`
CurrentMd5 string `json:"current_md5"`
NewFirmware bool `json:"new_firmware"`
GoingToUpgrade bool `json:"going_to_upgrade"`
Error string `json:"error"`
}
type RadiusAccountingSendData struct {
RadiusList []Radius `json:"radius_list"`
Mirroring bool `json:"mirroring"`
Message RadiusMessageObject `json:"message"`
}
type ClientAuthorizationData struct {
Session string `json:"session_id,omitempty"`
MAC string `json:"mac"`
CPE string `json:"cpe_id,omitempty"`
WLAN string `json:"wlan_id,omitempty"`
NasID string `json:"nas_id,omitempty"`
LocID string `json:"loc_id,omitempty"`
Radio string `json:"radio_id,omitempty"` // from what -- ?
SessionTimeout int64 `json:"session_timeout,omitempty"`
AcctSessionID string `json:"acct_session_id,omitempty"`
UserName string `json:"username,omitempty"`
UserAgent string `json:"useragent,omitempty"`
AuthenType string `json:"authen_type,omitempty"`
AuthType string `json:"auth_type,omitempty"`
Method string `json:"method"` // HTTP or RADIUS
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Deauth bool `json:"deauth,omitempty"`
}
type DHCPAckData struct {
ClientAddr string `json:"client_addr"`
ClientMAC string `json:"client_mac"`
ServerAddr string `json:"server_addr"`
ServerMAC string `json:"server_mac"`
ServerHost string `json:"server_host"`
RouterAddrs []string `json:"router_addrs"`
Subnet string `json:"subnet"`
}
type UserAuthorizationSuccessData struct {
Username string `json:"username"`
Role string `json:"role"`
Location string `json:"location"`
}
type ClientAuthErrorData struct {
Session string `json:"session_id"`
MAC string `json:"mac"`
CPE string `json:"cpe_id"`
WLAN string `json:"wlan_id"`
NasID string `json:"nas_id"`
LocID string `json:"loc_id"`
Radio string `json:"radio_id"` // from what -- ?
SessionTimeout int64 `json:"session_timeout"`
UserName string `json:"username,omitempty"`
UserAgent string `json:"useragent,omitempty"`
AuthenType string `json:"authen_type,omitempty"`
AuthType string `json:"auth_type,omitempty"`
}