sos(1)
| SOS(1) | SoS | SOS(1) |
NAME
sos - SoS Documentation
Sos is an extensible, portable, support data collection tool primarily aimed at Linux distributions and other UNIX-like operating systems.
This is the SoS developer documentation, for user documentation refer to:
https://github.com/sosreport/sos/wiki
This project is hosted at:
http://github.com/sosreport/sos
For the latest version, to contribute, and for more information, please visit the project pages or join the mailing list.
To clone the current master (development) branch run:
git clone git://github.com/sosreport/sos.git
REPORTING BUGS
Please report bugs via the mailing list or by opening an issue in the GitHub Issue Tracker
MAILING LIST
sos-devel is the mailing list for any sos-related questions and discussion. Patch submissions and reviews are welcome too.
PATCHES AND PULL REQUESTS
Patches can be submitted via the mailing list or as GitHub pull requests. If using GitHub please make sure your branch applies to the current master as a ‘fast forward’ merge (i.e. without creating a merge commit). Use the git rebase command to update your branch to the current master if necessary.
User and API documentation is automatically generated using Sphinx and Read the Docs.
WIKI
How to write a policy
Plugin options
To help get your changes merged quickly with as few revisions as possible please refer to the Contributor Guidelines when submitting patches or pull requests.
MANUAL INSTALLATION
to install locally (as root) ==> make install to build an rpm ==> make rpm to build a deb ==> make deb
PRE-BUILT PACKAGING
Fedora/RHEL users install via yum:
yum install sos
Debian(Sid) users install via apt:
apt-get install sosreport
Ubuntu(Saucy 13.10 and above) users install via apt:
sudo apt-get install sosreport
PLUGIN REFERENCE
sos.plugins — Plugin Interface
This exports methods available for use by plugins for sos
- class sos.plugins.ALTLinuxPlugin
- Bases: object
Tagging class for ALT Linux
- class sos.plugins.DebianPlugin
- Bases: object
Tagging class for Debian Linux
- class sos.plugins.ExperimentalPlugin
- Bases: object
Tagging class that indicates that this plugin is experimental
- class sos.plugins.IndependentPlugin
- Bases: object
Tagging class for plugins that can run on any platform
- class sos.plugins.Plugin(commons)
- Bases: object
This is the base class for sosreport plugins. Plugins should subclass this and set the class variables where applicable.
plugin_name is a string returned by plugin.name(). If this is set to None (the default) class_.__name__.tolower() will be returned. Be sure to set this if you are defining multiple plugins that do the same thing on different platforms.
requires_root is a boolean that specifies whether or not sosreport should execute this plugin as a super user.
version is a string representing the version of the plugin. This can be useful for post-collection tooling.
packages (files) is an iterable of the names of packages (the paths of files) to check for before running this plugin. If any of these packages or files is found on the system, the default implementation of check_enabled will return True.
profiles is an iterable of profile names that this plugin belongs to. Whenever any of the profiles is selected on the command line the plugin will be enabled (subject to normal check_enabled tests).
- add_alert(alertstring)
- Add an alert to the collection of alerts for this plugin. These will be displayed in the report
- add_cmd_output(cmds, suggest_filename=None, root_symlink=None, timeout=300, stderr=True, chroot=True, runat=None, env=None)
- Run a program or a list of programs and collect the output
- add_copy_spec(copyspecs, sizelimit=None, tailit=True)
- Add a file or glob but limit it to sizelimit megabytes. If fname is a single file the file will be tailed to meet sizelimit. If the first file in a glob is too large it will be tailed to meet the sizelimit.
- add_custom_text(text)
- Append text to the custom text that is included in the report. This is freeform and can include html.
- add_forbidden_path(forbidden)
- Specify a path to not copy, even if it’s part of a copy_specs[] entry.
- add_journal(units=None, boot=None, since=None, until=None, lines=None, allfields=False, output=None, timeout=None)
- Collect journald logs from one of more units.
Keyword arguments: units – A string, or list of strings specifying the systemd
- boot – A string selecting a boot index using the journalctl
- syntax. The special values ‘this’ and ‘last’ are also accepted.
- since – A string representation of the start time for journal
- messages.
- until – A string representation of the end time for journal
- messages.
lines – The maximum number of lines to be collected. allfields – Include all journal fields regardless of size or
- output – A journalctl output control string, for example
- “verbose”.
timeout – An optional timeout in seconds.
- add_string_as_file(content, filename)
- Add a string to the archive as a file named filename
- archive = None
- call_ext_prog(prog, timeout=300, stderr=True, chroot=True, runat=None)
- Execute a command independantly of the output gathering part of sosreport.
- check_enabled()
- This method will be used to verify that a plugin should execute given the
condition of the underlying environment.
The default implementation will return True if none of class.files, class.packages, nor class.commands is specified. If any of these is specified the plugin will check for the existence of any of the corresponding paths, packages or commands and return True if any are present.
For SCLPlugin subclasses, it will check whether the plugin can be run for any of installed SCLs. If so, it will store names of these SCLs on the plugin class in addition to returning True.
For plugins with more complex enablement checks this method may be overridden.
- check_ext_prog(prog)
- Execute a command independently of the output gathering part of sosreport and check the return code. Return True for a return code of 0 and False otherwise.
- collect()
- Collect the data for a plugin.
- commands = ()
- default_enabled()
- This decides whether a plugin should be automatically loaded or only if manually specified in the command line.
- do_cmd_output_sub(cmd, regexp, subst)
- Apply a regexp substitution to command output archived by sosreport. cmd
is the command name from which output is collected (i.e. excluding
parameters). The regexp can be a string or a compiled re object. The
substitution string, subst, is a string that replaces each occurrence of
regexp in each file collected from cmd. Internally ‘cmd’ is
treated as a glob with a leading and trailing ‘*’ and each
matching file from the current module’s command list is subjected
to the replacement.
This function returns the number of replacements made.
- do_cmd_private_sub(cmd)
- Remove certificate and key output archived by sosreport. cmd is the
command name from which output is collected (i.e. exlcuding parameters).
Any matching instances are replaced with:
‘—–SCRUBBED’ and this function does not take a
regexp or substituting string.
This function returns the number of replacements made.
- do_file_sub(srcpath, regexp, subst)
- Apply a regexp substitution to a file archived by sosreport. srcpath is
the path in the archive where the file can be found. regexp can be a
regexp string or a compiled re object. subst is a string to replace each
occurance of regexp in the content of srcpath.
This function returns the number of replacements made.
- do_path_regex_sub(pathexp, regexp, subst)
- Apply a regexp substituation to a set of files archived by sos. The set of files to be substituted is generated by matching collected file pathnames against pathexp which may be a regular expression string or compiled re object. The portion of the file to be replaced is specified via regexp and the replacement string is passed in subst.
- do_regex_find_all(regex, fname)
- file_grep(regexp, *fnames)
- Returns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by line.
- files = ()
- get_all_options()
- return a list of all options selected
- get_cmd_output_now(exe, suggest_filename=None, root_symlink=False, timeout=300, stderr=True, chroot=True, runat=None, env=None)
- Execute a command and save the output to a file for inclusion in the report.
- get_cmd_output_path(name=None, make=True)
- Return a path into which this module should store collected command output
- get_command_output(prog, timeout=300, stderr=True, chroot=True, runat=None, env=None)
- get_description()
- This function will return the description for the plugin
- get_option(optionname, default=0)
- Returns the first value that matches ‘optionname’ in
parameters passed in via the command line or set via set_option or via the
global_plugin_options dictionary, in that order.
optionaname may be iterable, in which case the first option that matches any of the option names is returned.
- get_option_as_list(optionname, delimiter=', ', default=None)
- Will try to return the option as a list separated by the delimiter.
- is_installed(package_name)
- Is the package $package_name installed?
- is_module_loaded(module_name)
- Return whether specified moudle as module_name is loaded or not
- join_sysroot(path)
- classmethod name()
- Returns the plugin’s name as a string. This should return a lowercase string.
- packages = ()
- plugin_name = None
- policy()
- postproc()
- Perform any postprocessing. To be replaced by a plugin if required.
- profiles = ()
- report()
- Present all information that was gathered in an html file that allows browsing the results.
- requires_root = True
- set_option(optionname, value)
- set the named option to value.
- setup()
- Collect the list of files declared by the plugin. This method may be overridden to add further copy_specs, forbidden_paths, and external programs if required.
- setup_verify()
- strip_sysroot(path)
- sysroot = '/'
- tmp_in_sysroot()
- use_sysroot()
- version = 'unversioned'
- class sos.plugins.PowerKVMPlugin
- Bases: sos.plugins.RedHatPlugin
Tagging class for IBM PowerKVM Linux
- class sos.plugins.RedHatPlugin
- Bases: object
Tagging class for Red Hat’s Linux distributions
- class sos.plugins.SCLPlugin
- Bases: sos.plugins.RedHatPlugin
Superclass for plugins operating on Software Collections (SCLs).
Subclasses of this plugin class can specify class.files and class.packages using “%(scl_name)s” interpolation. The plugin invoking mechanism will try to match these against all found SCLs on the system. SCLs that do match class.files or class.packages are then accessible via self.scls_matched when the plugin is invoked.
Additionally, this plugin class provides “add_cmd_output_scl” (run a command in context of given SCL), and “add_copy_spec_scl” and “add_copy_spec_limit_scl” (copy package from file system of given SCL).
For example, you can implement a plugin that will list all global npm packages in every SCL that contains “npm” package:
- class SCLNpmPlugin(Plugin, SCLPlugin):
- packages = (“%(scl_name)s-npm”,)
- def setup(self):
- for scl in self.scls_matched:
- self.add_cmd_output_scl(scl, “npm ls -g –json”)
- add_cmd_output_scl(scl, cmds, **kwargs)
- Same as add_cmd_output, except that it wraps command in “scl enable” call.
- add_copy_spec_limit_scl(scl, copyspec, **kwargs)
- Same as add_copy_spec_limit, except that it prepends path to SCL root to “copyspec”.
- add_copy_spec_scl(scl, copyspecs)
- Same as add_copy_spec, except that it prepends path to SCL root to “copyspecs”.
- convert_copyspec_scl(scl, copyspec)
- scls_matched
- class sos.plugins.SuSEPlugin
- Bases: object
Tagging class for SuSE Linux distributions
- class sos.plugins.UbuntuPlugin
- Bases: object
Tagging class for Ubuntu Linux
- class sos.plugins.ZKVMPlugin
- Bases: sos.plugins.RedHatPlugin
Tagging class for IBM ZKVM Linux
- sos.plugins.import_plugin(name, superclasses=None)
- Import name as a module and return a list of all classes defined in that module. superclasses should be a tuple of valid superclasses to import, this defaults to (Plugin,).
- sos.plugins.regex_findall(regex, fname)
- Return a list of all non overlapping matches in the string(s)
CORE REFERENCE
sos.archive — Archive Interface
- class sos.archive.Archive
- Bases: object
Abstract base class for archives.
- add_dir(path)
- add_file(src, dest=None)
- add_link(source, link_name)
- add_node(path, mode, device)
- add_string(content, dest)
- classmethod archive_type()
- Returns the archive class’s name as a string.
- cleanup()
- Clean up any temporary resources used by an Archive class.
- finalize(method)
- Finalize an archive object via method. This may involve creating An archive that is subsequently compressed or simply closing an archive that supports in-line handling. If method is automatic then the following methods are tried in order: xz, bz2 and gzip
- get_archive_path()
- Return a string representing the path to the temporary archive. For archive classes that implement in-line handling this will be the archive file itself. Archives that use a directory based cache prior to packaging should return the path to the temporary directory where the report content is located
- get_tmp_dir()
- Return a temporary directory that clients of the archive may use to write content to. The content of the path is guaranteed to be included in the generated archive.
- log = <logging.Logger object>
- log_debug(msg)
- log_error(msg)
- log_info(msg)
- log_warn(msg)
- name_max()
- Return the maximum file name length this archive can support. This is the lesser of the name length limit of the archive format and any temporary file system based cache.
- set_debug(debug)
- class sos.archive.FileCacheArchive(name, tmpdir)
- Bases: sos.archive.Archive
Abstract superclass for archive types that use a temporary cache directory in the file system.
- add_dir(path)
- add_file(src, dest=None)
- add_link(source, link_name)
- add_node(path, mode, device)
- add_string(content, dest)
- cleanup()
- dest_path(name)
- finalize(method)
- get_archive_path()
- get_tmp_dir()
- makedirs(path, mode=448)
- name_max()
- open_file(path)
- class sos.archive.TarFileArchive(name, tmpdir)
- Bases: sos.archive.FileCacheArchive
archive class using python TarFile to create tar archives
- copy_permissions_filter(tarinfo)
- get_selinux_context(path)
- method = None
- name()
- name_max()
- set_tarinfo_from_stat(tar_info, fstat, mode=None)
sos.policies — Policy Interface
- class sos.policies.GenericPolicy(sysroot=None)
- 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()
- class sos.policies.LinuxPolicy(sysroot=None)
- 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()
- distro = 'Linux'
- get_arch()
- get_local_name()
- Returns the name usd in the pre_work step
- get_preferred_hash_name()
- host_name()
- is_kernel_smp()
- kernel_version()
- pre_work()
- sanitize_case_id(case_id)
- sanitize_report_name(report_name)
- vendor = 'None'
- class sos.policies.PackageManager(chroot=None, query_command=None, verify_command=None, verify_filter=None)
- 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_pkgs()
- Return a list of all packages.
- all_pkgs_by_name(name)
- Return a list of packages that match name.
- all_pkgs_by_name_regex(regex_name, flags=0)
- Return a list of packages that match regex_name.
- build_verify_command(self, packages) -> str
- 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
- get_pkg_list()
- Returns a dictionary of packages in the following format:
{'package_name': {'name': 'package_name',
'version': 'major.minor.version'}}
- pkg_by_name(name)
- Return a single package that matches name.
- pkg_nvra(pkg)
- query_command = None
- verify_command = None
- verify_filter = None
- class sos.policies.Policy(sysroot=None)
- Bases: object
- PATH = ''
- check()
- This function is responsible for determining if the underlying system is supported by this policy.
- del_valid_subclasses()
- display_results(archive, directory, checksum)
- dist_version()
- Return the OS version
- distro = 'Unknown'
- get_archive_name()
- This function should return the filename of the archive without the extension.
- get_msg()
- 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()
- Return the class object of the prefered archive format for this platform
- get_preferred_hash_name()
- Returns the string name of the hashlib-supported checksum algorithm to use
- get_tmp_dir(opt_tmp_dir)
- get_valid_subclasses()
- host_sysroot()
- in_container()
- Returns True if sos is running inside a container environment.
- is_root()
- This method should return true if the user calling the script is considered to be a superuser
- match_plugin(plugin_classes)
- 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'
- pkg_by_name(pkg)
- post_work()
- This function is called after the sosreport has been generated.
- pre_work()
- This function is called prior to collection.
- set_commons(commons)
- set_exec_path()
- set_valid_subclasses(subclasses)
- valid_subclasses
- list of subclasses that this policy can process
- validate_plugin(plugin_class, experimental=False)
- Verifies that the plugin_class should execute under this policy
- vendor = 'Unknown'
- vendor_text = ''
- vendor_url = 'http://www.example.com/'
- sos.policies.import_policy(name)
- sos.policies.load(cache={}, sysroot=None)
sos.reporting — Reporting Interface
This provides a restricted tag language to define the sosreport index/report
- class sos.reporting.Alert(content)
- Bases: sos.reporting.Leaf
- ADDS_TO = 'alerts'
- class sos.reporting.Command(name, return_code, href)
- Bases: sos.reporting.Leaf
- ADDS_TO = 'commands'
- class sos.reporting.CopiedFile(name, href)
- Bases: sos.reporting.Leaf
- ADDS_TO = 'copied_files'
- class sos.reporting.CreatedFile(name)
- Bases: sos.reporting.Leaf
- ADDS_TO = 'created_files'
- class sos.reporting.Leaf
- Bases: sos.reporting.Node
Marker class that can be added to a Section node
- class sos.reporting.Node
- Bases: object
- can_add(node)
- class sos.reporting.Note(content)
- Bases: sos.reporting.Leaf
- ADDS_TO = 'notes'
- class sos.reporting.PlainTextReport(report_node)
- Bases: object
Will generate a plain text report from a top_level Report object
- ALERT = ' ! %s'
- DIVIDER = '========================================================================'
- LEAF = ' * %(name)s'
- NOTE = ' * %s'
- line_buf = []
- process_subsection(section, key, header, format_)
- subsections = ((<class 'sos.reporting.Command'>, ' * %(name)s', '- commands executed:'), (<class 'sos.reporting.CopiedFile'>, ' * %(name)s', '- files copied:'), (<class 'sos.reporting.CreatedFile'>, ' * %(name)s', '- files created:'), (<class 'sos.reporting.Alert'>, ' ! %s', '- alerts:'), (<class 'sos.reporting.Note'>, ' * %s', '- notes:'))
- unicode()
- class sos.reporting.Report
- Bases: sos.reporting.Node
The root element of a report. This is a container for sections.
- add(*nodes)
- can_add(node)
- class sos.reporting.Section(name)
- Bases: sos.reporting.Node
A section is a container for leaf elements. Sections may be nested inside of Report objects only.
- add(*nodes)
- can_add(node)
- sos.reporting.ends_bs(string)
- Return True if ‘string’ ends with a backslash, and False
otherwise.
Define this as a named function for no other reason than that pep8 now forbids binding of a lambda expression to a name:
‘E731 do not assign a lambda expression, use a def’
sos.utilities — Utilites Interface
- class sos.utilities.ImporterHelper(package)
- Bases: object
Provides a list of modules that can be imported in a package. Importable modules are located along the module __path__ list and modules are files that end in .py.
- get_modules()
- Returns the list of importable modules in the configured python package.
- sos.utilities.convert_bytes(bytes_, K=1024, M=1048576, G=1073741824, T=1099511627776)
- Converts a number of bytes to a shorter, more human friendly format
- sos.utilities.fileobj(path_or_file, mode='r')
- Returns a file-like object that can be used as a context manager
- sos.utilities.find(file_pattern, top_dir, max_depth=None, path_pattern=None)
- Generator function to find files recursively. Usage:
for filename in find("*.properties", "/var/log/foobar"):
print filename
- sos.utilities.grep(pattern, *files_or_paths)
- Returns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by line
- sos.utilities.import_module(module_fqname, superclasses=None)
- Imports the module module_fqname and returns a list of defined classes from that module. If superclasses is defined then the classes returned will be subclasses of the specified superclass or superclasses. If superclasses is plural it must be a tuple of classes.
- sos.utilities.is_executable(command)
- Returns if a command matches an executable on the PATH
- sos.utilities.shell_out(cmd, timeout=30, chroot=None, runat=None)
- Shell out to an external command and return the output or the empty string in case of error.
- sos.utilities.sos_get_command_output(command, timeout=300, stderr=False, chroot=None, chdir=None, env=None)
- Execute a command and return a dictionary of status and output, optionally changing root or current working directory before executing command.
- sos.utilities.tail(filename, number_of_bytes)
- Returns the last number_of_bytes of filename
AUTHOR
Bryn Reeves
COPYRIGHT
2021, Bryn Reeves
| July 6, 2021 | 3.2 |
