Skip to main content

NTP

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​

Namentp
DescriptionThe NTP servers of chrony, and its sync status
Placementnode
Areaconfig
Internalno
APIyes
CLIyes
Nextno
Platformsdebian
Sudochronyc
Runschronyc
Writes/etc/chrony/sources.d/osapi-ntp.sources
Keeps stateno
Usesmanagedfile
Used bynone

Methods (4)​

NAMEVERBHTTPROUTEPERMISSIONDESCRIPTION
getreadGET/api/node/{hostname}/ntpntp:readGet the sync status of chrony and its sources
createwritePOST/api/node/{hostname}/ntpntp:writeSet the NTP servers that chrony uses
updatewritePUT/api/node/{hostname}/ntpntp:writeReplace the NTP servers that osapi set
deletewriteDELETE/api/node/{hostname}/ntpntp:writeRemove the NTP servers that osapi set

Types (4)​

NAMEINPUTOUTPUT
getGetInputStatus { synchronized, stratum, offset, current_source, servers }
createCreateInput { servers* }Result { changed }
updateUpdateInput { servers* }Result { changed }
deleteDeleteInputResult { changed }

Settings (0)​

None. Declare them with behavior.Config.

Telemetry​

Spanbehavior.ntp.<method>
Child spansbehavior.managedfile.<method>, exec chronyc, exec chown, exec stat, file.write, file.remove, file.chmod, kv.get, kv.put
Metricsosapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total
Attributesosapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed
Recorded inputsservers (create, update)

Method get​

Nameget
Verbread
DescriptionGet the sync status of chrony and its sources
DetailReads 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.
HTTPGET
Route/api/node/{hostname}/ntp
Permissionntp:read
Commandosapi client node ntp get
Input typeGetInput
Output typeStatus

Input (0)​

None. The method takes no input; its command needs only --target.

Output (5)​

FIELDTYPEDESCRIPTION
synchronizedbooleanWhether chrony is synchronized to a source
stratumintegerThe NTP stratum of the host
offsetstringThe offset of the system clock from NTP time, such as +0.000003422s
current_sourcestringThe source that chrony follows now
serversarrayThe sources that chrony has

Examples (2)​

EXAMPLEINPUTOUTPUT
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​

Namecreate
Verbwrite
DescriptionSet the NTP servers that chrony uses
DetailWrites 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.
HTTPPOST
Route/api/node/{hostname}/ntp
Permissionntp:write
Commandosapi client node ntp create
Input typeCreateInput
Output typeResult

Input (1)​

FIELDTYPEREQUIREDDESCRIPTION
serversarrayyesThe NTP servers, hostnames or IP addresses

Output (1)​

FIELDTYPEDESCRIPTION
changedbooleanWhether the host changed

Examples (2)​

EXAMPLEINPUTOUTPUT
Set two serversservers=[0.pool.ntp.org 1.pool.ntp.org]changed=true
The servers that the host hasservers=[0.pool.ntp.org]changed=false

Method update​

Nameupdate
Verbwrite
DescriptionReplace the NTP servers that osapi set
DetailThe 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.
HTTPPUT
Route/api/node/{hostname}/ntp
Permissionntp:write
Commandosapi client node ntp update
Input typeUpdateInput
Output typeResult

Input (1)​

FIELDTYPEREQUIREDDESCRIPTION
serversarrayyesThe NTP servers, hostnames or IP addresses

Output (1)​

FIELDTYPEDESCRIPTION
changedbooleanWhether the host changed

Examples (2)​

EXAMPLEINPUTOUTPUT
Replace the serversservers=[time.cloudflare.com]changed=true
The servers that the file hasservers=[0.pool.ntp.org]changed=false

Method delete​

Namedelete
Verbwrite
DescriptionRemove the NTP servers that osapi set
DetailRemoves /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.
HTTPDELETE
Route/api/node/{hostname}/ntp
Permissionntp:write
Commandosapi client node ntp delete
Input typeDeleteInput
Output typeResult

Input (0)​

None. The method takes no input; its command needs only --target.

Output (1)​

FIELDTYPEDESCRIPTION
changedbooleanWhether the host changed

Examples (2)​

EXAMPLEINPUTOUTPUT
Remove the servers(none)changed=true
When osapi set no servers(none)changed=false