Connectivity
c.Connectivity calls the API's Connectivity group. Whether the host reaches an
address, by ICMP ping.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Ping(ctx, hostname, input) | *Response[Collection[ConnectivityPingResult]] | connectivity:execute | Ping an address from the host. |
Ping
func (s *ConnectivityService) Ping(
ctx context.Context,
hostname string,
input ConnectivityPingInput,
) (*Response[Collection[ConnectivityPingResult]], error)
Ping an address from the host.
Sends three ICMP echo requests from the host and reports how many came back, and their round-trip times. A host that does not answer is 100% loss, not an error. It changes nothing, so it reports changed: false. On Linux the agent pings without root when net.ipv4.ping_group_range admits its group.
It sends POST /api/node/{hostname}/connectivity/ping, and needs the permission
connectivity:execute.
The examples of the method's definition:
A host that answers, go run connectivity.go ping:
resp, err := c.Connectivity.Ping(ctx, target, client.ConnectivityPingInput{Address: "127.0.0.1"})
A host that does not answer, go run connectivity.go ping-2:
resp, err := c.Connectivity.Ping(ctx, target, client.ConnectivityPingInput{Address: "192.0.2.1"})
Types
The fields of each type are the properties of its schema in the API's spec.
ConnectivityPingInput
| Field | Type | Description |
|---|---|---|
Address | string | The IPv4 or IPv6 address to ping, or an @fact. reference that the agent resolves. |
ConnectivityPingResult
| Field | Type | Description |
|---|---|---|
AvgRTT | string | Average round-trip time in milliseconds, with two decimals. Absent when no reply came back. |
Changed | bool | Always false: a ping changes nothing on the host. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
MaxRTT | string | Maximum round-trip time in milliseconds, with two decimals. Absent when no reply came back. |
MinRTT | string | Minimum round-trip time in milliseconds, with two decimals. Absent when no reply came back. |
PacketLoss | float64 | Percentage of packet loss. |
PacketsReceived | int | Number of packets received. |
PacketsSent | int | Number of packets sent. |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
RowStatus
What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
A string, one of ok, failed, skipped, timeout.
Example
examples/sdk/client/connectivity.go
runs each example of this page. With no argument, it lists them.