Skip to main content

Ping

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.

osapi client node connectivity ping [flags]

Examples​

# A host that answers
osapi client node connectivity ping --target web-01 --address 127.0.0.1

# A host that answers, on macOS
osapi client node connectivity ping --target web-01 --address 127.0.0.1

# A host that does not answer
osapi client node connectivity ping --target web-01 --address 192.0.2.1

Result​

A host that answers, on one host:

$ osapi client node connectivity ping --target web-01 --address 127.0.0.1
Results:
  HOSTNAME  STATUS  PACKETS SENT  PACKETS RECEIVED  PACKET LOSS  MIN RTT  AVG RTT  MAX RTT
  web-01    ok      3             3                 0.00         0.04ms   0.05ms   0.06ms

  1 host: 1 ok   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node connectivity ping --target _all --address 127.0.0.1
Results:
  HOSTNAME  STATUS  PACKETS SENT  PACKETS RECEIVED  PACKET LOSS  MIN RTT  AVG RTT  MAX RTT
  web-01    ok      3             3                 0.00         0.04ms   0.05ms   0.06ms
  web-02    ok      3             3                 0.00         0.04ms   0.05ms   0.06ms

  3 hosts: 2 ok, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"avg_rtt": "0.05ms",
"changed": false,
"hostname": "web-01",
"max_rtt": "0.06ms",
"min_rtt": "0.04ms",
"packet_loss": 0,
"packets_received": 3,
"packets_sent": 3,
"status": "ok"
}
]
}

A host that answers, on macOS, on one host:

$ osapi client node connectivity ping --target web-01 --address 127.0.0.1
Results:
  HOSTNAME  STATUS  PACKETS SENT  PACKETS RECEIVED  PACKET LOSS  MIN RTT  AVG RTT  MAX RTT
  web-01    ok      3             3                 0.00         0.08ms   0.14ms   0.17ms

  1 host: 1 ok   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node connectivity ping --target _all --address 127.0.0.1
Results:
  HOSTNAME  STATUS  PACKETS SENT  PACKETS RECEIVED  PACKET LOSS  MIN RTT  AVG RTT  MAX RTT
  web-01    ok      3             3                 0.00         0.08ms   0.14ms   0.17ms
  web-02    ok      3             3                 0.00         0.08ms   0.14ms   0.17ms

  3 hosts: 2 ok, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"avg_rtt": "0.14ms",
"changed": false,
"hostname": "web-01",
"max_rtt": "0.17ms",
"min_rtt": "0.08ms",
"packet_loss": 0,
"packets_received": 3,
"packets_sent": 3,
"status": "ok"
}
]
}

A host that does not answer, on one host:

$ osapi client node connectivity ping --target web-01 --address 192.0.2.1
Results:
  HOSTNAME  STATUS  PACKETS SENT  PACKETS RECEIVED  PACKET LOSS  MIN RTT  AVG RTT  MAX RTT
  web-01    ok      3             0                 100.00

  1 host: 1 ok   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node connectivity ping --target _all --address 192.0.2.1
Results:
  HOSTNAME  STATUS  PACKETS SENT  PACKETS RECEIVED  PACKET LOSS  MIN RTT  AVG RTT  MAX RTT
  web-01    ok      3             0                 100.00
  web-02    ok      3             0                 100.00

  3 hosts: 2 ok, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": false,
"hostname": "web-01",
"packet_loss": 100,
"packets_received": 0,
"packets_sent": 3,
"status": "ok"
}
]
}

The command fails in these cases:

CallFlagsFails with
A name, not an address--address example.comip_or_fact

Permission​

It needs the connectivity:execute permission. osapi controller role get --name <role> shows what a role grants.

Flags​

FlagDescriptionDefault
--addressThe IPv4 or IPv6 address to ping, or an @fact. reference that the agent resolves (required)
-T, --targetTarget: _all, _any, hostname, or label (group:web.dev)_all

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml
--urlBase URL the CLI client connects to (controller.client.url)https://localhost:8080

Output tells how the result is printed, and what --json gives.