sos.plugins
— Plugin Interface¶
This exports methods available for use by plugins for sos
-
class
sos.plugins.
ALTLinuxPlugin
[source] Bases:
object
Tagging class for ALT Linux
-
class
sos.plugins.
DebianPlugin
[source] Bases:
object
Tagging class for Debian Linux
-
class
sos.plugins.
ExperimentalPlugin
[source] Bases:
object
Tagging class that indicates that this plugin is experimental
-
class
sos.plugins.
IndependentPlugin
[source] Bases:
object
Tagging class for plugins that can run on any platform
-
class
sos.plugins.
Plugin
(commons)[source] 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)[source] 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)[source] Run a program or a list of programs and collect the output
-
add_copy_spec
(copyspecs, sizelimit=None, tailit=True)[source] 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)[source] Append text to the custom text that is included in the report. This is freeform and can include html.
-
add_forbidden_path
(forbidden)[source] 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)[source] Collect journald logs from one of more units.
Keyword arguments: units – A string, or list of strings specifying the systemd
units for which journal entries will be collected.- 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
non-printable characters.- output – A journalctl output control string, for example
- “verbose”.
timeout – An optional timeout in seconds.
-
add_string_as_file
(content, filename)[source] 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)[source] Execute a command independantly of the output gathering part of sosreport.
-
check_enabled
()[source] 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)[source] 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
()[source] Collect the data for a plugin.
-
commands
= ()
-
default_enabled
()[source] 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)[source] 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)[source] 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)[source] 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)[source] 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)[source]
-
file_grep
(regexp, *fnames)[source] 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
()[source] 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)[source] Execute a command and save the output to a file for inclusion in the report.
-
get_cmd_output_path
(name=None, make=True)[source] 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)[source]
-
get_description
()[source] This function will return the description for the plugin
-
get_option
(optionname, default=0)[source] 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)[source] Will try to return the option as a list separated by the delimiter.
-
is_installed
(package_name)[source] Is the package $package_name installed?
-
is_module_loaded
(module_name)[source] Return whether specified moudle as module_name is loaded or not
-
join_sysroot
(path)[source]
-
classmethod
name
()[source] Returns the plugin’s name as a string. This should return a lowercase string.
-
packages
= ()
-
plugin_name
= None
-
policy
()[source]
-
postproc
()[source] Perform any postprocessing. To be replaced by a plugin if required.
-
profiles
= ()
-
report
()[source] Present all information that was gathered in an html file that allows browsing the results.
-
requires_root
= True
-
set_option
(optionname, value)[source] set the named option to value.
-
setup
()[source] 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
()[source]
-
strip_sysroot
(path)[source]
-
sysroot
= '/'
-
tmp_in_sysroot
()[source]
-
use_sysroot
()[source]
-
version
= 'unversioned'
-
-
class
sos.plugins.
PowerKVMPlugin
[source] Bases:
sos.plugins.RedHatPlugin
Tagging class for IBM PowerKVM Linux
-
class
sos.plugins.
RedHatPlugin
[source] Bases:
object
Tagging class for Red Hat’s Linux distributions
-
class
sos.plugins.
SCLPlugin
[source] 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)[source] Same as add_cmd_output, except that it wraps command in “scl enable” call.
-
add_copy_spec_limit_scl
(scl, copyspec, **kwargs)[source] Same as add_copy_spec_limit, except that it prepends path to SCL root to “copyspec”.
-
add_copy_spec_scl
(scl, copyspecs)[source] Same as add_copy_spec, except that it prepends path to SCL root to “copyspecs”.
-
convert_copyspec_scl
(scl, copyspec)[source]
-
scls_matched
-
class
sos.plugins.
SuSEPlugin
[source] Bases:
object
Tagging class for SuSE Linux distributions
-
class
sos.plugins.
UbuntuPlugin
[source] Bases:
object
Tagging class for Ubuntu Linux
-
class
sos.plugins.
ZKVMPlugin
[source] Bases:
sos.plugins.RedHatPlugin
Tagging class for IBM ZKVM Linux
-
sos.plugins.
import_plugin
(name, superclasses=None)[source] 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)[source] Return a list of all non overlapping matches in the string(s)