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

GenericPolicy.get_msg()[source]
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.

InitSystem.get_service_names(regex)[source]

Get a list of all services discovered on the system that match the given regex.

InitSystem.get_service_status(name)[source]

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

InitSystem.is_disabled(name)[source]

Check if a given service name is disabled

InitSystem.is_enabled(name)[source]

Check if given service name is enabled

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

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

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

InitSystem.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, init=None)[source]

Bases: sos.policies.Policy

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

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

Returns the name usd in the pre_work step

LinuxPolicy.get_preferred_hash_name()[source]
LinuxPolicy.get_upload_https_auth(user=None, password=None)[source]

Formats the user/password credentials using basic auth

LinuxPolicy.get_upload_password()[source]

Helper function to determine if we should use the policy default upload password or one provided by the user

LinuxPolicy.get_upload_url()[source]

Helper function to determine if we should use the policy default upload url or one provided by the user

LinuxPolicy.get_upload_url_string()[source]

Used by distro policies to potentially change the string used to report upload location from the URL to a more human-friendly string

LinuxPolicy.get_upload_user()[source]

Helper function to determine if we should use the policy default upload user or one provided by the user

LinuxPolicy.host_name()[source]
LinuxPolicy.init = None
LinuxPolicy.init_kernel_modules()[source]

Obtain a list of loaded kernel modules to reference later for plugin enablement and SoSPredicate checks

LinuxPolicy.is_kernel_smp()[source]
LinuxPolicy.kernel_version()[source]
LinuxPolicy.pre_work()[source]
LinuxPolicy.prompt_for_upload_password()[source]

Should be overridden by policies to determine if a password needs to be provided for upload or not

LinuxPolicy.prompt_for_upload_user()[source]

Should be overridden by policies to determine if a user needs to be provided or not

LinuxPolicy.sanitize_filename(name)[source]
LinuxPolicy.upload_archive(archive)[source]

Entry point for sos attempts to upload the generated archive to a policy or user specified location.

Curerntly there is support for HTTPS, SFTP, and FTP. HTTPS uploads are preferred for policy-defined defaults.

Policies that need to override uploading methods should override the respective upload_https(), upload_sftp(), and/or upload_ftp() methods and should NOT override this method.

In order to enable this for a policy, that policy needs to implement the following:

Required:
Class Attrs:
_upload_url The default location to use. Note
these MUST include protocol header

_upload_user Default username, if any else None _upload_password Default password, if any else None _use_https_streaming Set to True if the HTTPS endpoint

supports streaming data
Optional:
Class Attrs:
_upload_directory Default FTP server directory, if any
Methods:
prompt_for_upload_user() Determines if sos should prompt
for a username or not.
get_upload_user() Determines if the default or a
different username should be used
get_upload_https_auth() Format authentication data for
HTTPS uploads
get_upload_url_string() If you want your policy to print
a string other than the default URL for your vendor/distro, override this method
LinuxPolicy.upload_ftp(url=None, directory=None, user=None, password=None)[source]

Attempts to upload the archive to either the policy defined or user provided FTP location.

LinuxPolicy.upload_https()[source]

Attempts to upload the archive to an HTTPS location.

Policies may define whether this upload attempt should use streaming or non-streaming data by setting the use_https_streaming class attr to True

LinuxPolicy.upload_password = None
LinuxPolicy.upload_sftp()[source]

Attempts to upload the archive to an SFTP location.

Due to the lack of well maintained, secure, and generally widespread python libraries for SFTP, sos will shell-out to the system’s local ssh installation in order to handle these uploads.

Do not override this method with one that uses python-paramiko, as the upstream sos team will reject any PR that includes that dependency.

LinuxPolicy.upload_url = None
LinuxPolicy.upload_user = None
LinuxPolicy.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.

PackageManager.all_files()[source]

Returns a list of files known by the package manager

PackageManager.all_pkgs()[source]

Return a list of all packages.

PackageManager.all_pkgs_by_name(name)[source]

Return a list of packages that match name.

PackageManager.all_pkgs_by_name_regex(regex_name, flags=0)[source]

