sos.policies — Policy Interface

sos.policies.DESC = 'desc'

Constants for on-disk preset fields

class sos.policies.GenericPolicy(sysroot=None)[source]

Bases: sos.policies.Policy

This Policy will be returned if no other policy can be loaded. This should allow for IndependentPlugins to be executed on any system

get_msg()[source]

This method is used to prepare the preamble text to display to the user in non-batch mode. If your policy sets self.distro that text will be substituted accordingly. You can also override this method to do something more complicated.

class sos.policies.InitSystem(init_cmd=None, list_cmd=None, query_cmd=None)[source]

Bases: object

Encapsulates an init system to provide service-oriented functions to sos.

This should be used to query the status of services, such as if they are enabled or disabled on boot, or if the service is currently running.

get_service_status(name)[source]

Returns the status for the given service name along with the output of the query command

is_disabled(name)[source]

Check if a given service name is disabled

is_enabled(name)[source]

Check if given service name is enabled

is_running(name)[source]

Checks if the given service name is in a running state.

This should be overridden by initsystems that subclass InitSystem

is_service(name)[source]

Checks if the given service name exists on the system at all, this does not check for the service status

load_all_services()[source]

This loads all services known to the init system into a dict. The dict should be keyed by the service name, and contain a dict of the name and service status

parse_query(output)[source]

Parses the output returned by the query command to make a determination of what the state of the service is

This should be overriden by anything that subclasses InitSystem

class sos.policies.LinuxPolicy(sysroot=None)[source]

Bases: sos.policies.Policy

This policy is meant to be an abc class that provides common implementations used in Linux distros

PATH = '/bin:/sbin:/usr/bin:/usr/sbin'
default_runlevel()[source]
distro = 'Linux'
get_arch()[source]
get_local_name()[source]

Returns the name usd in the pre_work step

get_preferred_hash_name()[source]

Returns the string name of the hashlib-supported checksum algorithm to use

host_name()[source]
init = None
is_kernel_smp()[source]
kernel_version()[source]
lsmod()[source]

Return a list of kernel module names as strings.

pre_work()[source]

This function is called prior to collection.

sanitize_filename(name)[source]
vendor = 'None'
class sos.policies.PackageManager(chroot=None, query_command=None, verify_command=None, verify_filter=None, files_command=None)[source]

Bases: object

Encapsulates a package manager. If you provide a query_command to the constructor it should print each package on the system in the following format:

package name|package.version

You may also subclass this class and provide a get_pkg_list method to build the list of packages and versions.

all_files()[source]

Returns a list of files known by the package manager

all_pkgs()[source]

Return a list of all packages.

all_pkgs_by_name(name)[source]

Return a list of packages that match name.

all_pkgs_by_name_regex(regex_name, flags=0)[source]

Return a list of packages that match regex_name.

build_verify_command(self, packages) → str[source]

Generate a command to verify the list of packages given in packages using the native package manager’s verification tool.

