代码拉取完成,页面将自动刷新
package docker
import (
"strings"
"github.com/fsouza/go-dockerclient"
"github.com/elastic/beats/libbeat/common"
)
type Container struct {
ID string
Name string
Labels common.MapStr
}
func (c *Container) ToMapStr() common.MapStr {
m := common.MapStr{
"id": c.ID,
"name": c.Name,
}
if len(c.Labels) > 0 {
m["labels"] = c.Labels
}
return m
}
func NewContainer(container *docker.APIContainers) *Container {
return &Container{
ID: container.ID,
Name: ExtractContainerName(container.Names),
Labels: DeDotLabels(container.Labels),
}
}
func ExtractContainerName(names []string) string {
output := names[0]
if len(names) > 1 {
for _, name := range names {
if strings.Count(output, "/") > strings.Count(name, "/") {
output = name
}
}
}
return strings.Trim(output, "/")
}
// DeDotLabels returns a new common.MapStr containing a copy of the labels
// where the dots in each label name have been changed to an underscore.
func DeDotLabels(labels map[string]string) common.MapStr {
outputLabels := common.MapStr{}
for k, v := range labels {
// This is necessary so that ES does not interpret '.' fields as new
// nested JSON objects, and also makes this compatible with ES 2.x.
label := strings.Replace(k, ".", "_", -1)
outputLabels.Put(label, v)
}
return outputLabels
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。