Return a list of packages that match regex_name.

PackageManager.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
PackageManager.chroot = None
PackageManager.files = None
PackageManager.get_pkg_list()[source]

Returns a dictionary of packages in the following format:

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

Return a single package that matches name.

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

Bases: object

Policy.PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
Policy.add_preset(name=None, desc=None, note=None, opts=SoSOptions(add_preset='', alloptions=False, allow_system_changes=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, no_env_vars=False, no_postproc=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, since=None, sysroot=None, threads=4, tmp_dir='', upload=False, upload_url='', upload_directory='', upload_user='', upload_pass='', 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
Policy.check()[source]

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

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

Return the OS version

Policy.distro = 'Unknown'
Policy.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.
Policy.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().

Policy.get_cmd_for_compress_method(method, threads)[source]
Policy.get_default_scl_prefix()[source]
Policy.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.

Policy.get_preferred_archive()[source]

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

Policy.get_preferred_hash_name()[source]

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

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

Returns True if sos is running inside a container environment.

Policy.is_root()[source]

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

Policy.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.
Policy.match_plugin(plugin_classes)[source]
Policy.msg = 'This command will collect system configuration and diagnostic information from this %(distro)s system.\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\n%(changes_text)s\n\n%(vendor_text)s\n'
Policy.name_pattern = 'legacy'
Policy.pkg_by_name(pkg)[source]
Policy.post_work()[source]

This function is called after the sosreport has been generated.

Policy.pre_work()[source]

This function is called prior to collection.

Policy.presets = {'': PresetDefaults(name='' desc='' note='None' opts=(SoSOptions(add_preset='', alloptions=False, allow_system_changes=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, no_env_vars=False, no_postproc=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, since=None, sysroot=None, threads=4, tmp_dir='', upload=False, upload_url='', upload_directory='', upload_user='', upload_pass='', verbosity=0, verify=False))}
Policy.presets_path = '/var/lib/sos/presets'
Policy.probe_preset()[source]

Return a PresetDefaults object matching the runing host.

Stub method to be implemented by derived policy classes.

Returns:a PresetDefaults object.
Policy.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.
Policy.set_commons(commons)[source]
Policy.set_exec_path()[source]
Policy.set_valid_subclasses(subclasses)[source]
Policy.valid_subclasses

list of subclasses that this policy can process

Policy.validate_plugin(plugin_class, experimental=False)[source]

Verifies that the plugin_class should execute under this policy

Policy.vendor = 'Unknown'
Policy.vendor_text = ''
Policy.vendor_url = 'http://www.example.com/'
class sos.policies.PresetDefaults(name='', desc='', note=None, opts=SoSOptions(add_preset='', alloptions=False, allow_system_changes=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, no_env_vars=False, no_postproc=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, since=None, sysroot=None, threads=4, tmp_dir='', upload=False, upload_url='', upload_directory='', upload_user='', upload_pass='', verbosity=0, verify=False))[source]

Bases: object

Preset command line defaults.

PresetDefaults.builtin = True

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

PresetDefaults.delete(presets_path)[source]
PresetDefaults.desc = None

Human readable preset description

PresetDefaults.name = None

Preset name, used for selection

PresetDefaults.note = None

Notes on preset behaviour

PresetDefaults.opts = SoSOptions(add_preset='', alloptions=False, allow_system_changes=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, no_env_vars=False, no_postproc=False, note='', onlyplugins=[], plugin_timeout=None, plugopts=[], preset='auto', profiles=[], quiet=False, since=None, sysroot=None, threads=4, tmp_dir='', upload=False, upload_url='', upload_directory='', upload_user='', upload_pass='', verbosity=0, verify=False)

Options set for this preset

PresetDefaults.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

SystemdInit.is_running(name)[source]
SystemdInit.load_all_services()[source]
SystemdInit.parse_query(output)[source]
sos.policies.get_human_readable(size, precision=2)[source]
sos.policies.import_policy(name)[source]
sos.policies.load(cache={}, sysroot=None)[source]

Previous topic

sos.archive — Archive Interface

Next topic

sos.reporting — Reporting Interface

This Page