From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 3CEC41FF0B3 for ; Thu, 26 Nov 2026 14:44:03 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C235F21829; Thu, 26 Nov 2026 14:43:03 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH manager 16/16] api: nodes: time: add endpoint to list the current NTP sources Date: Thu, 26 Nov 2026 14:40:13 +0100 Message-ID: <20261126134128.316681-17-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126134128.316681-1-j.theisen@proxmox.com> References: <20261126134128.316681-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795700531678 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.066 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: PZ6CNZD6C5HQ7BLYSJTEJQA55UZ4T5GL X-Message-ID-Hash: PZ6CNZD6C5HQ7BLYSJTEJQA55UZ4T5GL X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Report which sources the time synchronization service currently uses, including the members of pools, together with their selection state, reachability and offset. This allows checking why the clock is not synchronized or how far off a node is, without logging in to the shell. Like for the immediate synchronization, the time endpoint reports whether the active service supports listing its sources, so clients can decide whether to offer it. Signed-off-by: Jonas Theisen --- Notes: This depends on the NTP sources helper in PVE::Systemd from pve-common. PVE/API2/Nodes.pm | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index dd5d0840..2a255294 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -1763,6 +1763,12 @@ __PACKAGE__->register_method({ type => 'boolean', optional => 1, }, + 'ntp-sources-supported' => { + description => "Whether the active time synchronization service supports" + . " listing its current sources, see 'time/sources'.", + type => 'boolean', + optional => 1, + }, clustered => { description => "Whether the node is part of a cluster, where jumps of the clock" . " can disrupt the cluster, so 'time/sync' requires 'force'.", @@ -1813,6 +1819,7 @@ __PACKAGE__->register_method({ $res->{'ntp-service'} = $service; $res->{'ntp-pools-supported'} = PVE::Systemd::is_ntp_pools_supported($service); $res->{'ntp-sync-supported'} = PVE::Systemd::is_ntp_sync_supported($service); + $res->{'ntp-sources-supported'} = PVE::Systemd::is_ntp_sources_supported($service); $res->{clustered} = PVE::Corosync::check_conf_exists(1) ? 1 : 0; if (my $sources = PVE::Systemd::get_ntp_servers()) { for my $type ('servers', 'pools') { @@ -1951,6 +1958,86 @@ __PACKAGE__->register_method({ }, }); +__PACKAGE__->register_method({ + name => 'time_sources', + path => 'time/sources', + method => 'GET', + description => "List the sources the time synchronization service currently uses, including" + . " the members of pools. Supported for chrony and systemd-timesyncd, which only reports" + . " the server it currently uses.", + permissions => { + check => ['perm', '/nodes/{node}', ['Sys.Audit']], + }, + proxyto => 'node', + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + }, + }, + returns => { + type => 'array', + items => { + type => 'object', + properties => { + address => { + description => "The address of the source.", + type => 'string', + }, + name => { + description => "The name the source was configured with, e.g. the name of" + . " its pool, if it differs from the address.", + type => 'string', + optional => 1, + }, + state => { + description => "The selection state of the source. 'selected' is the source" + . " the clock is synchronized to, 'combined' sources are used in" + . " addition, 'candidate' sources could be used, 'falseticker' sources" + . " are inconsistent with the majority, and 'unusable' sources are, for" + . " example, unreachable or too variable.", + type => 'string', + enum => ['selected', 'combined', 'candidate', 'falseticker', 'unusable'], + }, + stratum => { + description => "The stratum of the source.", + type => 'integer', + optional => 1, + }, + poll => { + description => "The polling interval in seconds.", + type => 'number', + optional => 1, + }, + reach => { + description => "The reachability register of the last 8 polls, with a bit" + . " set for each received response.", + type => 'integer', + minimum => 0, + maximum => 255, + optional => 1, + }, + 'last-rx' => { + description => "Seconds since the last sample was received.", + type => 'integer', + optional => 1, + }, + offset => { + description => "The offset of the local clock to the source in seconds, as" + . " of the last sample. Positive if the local clock is ahead.", + type => 'number', + optional => 1, + }, + }, + }, + }, + code => sub { + my ($param) = @_; + + return PVE::Systemd::get_ntp_sources(); + }, +}); + __PACKAGE__->register_method({ name => 'aplinfo', path => 'aplinfo', -- 2.47.3