MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / Ping

Method Ping

agent-source-code/internal/client/client.go:73–104  ·  view source on GitHub ↗

Ping sends a ping request to the server

(ctx context.Context)

Source from the content-addressed store, hash-verified

71
72// Ping sends a ping request to the server
73func (c *Client) Ping(ctx context.Context) (*models.PingResponse, error) {
74 url := fmt.Sprintf("%s/api/%s/hosts/ping", c.config.PatchmonServer, c.config.APIVersion)
75
76 c.logger.WithFields(logrus.Fields{
77 "url": url,
78 "method": "POST",
79 }).Debug("Sending ping request to server")
80
81 resp, err := c.client.R().
82 SetContext(ctx).
83 SetHeader("Content-Type", "application/json").
84 SetHeader("X-API-ID", c.credentials.APIID).
85 SetHeader("X-API-KEY", c.credentials.APIKey).
86 SetResult(&models.PingResponse{}).
87 Post(url)
88
89 if err != nil {
90 return nil, fmt.Errorf("ping request failed: %w", err)
91 }
92
93 if resp.StatusCode() != 200 {
94 c.logger.WithField("response", resp.String()).Debug("Full error response from ping request")
95 return nil, fmt.Errorf("ping request failed with status %d: %s", resp.StatusCode(), truncateResponse(resp.String(), 200))
96 }
97
98 result, ok := resp.Result().(*models.PingResponse)
99 if !ok {
100 return nil, fmt.Errorf("invalid response format")
101 }
102
103 return result, nil
104}
105
106// SendUpdate sends package update information to the server
107func (c *Client) SendUpdate(ctx context.Context, payload *models.ReportPayload) (*models.UpdateResponse, error) {

Callers 4

verifyDockerStableMethod · 0.95
IsAvailableMethod · 0.45
pingServerFunction · 0.45
runServiceLoopFunction · 0.45

Calls 1

truncateResponseFunction · 0.85

Tested by

no test coverage detected