forked from rancher/agent
/
ping.go
38 lines (35 loc) · 1.08 KB
/
ping.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
package handlers
import (
engineCli "github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/rancher/agent/core/hostInfo"
"github.com/rancher/agent/core/marshaller"
"github.com/rancher/agent/core/ping"
"github.com/rancher/agent/model"
"github.com/rancher/agent/utilities/config"
"github.com/rancher/agent/utilities/constants"
revents "github.com/rancher/event-subscriber/events"
"github.com/rancher/go-rancher/v2"
)
type PingHandler struct {
dockerClient *engineCli.Client
collectors []hostInfo.Collector
}
func (h *PingHandler) Ping(event *revents.Event, cli *client.RancherClient) error {
if event.ReplyTo == "" {
return nil
}
resp := model.PingResponse{
Resources: []model.PingResource{},
}
if config.DoPing() {
if err := ping.DoPingAction(event, &resp, h.dockerClient, h.collectors); err != nil {
return errors.Wrap(err, constants.PingError+"failed to do ping action")
}
}
data, err := marshaller.StructToMap(resp)
if err != nil {
return errors.Wrap(err, constants.PingError+"failed to marshall response data")
}
return reply(data, event, cli)
}