This repository has been archived by the owner on Jul 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
docker.go
61 lines (50 loc) · 1.81 KB
/
docker.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
package docker
import (
"context"
"github.com/puppetlabs/lumogon/capabilities/payloadfilter"
"github.com/puppetlabs/lumogon/capabilities/registry"
"github.com/puppetlabs/lumogon/dockeradapter"
"github.com/puppetlabs/lumogon/logging"
"github.com/puppetlabs/lumogon/types"
)
var dockerDescription = `The 'docker' capability captures information related to the underlying Docker server`
var dockerCapability = dockeradapter.DockerAPICapability{
Capability: types.Capability{
Schema: "http://puppet.com/lumogon/capability/docker/draft-01/schema#1",
Title: "Docker Server Information",
Name: "docker",
Description: dockerDescription,
Type: "dockerapi",
Payload: nil,
SupportedOS: map[string]int{"all": 1},
},
Harvest: func(capability *dockeradapter.DockerAPICapability, client dockeradapter.Harvester, id string, target types.TargetContainer) {
logging.Debug("[Docker Server] Harvesting docker server information associated with %s [%s]", target.Name, target.ID)
capability.HarvestID = id
version, err := VersionToMap(client)
if err != nil {
capability.PayloadError(err.Error())
return
}
filtered, _ := payloadfilter.Filter(version)
capability.Payload = filtered
},
}
// VersionToMap Extracts and returns a formatted map[string]interface{} containing
// version information exposted via the Docker API
func VersionToMap(client dockeradapter.Harvester) (map[string]interface{}, error) {
ctx := context.Background()
v, err := client.ServerVersion(ctx)
if err != nil {
return nil, err
}
return map[string]interface{}{
"Version": v.Version,
"APIVersion": v.APIVersion,
"MinAPIVersion": v.MinAPIVersion,
}, nil
}
func init() {
logging.Debug("[Docker Server] Initialising capability: %s", dockerCapability.Title)
registry.Registry.Add(dockerCapability)
}