The command to be executed is returned as a string that may be passed to a command execution routine (for e.g. sos_get_command_output().

Parameters:packages – a string, or a list of strings giving package names to be verified.
Returns:a string containing an executable command that will perform verification of the given packages.
Returntype:str or NoneType
chroot = None
files = None
get_pkg_list()[source]

Returns a dictionary of packages in the following format:

{'package_name': {'name': 'package_name',
                  'version': 'major.minor.version'}}
pkg_by_name(name)[source]

Return a single package that matches name.

pkg_nvra(pkg)[source]
query_command = None
verify_command = None
verify_filter = None
class sos.policies.Policy(sysroot=None)[source]

Bases: object

PATH = ''
add_preset(name=None, desc=None, note=None, opts=SoSOptions(add_preset='', alloptions=False, all_logs=False, batch=False, build=False, case_id='', chroot='auto', compression_type='auto', config_file='', desc='', debug=False, del_preset='', dry_run=False, enableplugins=[], encrypt_key=None, encrypt_pass=None, experimental=False, label='', list_plugins=False, list_presets=False, list_profiles=False, log_size=25, noplugins=[], noreport=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, sysroot=None, threads=4, tmp_dir='', verbosity=0, verify=False))[source]

Add a new on-disk preset and write it to the configured presets path.

Parameters:preset – the new PresetDefaults to add
check()[source]

This function is responsible for determining if the underlying system is supported by this policy.

default_scl_prefix = ''
del_preset(name='')[source]
del_valid_subclasses()[source]
display_results(archive, directory, checksum)[source]
dist_version()[source]

Return the OS version

distro = 'Unknown'
find_preset(preset)[source]

Find a preset profile matching the specified preset string.

Parameters:preset – a string containing a preset profile name.
Returns:a matching PresetProfile.
get_archive_name()[source]

This function should return the filename of the archive without the extension.

This uses the policy’s name_pattern attribute to determine the name. There are two pre-defined naming patterns - ‘legacy’ and ‘friendly’ that give names like the following:

legacy - ‘sosreport-tux.123456-20171224185433’ friendly - ‘sosreport-tux-mylabel-123456-2017-12-24-ezcfcop.tar.xz’

A custom name_pattern can be used by a policy provided that it defines name_pattern using a format() style string substitution.

Usable substitutions are:

name - the short hostname of the system label - the label given by –label case - the case id given by –case-id or –ticker-number rand - a random string of 7 alpha characters

Note that if a datestamp is needed, the substring should be set in the name_pattern in the format accepted by strftime().

get_cmd_for_compress_method(method, threads)[source]
get_default_scl_prefix()[source]
get_msg()[source]

This method is used to prepare the preamble text to display to the user in non-batch mode. If your policy sets self.distro that text will be substituted accordingly. You can also override this method to do something more complicated.

get_preferred_archive()[source]

Return the class object of the prefered archive format for this platform

get_preferred_hash_name()[source]

Returns the string name of the hashlib-supported checksum algorithm to use

get_tmp_dir(opt_tmp_dir)[source]
get_valid_subclasses()[source]
host_sysroot()[source]
in_container()[source]

Returns True if sos is running inside a container environment.

is_root()[source]

This method should return true if the user calling the script is considered to be a superuser

load_presets(presets_path=None)[source]

Load presets from disk.

Read JSON formatted preset data from the specified path, or the default location at /var/lib/sos/presets.

Parameters:presets_path – a directory containing JSON presets.
match_plugin(plugin_classes)[source]
msg = 'This command will collect system configuration and diagnostic information from this %(distro)s system. An archive containing the collected information will be generated in %(tmpdir)s.\n\nFor more information on %(vendor)s visit:\n\n %(vendor_url)s\n\nThe generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party.\n\nNo changes will be made to system configuration.\n%(vendor_text)s\n'
name_pattern = 'legacy'
pkg_by_name(pkg)[source]
post_work()[source]

This function is called after the sosreport has been generated.

pre_work()[source]

This function is called prior to collection.

presets = {'': PresetDefaults(name='' desc='' note='None' opts=(SoSOptions(add_preset='', alloptions=False, all_logs=False, batch=False, build=False, case_id='', chroot='auto', compression_type='auto', config_file='', desc='', debug=False, del_preset='', dry_run=False, enableplugins=[], encrypt_key=None, encrypt_pass=None, experimental=False, label='', list_plugins=False, list_presets=False, list_profiles=False, log_size=25, noplugins=[], noreport=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, sysroot=None, threads=4, tmp_dir='', verbosity=0, verify=False))}
presets_path = '/var/lib/sos/presets'
probe_preset()[source]

Return a PresetDefaults object matching the runing host.

Stub method to be implemented by derived policy classes.

Returns:a PresetDefaults object.
register_presets(presets, replace=False)[source]

Add new presets to this policy object.

Merges the presets dictionary presets into this Policy object, or replaces the current presets if replace is True.

presets should be a dictionary mapping str preset names to <class PresetDefaults> objects specifying the command line defaults.

Parameters:
  • presets – dictionary of presets to add or replace
  • replace – replace presets rather than merge new presets.
set_commons(commons)[source]
set_exec_path()[source]
set_valid_subclasses(subclasses)[source]
valid_subclasses

list of subclasses that this policy can process

validate_plugin(plugin_class, experimental=False)[source]

Verifies that the plugin_class should execute under this policy

vendor = 'Unknown'
vendor_text = ''
vendor_url = 'http://www.example.com/'
class sos.policies.PresetDefaults(name='', desc='', note=None, opts=SoSOptions(add_preset='', alloptions=False, all_logs=False, batch=False, build=False, case_id='', chroot='auto', compression_type='auto', config_file='', desc='', debug=False, del_preset='', dry_run=False, enableplugins=[], encrypt_key=None, encrypt_pass=None, experimental=False, label='', list_plugins=False, list_presets=False, list_profiles=False, log_size=25, noplugins=[], noreport=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, sysroot=None, threads=4, tmp_dir='', verbosity=0, verify=False))[source]

Bases: object

Preset command line defaults.

builtin = True

True if this preset if built-in or False otherwise.

delete(presets_path)[source]
desc = None

Human readable preset description

name = None

Preset name, used for selection

note = None

Notes on preset behaviour

opts = SoSOptions(add_preset='', alloptions=False, all_logs=False, batch=False, build=False, case_id='', chroot='auto', compression_type='auto', config_file='', desc='', debug=False, del_preset='', dry_run=False, enableplugins=[], encrypt_key=None, encrypt_pass=None, experimental=False, label='', list_plugins=False, list_presets=False, list_profiles=False, log_size=25, noplugins=[], noreport=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, sysroot=None, threads=4, tmp_dir='', verbosity=0, verify=False)

Options set for this preset

write(presets_path)[source]

Write this preset to disk in JSON notation.

Parameters:presets_path – the directory where the preset will be written.
class sos.policies.SystemdInit[source]

Bases: sos.policies.InitSystem

is_running(name)[source]

Checks if the given service name is in a running state.

This should be overridden by initsystems that subclass InitSystem

load_all_services()[source]

This loads all services known to the init system into a dict. The dict should be keyed by the service name, and contain a dict of the name and service status

parse_query(output)[source]

Parses the output returned by the query command to make a determination of what the state of the service is

This should be overriden by anything that subclasses InitSystem

sos.policies.import_policy(name)[source]
sos.policies.load(cache={}, sysroot=None)[source]