forked from StephanU/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
63 lines (50 loc) · 1.11 KB
/
data.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
package pool_disk
import (
"encoding/json"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
type Stats struct {
BytesUsed int64 `json:"bytes_used"`
MaxAvail int64 `json:"max_avail"`
Objects int64 `json:"objects"`
KbUsed int64 `json:"kb_used"`
}
type Pool struct {
Id int64 `json:"id"`
Name string `json:"name"`
Stats Stats `json:"stats"`
}
type Output struct {
Pools []Pool `json:"pools"`
}
type DfRequest struct {
Status string `json:"status"`
Output Output `json:"output"`
}
func eventsMapping(content []byte) []common.MapStr {
var d DfRequest
err := json.Unmarshal(content, &d)
if err != nil {
logp.Err("Error: ", err)
}
events := []common.MapStr{}
for _, Pool := range d.Output.Pools {
event := common.MapStr{
"name": Pool.Name,
"id": Pool.Id,
"stats": common.MapStr{
"used": common.MapStr{
"bytes": Pool.Stats.BytesUsed,
"kb": Pool.Stats.KbUsed,
},
"available": common.MapStr{
"bytes": Pool.Stats.MaxAvail,
},
"objects": Pool.Stats.Objects,
},
}
events = append(events, event)
}
return events
}