@@ -117,3 +117,41 @@ let is_ntp_dhcp_enabled () =
117117 let stat = Unix. stat ! Xapi_globs. ntp_dhcp_script in
118118 stat.Unix. st_perm land 0o100 <> 0
119119 with _ -> false
120+
121+ (* chronyc -c sources output the ntp servers status in csv format. Example:
122+ ^,-,10.62.16.11,5,6,377,54,0.000496471,0.000496471,0.071449950
123+ ^,?,17.253.14.123,0,8,0,4294967295,0.000000000,0.000000000,0.000000000
124+ ^,?,104.40.149.189,0,8,0,4294967295,0.000000000,0.000000000,0.000000000
125+ ^,*,10.71.56.11,5,6,377,57,-0.000006851,-0.000118707,0.082518920
126+ Source mode: '^' = server, '=' = peer, '#' = local clock.
127+ Source state: '*' = current synced, '+' = combined, '-' = not combined,
128+ '?' = unreachable, 'x' = time may be in error, '~' = time too variable
129+ *)
130+ let get_servers_status () =
131+ let convert = function
132+ | "*" ->
133+ " synced"
134+ | "+" ->
135+ " combined"
136+ | "-" ->
137+ " uncombined"
138+ | "x" ->
139+ " error"
140+ | "~" ->
141+ " variable"
142+ | "?" ->
143+ " unreachable"
144+ | _ ->
145+ " unknown"
146+ in
147+ let r = Helpers. call_script ! Xapi_globs. ntp_client_path [" -c" ; " sources" ] in
148+ let lines = String. split_on_char '\n' r in
149+ List. filter_map
150+ (fun line ->
151+ line |> String. trim |> String. split_on_char ',' |> function
152+ | "^" :: status :: server :: _ ->
153+ Some (server, convert status)
154+ | _ ->
155+ None
156+ )
157+ lines
0 commit comments