forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
41 lines (33 loc) · 898 Bytes
/
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
package container
import (
"time"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/module/docker"
dc "github.com/fsouza/go-dockerclient"
)
func eventsMapping(containersList []dc.APIContainers) []common.MapStr {
myEvents := []common.MapStr{}
for _, container := range containersList {
myEvents = append(myEvents, eventMapping(&container))
}
return myEvents
}
func eventMapping(cont *dc.APIContainers) common.MapStr {
event := common.MapStr{
"created": common.Time(time.Unix(cont.Created, 0)),
"id": cont.ID,
"name": docker.ExtractContainerName(cont.Names),
"command": cont.Command,
"image": cont.Image,
"size": common.MapStr{
"root_fs": cont.SizeRootFs,
"rw": cont.SizeRw,
},
"status": cont.Status,
}
labels := docker.DeDotLabels(cont.Labels)
if len(labels) > 0 {
event["labels"] = labels
}
return event
}