-
Notifications
You must be signed in to change notification settings - Fork 17
/
info.go
386 lines (346 loc) · 14.1 KB
/
info.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package gorocket
import (
"fmt"
"net/http"
"time"
)
type RespInfo struct {
Version string `json:"version"`
Info struct {
Version string `json:"version"`
Build Build `json:"build"`
Commit Commit `json:"commit"`
MarketplaceAPIVersion string `json:"marketplaceApiVersion"`
} `json:"info"`
Success bool `json:"success"`
}
type Build struct {
Date time.Time `json:"date"`
NodeVersion string `json:"nodeVersion"`
Arch string `json:"arch"`
Platform string `json:"platform"`
OsRelease string `json:"osRelease"`
TotalMemory int64 `json:"totalMemory"`
FreeMemory int `json:"freeMemory"`
Cpus int `json:"cpus"`
}
type Commit struct {
Hash string `json:"hash"`
Date string `json:"date"`
Author string `json:"author"`
Subject string `json:"subject"`
Tag string `json:"tag"`
Branch string `json:"branch"`
}
type RespDirectory struct {
Result []DirectoryResult `json:"result"`
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
Success bool `json:"success"`
}
type DirectoryResult struct {
ID string `json:"_id"`
CreatedAt time.Time `json:"createdAt"`
Emails []Email `json:"emails"`
Name string `json:"name"`
Username string `json:"username"`
AvatarETag string `json:"avatarETag"`
}
type Result struct {
ID string `json:"_id"`
Ts time.Time `json:"ts"`
T string `json:"t"`
Name string `json:"name"`
UsersCount int `json:"usersCount"`
Default bool `json:"default"`
LastMessage LastMessage `json:"lastMessage"`
}
type LastMessage struct {
ID string `json:"_id"`
Alias string `json:"alias"`
Msg string `json:"msg"`
Attachments []interface{} `json:"attachments"`
ParseUrls bool `json:"parseUrls"`
Groupable bool `json:"groupable"`
Ts time.Time `json:"ts"`
U U `json:"u"`
Rid string `json:"rid"`
UpdatedAt time.Time `json:"_updatedAt"`
Mentions []interface{} `json:"mentions"`
Channels []interface{} `json:"channels"`
}
type U struct {
ID string `json:"_id"`
Username string `json:"username"`
Name string `json:"name,omitempty"`
}
type RespSpotlight struct {
Users []UsersInfo `json:"users"`
Rooms []RoomsInfo `json:"rooms"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
type UsersInfo struct {
ID string `json:"_id"`
Status string `json:"status"`
Name string `json:"name"`
Username string `json:"username"`
StatusText string `json:"statusText"`
AvatarETag string `json:"avatarETag,omitempty"`
}
type RoomsInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
T string `json:"t"`
LastMessage LastMessage `json:"lastMessage"`
}
type RespStatistics struct {
ID string `json:"_id"`
Wizard Wizard `json:"wizard"`
UniqueID string `json:"uniqueId"`
InstalledAt time.Time `json:"installedAt"`
Version string `json:"version"`
TotalUsers int `json:"totalUsers"`
ActiveUsers int `json:"activeUsers"`
ActiveGuests int `json:"activeGuests"`
NonActiveUsers int `json:"nonActiveUsers"`
AppUsers int `json:"appUsers"`
OnlineUsers int `json:"onlineUsers"`
AwayUsers int `json:"awayUsers"`
TotalConnectedUsers int `json:"totalConnectedUsers"`
OfflineUsers int `json:"offlineUsers"`
TotalRooms int `json:"totalRooms"`
TotalChannels int `json:"totalChannels"`
TotalPrivateGroups int `json:"totalPrivateGroups"`
TotalDirect int `json:"totalDirect"`
TotalLivechat int `json:"totalLivechat"`
TotalDiscussions int `json:"totalDiscussions"`
TotalThreads int `json:"totalThreads"`
TotalLivechatVisitors int `json:"totalLivechatVisitors"`
TotalLivechatAgents int `json:"totalLivechatAgents"`
LivechatEnabled bool `json:"livechatEnabled"`
TotalChannelMessages int `json:"totalChannelMessages"`
TotalPrivateGroupMessages int `json:"totalPrivateGroupMessages"`
TotalDirectMessages int `json:"totalDirectMessages"`
TotalLivechatMessages int `json:"totalLivechatMessages"`
TotalMessages int `json:"totalMessages"`
FederatedServers int `json:"federatedServers"`
FederatedUsers int `json:"federatedUsers"`
LastLogin time.Time `json:"lastLogin"`
LastMessageSentAt time.Time `json:"lastMessageSentAt"`
LastSeenSubscription time.Time `json:"lastSeenSubscription"`
Os Os `json:"os"`
Process Process `json:"process"`
Deploy Deploy `json:"deploy"`
EnterpriseReady bool `json:"enterpriseReady"`
UploadsTotal int `json:"uploadsTotal"`
UploadsTotalSize int `json:"uploadsTotalSize"`
Migration Migration `json:"migration"`
InstanceCount int `json:"instanceCount"`
OplogEnabled bool `json:"oplogEnabled"`
MongoVersion string `json:"mongoVersion"`
MongoStorageEngine string `json:"mongoStorageEngine"`
UniqueUsersOfYesterday Stats `json:"uniqueUsersOfYesterday"`
UniqueUsersOfLastMonth Stats `json:"uniqueUsersOfLastMonth"`
UniqueDevicesOfYesterday Stats `json:"uniqueDevicesOfYesterday"`
UniqueDevicesOfLastMonth Stats `json:"uniqueDevicesOfLastMonth"`
UniqueOSOfYesterday Stats `json:"uniqueOSOfYesterday"`
UniqueOSOfLastMonth Stats `json:"uniqueOSOfLastMonth"`
Apps Apps `json:"apps"`
Integrations Integrations `json:"integrations"`
PushQueue int `json:"pushQueue"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"_updatedAt"`
Success bool `json:"success"`
}
type Wizard struct {
OrganizationType string `json:"organizationType"`
Industry string `json:"industry"`
Size string `json:"size"`
Country string `json:"country"`
Language string `json:"language"`
ServerType string `json:"serverType"`
RegisterServer bool `json:"registerServer"`
}
type Os struct {
Type string `json:"type"`
Platform string `json:"platform"`
Arch string `json:"arch"`
Release string `json:"release"`
Uptime int `json:"uptime"`
Loadavg []float64 `json:"loadavg"`
Totalmem int64 `json:"totalmem"`
Freemem int `json:"freemem"`
Cpus []Cpus `json:"cpus"`
}
type Cpus struct {
Model string `json:"model"`
Speed int `json:"speed"`
Times Times `json:"times"`
}
type Times struct {
User int `json:"user"`
Nice int `json:"nice"`
Sys int `json:"sys"`
Idle int `json:"idle"`
Irq int `json:"irq"`
}
type Process struct {
NodeVersion string `json:"nodeVersion"`
Pid int `json:"pid"`
Uptime float64 `json:"uptime"`
}
type Apps struct {
EngineVersion string `json:"engineVersion"`
Enabled bool `json:"enabled"`
TotalInstalled int `json:"totalInstalled"`
TotalActive int `json:"totalActive"`
}
type Integrations struct {
TotalIntegrations int `json:"totalIntegrations"`
TotalIncoming int `json:"totalIncoming"`
TotalIncomingActive int `json:"totalIncomingActive"`
TotalOutgoing int `json:"totalOutgoing"`
TotalOutgoingActive int `json:"totalOutgoingActive"`
TotalWithScriptEnabled int `json:"totalWithScriptEnabled"`
}
type Stats struct {
Year int `json:"year"`
Month int `json:"month"`
Day int `json:"day"`
Data []interface{} `json:"data"`
}
type Migration struct {
ID string `json:"_id"`
Locked bool `json:"locked"`
Version int `json:"version"`
}
type Deploy struct {
Method string `json:"method"`
Platform string `json:"platform"`
}
type RespStatisticsList struct {
Statistics []struct {
ID string `json:"_id"`
Wizard Wizard `json:"wizard"`
UniqueID string `json:"uniqueId"`
InstalledAt time.Time `json:"installedAt"`
Version string `json:"version"`
TotalUsers int `json:"totalUsers"`
ActiveUsers int `json:"activeUsers"`
ActiveGuests int `json:"activeGuests"`
NonActiveUsers int `json:"nonActiveUsers"`
AppUsers int `json:"appUsers"`
OnlineUsers int `json:"onlineUsers"`
AwayUsers int `json:"awayUsers"`
TotalConnectedUsers int `json:"totalConnectedUsers"`
OfflineUsers int `json:"offlineUsers"`
TotalRooms int `json:"totalRooms"`
TotalChannels int `json:"totalChannels"`
TotalPrivateGroups int `json:"totalPrivateGroups"`
TotalDirect int `json:"totalDirect"`
TotalLivechat int `json:"totalLivechat"`
TotalDiscussions int `json:"totalDiscussions"`
TotalThreads int `json:"totalThreads"`
TotalLivechatVisitors int `json:"totalLivechatVisitors"`
TotalLivechatAgents int `json:"totalLivechatAgents"`
TotalChannelMessages int `json:"totalChannelMessages"`
TotalPrivateGroupMessages int `json:"totalPrivateGroupMessages"`
TotalDirectMessages int `json:"totalDirectMessages"`
TotalLivechatMessages int `json:"totalLivechatMessages"`
TotalMessages int `json:"totalMessages"`
FederatedServers int `json:"federatedServers"`
FederatedUsers int `json:"federatedUsers"`
Os Os `json:"os"`
Process Process `json:"process"`
Deploy Deploy `json:"deploy"`
EnterpriseReady bool `json:"enterpriseReady"`
UploadsTotal int `json:"uploadsTotal"`
UploadsTotalSize int `json:"uploadsTotalSize"`
Migration Migration `json:"migration"`
InstanceCount int `json:"instanceCount"`
OplogEnabled bool `json:"oplogEnabled"`
MongoVersion string `json:"mongoVersion"`
MongoStorageEngine string `json:"mongoStorageEngine"`
UniqueUsersOfYesterday Stats `json:"uniqueUsersOfYesterday"`
UniqueUsersOfLastMonth Stats `json:"uniqueUsersOfLastMonth"`
UniqueDevicesOfYesterday Stats `json:"uniqueDevicesOfYesterday"`
UniqueDevicesOfLastMonth Stats `json:"uniqueDevicesOfLastMonth"`
UniqueOSOfYesterday Stats `json:"uniqueOSOfYesterday"`
UniqueOSOfLastMonth Stats `json:"uniqueOSOfLastMonth"`
Apps Apps `json:"apps"`
Integrations Integrations `json:"integrations"`
PushQueue int `json:"pushQueue"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"_updatedAt"`
LivechatEnabled bool `json:"livechatEnabled,omitempty"`
LastLogin time.Time `json:"lastLogin,omitempty"`
LastMessageSentAt time.Time `json:"lastMessageSentAt,omitempty"`
LastSeenSubscription time.Time `json:"lastSeenSubscription,omitempty"`
} `json:"statistics"`
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
Success bool `json:"success"`
}
// Info returns information about the server
func (c *Client) Info() (*RespInfo, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/info", c.baseURL), nil)
if err != nil {
return nil, err
}
res := RespInfo{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
// Directory returns a list of channels
func (c *Client) Directory() (*RespDirectory, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/directory", c.baseURL, c.apiVersion), nil)
if err != nil {
return nil, err
}
res := RespDirectory{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
// Spotlight returns a list of users and rooms that match the provided query
func (c *Client) Spotlight(query string) (*RespSpotlight, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/spotlight?query=%s", c.baseURL, c.apiVersion, query), nil)
if err != nil {
return nil, err
}
res := RespSpotlight{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
// Statistics returns statistics about the server
func (c *Client) Statistics() (*RespStatistics, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/statistics", c.baseURL, c.apiVersion), nil)
if err != nil {
return nil, err
}
res := RespStatistics{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
// StatisticsList returns a list of statistics
func (c *Client) StatisticsList() (*RespStatisticsList, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/statistics.list", c.baseURL, c.apiVersion), nil)
if err != nil {
return nil, err
}
res := RespStatisticsList{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}