System time configuration

ChronyConf - file /etc/chronyd.conf

class insights.parsers.system_time.ChronyConf(context)[source]

Bases: NTPConfParser

A parser for analyzing the chrony service config file /etc/chrony.conf

Uses the NTPConfParser class defined in this module.

LocalTime - command file -L /etc/localtime

class insights.parsers.system_time.LocalTime(context, extra_bad_lines=None)[source]

Bases: CommandParser

A parser for working with the output of command: file -L /etc/localtime

Sample Input:

/etc/localtime: timezone data, version 2, 5 gmt time flags, 5 std time flags, no leap seconds, 69 transition times, 5 abbreviation chars

Examples

>>> localtime = shared[LocalTime]
>>> localtime.data['name']
'/etc/localtime'
>>> localtime.data['version']
'2'
>>> localtime.data['gmt_time_flag']
'5'
>>> localtime.data['leap_second']
'no'
parse_content(content)[source]

This method must be implemented by classes based on this class.

NTPConfParser base class

class insights.parsers.system_time.NTPConfParser(context)[source]

Bases: Parser

NTP and Chrony both use the same format for their configuration file - a series of keywords with optional values. Some keywords can appear more than once, so all keyword values are stored as a list of strings. Keywords that have no value, like ‘iburst’ or ‘rtcsync’, are left as keys but have None as a value.

Also provides the servers and peers properties as (sorted) lists of the found ‘server’ and ‘peer’ data (respectively).

Sample Input::
>>> ntp_conf_data = '''
... server 0.rhel.pool.ntp.org iburst
... server 1.rhel.pool.ntp.org iburst
... server 2.rhel.pool.ntp.org iburst
... server 3.rhel.pool.ntp.org iburst
... # Enable kernel RTC synchronization.
... rtcsync
... leapsecmode slew
... maxslewrate 1000
... smoothtime 400 0.001 leaponly
... tinker step 0.9
... '''

Examples

>>> ntp = shared[NTP_conf]
>>> 'rtcsync' in ntp.data # Single word options are present but None
True
>>> ntp.data['rtcsync'] # Not in dictionary if option not set
None
>>> len(ntp.data['server'])
4
>>> ntp.data['server'][0]
'0.rhel.pool.ntp.org iburst'
>>> ntp.servers[0] # same data as above
'0.rhel.pool.ntp.org iburst'
>>> ntp.data['maxslewrate']
'1000'
>>> ntp.get_last('rtcsync') # See above for fetching single-word options
None
>>> ntp.get_last('leapsecmode')
'slew'
>>> ntp.get_last('tinker', 'panic', 'none') # Use default value
'none'
>>> ntp.get_last('tinker', 'step', '1') # Use value set in file
'0.9'
>>> ntp.get_param('tinker', 'step') # Get list of all settings
['0.9']
get_last(keyword, param=None, default=None)[source]

Get the parameters for a given keyword, or default if keyword or parameter are not present in the configuration.

This finds the last declaration of the given parameter (which is the one which takes effect). If no parameter is given, then the entire line is treated as the parameter and returned.

Parameters:
  • keyword (str) -- The keyword name, e.g. ‘tinker’ or ‘driftfile’

  • param (str) -- The parameter name, e.g. ‘panic’ or ‘step’. If not given, the last definition of that keyword is given.

Returns:

The value of the given parameter, or None if not found.

Return type:

str or None

get_param(keyword, param=None, default=None)[source]

Get all the parameters for a given keyword, or default if keyword or parameter are not present in the configuration.

This finds every declaration of the given parameter (which is the one which takes effect). If no parameter is given, then the entire line is treated as the parameter. There is always at least one element returned - the default, or

Parameters:
  • keyword (str) -- The keyword name, e.g. ‘tinker’ or ‘driftfile’

  • param (str) -- The parameter name, e.g. ‘panic’ or ‘step’. If not given, all the definitions of that keyword are given.

  • default (str) -- The default (singular) value if the keyword or parameter is not found. If not given, None is used.

Returns:

All the values of the given parameter, or an empty list if not found.

Return type:

list

parse_content(content)[source]

This method must be implemented by classes based on this class.

NTPConf - file /etc/ntpd.conf

class insights.parsers.system_time.NTPConf(context)[source]

Bases: NTPConfParser

A parser for analyzing the ntpd service config file /etc/ntp.conf

Uses the NTPConfParser class defined in this module.

NtpTime - command ntptime

class insights.parsers.system_time.NtpTime(context, extra_bad_lines=None)[source]

Bases: CommandParser

A parser for working with the output of the ntptime.

This doesn’t attempt to get much out of the output; useful things that it retrieves are:

  • ntp_gettime - the return code of the ntp_gettime() call.

  • ntp_adjtime - the return code of the ntp_adjtime() call.

  • status - the hexadecimal status code as a string.

  • flags - the flags in brackets after the status code.

Sample Input:

ntp_gettime() returns code 0 (OK)
  time dbbc595d.1adbd720  Thu, Oct 27 2016 18:45:49.104, (.104917550),
  maximum error 263240 us, estimated error 102 us, TAI offset 0
ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset 0.000 us, frequency 4.201 ppm, interval 1 s,
  maximum error 263240 us, estimated error 102 us,
  status 0x2011 (PLL,INS,NANO),
  time constant 2, precision 0.001 us, tolerance 500 ppm,

Examples

>>> ntptime = shared[NtpTime]
>>> ntptime.data['stats']
'0x2011'
>>> ntptime.data['ntp_gettime']
'0'
>>> ntptime.data['flags']
['PLL', 'INS', 'NANO']
>>> ntptime.data['interval']  # Other values are integers or floats
1
>>> ntptime.data['precision']  # Note floats may not be exact
0.001
>>> ntptime.data['maximum error']
263240
parse_content(content)[source]

This method must be implemented by classes based on this class.