The NTP servers of chrony, and its sync status.
osapi dsl behavior get --name ntp and osapi dsl behavior method get show the
same. Its chain shows each call that its
examples make.
Behavior
| |
|---|
| Name | ntp |
| Description | The NTP servers of chrony, and its sync status |
| Placement | node |
| Area | config |
| Internal | no |
| API | yes |
| CLI | yes |
| Next | no |
| Platforms | debian |
| Sudo | chronyc |
| Runs | chronyc |
| Writes | /etc/chrony/sources.d/osapi-ntp.sources |
| Keeps state | no |
| Uses | managedfile |
| Used by | none |
Methods (4)
| NAME | VERB | HTTP | ROUTE | PERMISSION | DESCRIPTION |
|---|
| get | read | GET | /api/node/{hostname}/ntp | ntp:read | Get the sync status of chrony and its sources |
| create | write | POST | /api/node/{hostname}/ntp | ntp:write | Set the NTP servers that chrony uses |
| update | write | PUT | /api/node/{hostname}/ntp | ntp:write | Replace the NTP servers that osapi set |
| delete | write | DELETE | /api/node/{hostname}/ntp | ntp:write | Remove the NTP servers that osapi set |
Types (4)
| NAME | INPUT | OUTPUT |
|---|
| get | GetInput | Status { synchronized, stratum, offset, current_source, servers } |
| create | CreateInput { servers* } | Result { changed } |
| update | UpdateInput { servers* } | Result { changed } |
| delete | DeleteInput | Result { changed } |
Settings (0)
None. Declare them with behavior.Config.
Telemetry
| |
|---|
| Span | behavior.ntp.<method> |
| Child spans | behavior.managedfile.<method>, exec chronyc, exec chown, exec stat, file.write, file.remove, file.chmod, kv.get, kv.put |
| Metrics | osapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total |
| Attributes | osapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed |
| Recorded inputs | servers (create, update) |
Method get
| |
|---|
| Name | get |
| Verb | read |
| Description | Get the sync status of chrony and its sources |
| Detail | Reads chronyc tracking, for whether chrony is synchronized, its stratum, its offset from NTP time and the source that it follows, and chronyc sources, for each source that it has. |
| HTTP | GET |
| Route | /api/node/{hostname}/ntp |
| Permission | ntp:read |
| Command | osapi client node ntp get |
| Input type | GetInput |
| Output type | Status |
None. The method takes no input; its command needs only --target.
Output (5)
| FIELD | TYPE | DESCRIPTION |
|---|
| synchronized | boolean | Whether chrony is synchronized to a source |
| stratum | integer | The NTP stratum of the host |
| offset | string | The offset of the system clock from NTP time, such as +0.000003422s |
| current_source | string | The source that chrony follows now |
| servers | array | The sources that chrony has |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|
| A host synchronized to time.cloudflare.com | (none) | synchronized=true, stratum=3, offset=+0.000003422s, current_source=time.cloudflare.com, servers=[time.cloudflare.com 0.pool.ntp.org] |
| A host that chrony does not synchronize | (none) | synchronized=false, offset=-0.000001834s |
Method create
| |
|---|
| Name | create |
| Verb | write |
| Description | Set the NTP servers that chrony uses |
| Detail | Writes a server line for each server to /etc/chrony/sources.d/osapi-ntp.sources, and reloads the sources with chronyc reload sources. A file that has the same servers does not change, and reports changed: false. |
| HTTP | POST |
| Route | /api/node/{hostname}/ntp |
| Permission | ntp:write |
| Command | osapi client node ntp create |
| Input type | CreateInput |
| Output type | Result |
| FIELD | TYPE | REQUIRED | DESCRIPTION |
|---|
| servers | array | yes | The NTP servers, hostnames or IP addresses |
Output (1)
| FIELD | TYPE | DESCRIPTION |
|---|
| changed | boolean | Whether the host changed |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|
| Set two servers | servers=[0.pool.ntp.org 1.pool.ntp.org] | changed=true |
| The servers that the host has | servers=[0.pool.ntp.org] | changed=false |
Method update
| |
|---|
| Name | update |
| Verb | write |
| Description | Replace the NTP servers that osapi set |
| Detail | The same as create, for servers that osapi set already. It fails with not found when osapi set none. The servers that the file has already report changed: false. |
| HTTP | PUT |
| Route | /api/node/{hostname}/ntp |
| Permission | ntp:write |
| Command | osapi client node ntp update |
| Input type | UpdateInput |
| Output type | Result |
| FIELD | TYPE | REQUIRED | DESCRIPTION |
|---|
| servers | array | yes | The NTP servers, hostnames or IP addresses |
Output (1)
| FIELD | TYPE | DESCRIPTION |
|---|
| changed | boolean | Whether the host changed |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|
| Replace the servers | servers=[time.cloudflare.com] | changed=true |
| The servers that the file has | servers=[0.pool.ntp.org] | changed=false |
Method delete
| |
|---|
| Name | delete |
| Verb | write |
| Description | Remove the NTP servers that osapi set |
| Detail | Removes /etc/chrony/sources.d/osapi-ntp.sources and reloads the sources, so chrony uses its other sources. When osapi set no servers, it reports changed: false. |
| HTTP | DELETE |
| Route | /api/node/{hostname}/ntp |
| Permission | ntp:write |
| Command | osapi client node ntp delete |
| Input type | DeleteInput |
| Output type | Result |
None. The method takes no input; its command needs only --target.
Output (1)
| FIELD | TYPE | DESCRIPTION |
|---|
| changed | boolean | Whether the host changed |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|
| Remove the servers | (none) | changed=true |
| When osapi set no servers | (none) | changed=false |