sos.report.plugins — Plugin Interface¶
This exports methods available for use by plugins for sos
- class sos.report.plugins.AzurePlugin[source]¶
Bases:
PluginDistroTagTagging class for Azure Linux
- class sos.report.plugins.CosPlugin[source]¶
Bases:
PluginDistroTagTagging class for Container-Optimized OS
- class sos.report.plugins.DebianPlugin[source]¶
Bases:
PluginDistroTagTagging class for Debian Linux
- class sos.report.plugins.ExperimentalPlugin[source]¶
Bases:
PluginDistroTagTagging class that indicates that this plugin is experimental
- class sos.report.plugins.IndependentPlugin[source]¶
Bases:
PluginDistroTagTagging class for plugins that can run on any platform
- class sos.report.plugins.OpenEulerPlugin[source]¶
Bases:
PluginDistroTagTagging class for openEuler linux distributions
- class sos.report.plugins.Plugin(commons)[source]¶
Bases:
objectThis is the base class for sos report plugins. Plugins should subclass this and set the class variables where applicable.
- Parameters:
commons (
dict) – A set of information that is shared internally so that plugins may access the same dataset. This is provided automatically by sos
Each Plugin() subclass should also subclass at least one tagging class, e.g.
RedHatPlugin, to support that distribution. If different distributions require different collections, each distribution should have its own subclass of the Plugin that also subclasses the tagging class for their respective distributions.- Variables:
plugin_name (
str) – The name of the plugin, will be returned by name()packages (
tuple) – Package name(s) that, if installed, enable this pluginfiles (
tuple) – File path(s) that, if present, enable this plugincommands (
tuple) – Executables that, if present, enable this pluginkernel_mods (
tuple) – Kernel module(s) that, if loaded, enable this pluginservices (
tuple) – Service name(s) that, if running, enable this pluginarchitectures (
tuple, orNone) – Architecture(s) this plugin is enabled for. Defaults to ‘none’ to enable on all arches.profiles (
tuple) – Name(s) of profile(s) this plugin belongs toplugin_timeout (
int) – Timeout in seconds for this plugin as a wholecmd_timeout (
int) – Timeout in seconds for individual commands
- add_alert(alertstring)[source]¶
Add an alert to the collection of alerts for this plugin. These will be displayed in the report
- Parameters:
alertstring (
str) – The text to add as an alert
- add_cmd_output(cmds, suggest_filename=None, root_symlink=None, timeout=None, stderr=True, chroot=True, runat=None, env=None, binary=False, sizelimit=None, pred=None, subdir=None, changes=False, foreground=False, tags=[], priority=10, cmd_as_tag=False, container=None, to_file=False, runas=None, snap_cmd=False, runtime=None)[source]¶
Run a program or a list of programs and collect the output
Output will be limited to sizelimit, collecting the last X amount of command output matching sizelimit. Unless suggest_filename is set, the file that the output is saved to will match the command as it was executed, and will be saved under sos_commands/$plugin
- Parameters:
cmds (
stror alistof strings) – The command(s) to executesuggest_filename (
str) – Override the name of the file output is saved to within the archiveroot_symlink (
str) – If set, create a symlink with this name in the archive roottimeout (
int) – Timeout in seconds to allow each cmd to run forstderr (
bool) – Should stderr output be collectedchroot (
bool) – Should sos chroot the cmds being runrunat (
str) – Run the cmds from this location in the filesystemenv (
dict) – Set environment variables for the cmds being runbinary (
bool) – Is the command expected to produce binary outputsizelimit (
int) – Maximum amount of output in MB to savepred (
SoSPredicate) – A predicate to gate if cmds should be collected or notsubdir (
str) – Save output to this subdirectory, within the plugin’s directory under sos_commandschanges (
int) – Do cmds have the potential to change system stateforeground (
bool) – Should the cmds be run in the foreground, with an attached TTYtags (
stror alistof strings) – A tag or set of tags to add to the metadata entries for the cmds being runpriority (
int) – The priority with which this command should be run, lower values will run before higher valuescmd_as_tag (
bool) – Should the command string be automatically formatted to a tag?container (
str) – Run the specified cmds inside a container with this ID or nameto_file (
bool) – Should command output be written directly to a new file rather than stored in memory?runas (
str) – Run the cmd as the runas usersnap_cmd (
bool) – Are the commands being run from a snap?runtime (
str) – Specific runtime to use to run container cmd
- add_cmd_tags(tagdict)[source]¶
Retroactively add tags to any commands that have been run by this plugin that match a given regex
- Parameters:
tagdict (
dict) – A dict containing the command regex and associated tags
tagdict takes the form of {cmd_regex: tags}, for example to tag all commands starting with foo with the tag bar, use {‘foo.*’: [‘bar’]}
- add_container_logs(containers, get_all=False, **kwargs)[source]¶
Helper to get the
logsoutput for a given container or list of container names and/or regexes.Supports passthru of add_cmd_output() options
- Parameters:
containers (
strorlistof strs) – The name of the container to retrieve logs from, may be a single name or a regexget_all (
bool) – Should non-running containers also be queried? Default: Falsekwargs – Any kwargs supported by
add_cmd_output()are supported here
- add_copy_spec(copyspecs, sizelimit=None, maxage=None, tailit=True, pred=None, tags=[], container=None, runas=None)[source]¶
Add a file, directory, or globs matching filepaths to the archive
- Parameters:
copyspecs (
stror alistof strings) – Files, directories, or globs matching filepathssizelimit (
int) – Limit the total size of collections from copyspecs to this size in MBmaxage (
int) – Collect files with mtime not older than this many hourstailit (
bool) – Should a file that exceeds sizelimit be tail’ed to fit the remaining space to meet sizelimitpred (
SoSPredicate) – A predicate to gate if copyspecs should be collectedtags (
stror alistof strings) – A tag or set of tags to add to the metadata information for this collectioncontainer (
stror alistof strings) – Container(s) from which this file should be copiedrunas (
str) – When collecting data from a container, run it under this user.
copyspecs will be expanded and/or globbed as appropriate. Specifying a directory here will cause the plugin to attempt to collect the entire directory, recursively.
If container is specified, copyspecs may only be explicit paths, not globs as currently container runtimes do not support glob expansion as part of the copy operation.
Note that sizelimit is applied to each copyspec, not each file individually. For example, a copyspec of
['/etc/foo', '/etc/bar.conf']and a sizelimit of 25 means that sos will collect up to 25MB worth of files within /etc/foo, and will collect the last 25MB of /etc/bar.conf.
- add_custom_text(text)[source]¶
Append text to the custom text that is included in the report. This is freeform and can include html.
- Parameters:
text (
str) – The text to include in the report
- add_default_cmd_environment(env_vars)[source]¶
Add or modify a specific environment variable in the set of default environment variables used by this Plugin.
- Parameters:
env_vars (
dict) – The environment variables to add to the current set of env vars in use
- add_default_collections()[source]¶
Based on the class attrs defined for plugin enablement, add a standardized set of collections before we call the plugin’s own setup() method.
- add_device_cmd(cmds, devices, timeout=None, sizelimit=None, chroot=True, runat=None, env=None, binary=False, prepend_path=None, whitelist=[], blacklist=[], tags=[], priority=10, subdir=None)[source]¶
Run a command or list of commands against devices discovered during sos initialization.
Any commands specified by cmd will be iterated over the list of the specified devices. Commands passed to this should include a ‘%(dev)s’ variable for substitution.
- Parameters:
cmds (
stror alistof strings) – The command(s) to run against the list of devicesdevices (
stror alistof devices or device paths.) – The device paths to run cmd against. This should be either a list of devices/device paths or a key in the devices dict discovered by sos during initialization.timeout (
int) – Timeout in seconds to allow each cmd to runsizelimit (
int) – Maximum amount of output to collect, in MBchroot (
bool) – Should sos chroot the command(s) being runrunat (
str) – Set the filesystem location to execute the command fromenv (
dict) – Set environment variables for the command(s) being runbinary (
bool) – Is the output collected going to be binary dataprepend_path (
strorNone) – The leading path for block device nameswhitelist (
listofstr) – Limit the devices the cmds will be run against to devices matching these item(s)blacklist (
listofstr) – Do not run cmds against devices matching these item(s)subdir (
str) – Write the command output to this subdir within the Plugin directory
- add_dir_listing(paths, tree=False, recursive=False, chroot=True, env=None, sizelimit=None, pred=None, subdir=None, tags=[], runas=None, container=None, suggest_filename=None, extra_opts=None)[source]¶
Used as a way to standardize our collections of directory listings, either as an output of ls or tree depending on if the tree parameter is set to True.
This is ultimately a wrapper around add_cmd_output() and supports several, but not all, of the options for that method.
- Parameters:
paths (
stror alistof ``str``s) – The path(s) to collect a listing fortree (
bool(default: False)) – Collect output with tree instead of lsrecursive (
bool(default: False)) – Recursively list directory contents with ls
- add_env_var(name)[source]¶
Add an environment variable to the list of to-be-collected env vars.
Collected environment variables will be saved to an environment file in the archive root, and any variable specified for collection will be collected in lowercase, uppercase, and the form provided
- Parameters:
name (
str) – The name of the environment variable to collect
- add_file_tags(tagdict)[source]¶
Apply a tag to a file matching a given regex, for use when a file is copied by a more generic copyspec.
- Parameters:
tagdict (
dict) – A dict containing the filepatterns to match and the tag(s) to apply to those files
tagdict takes the form {file_pattern: tag}, E.G. to match all bond devices from /proc/net/bonding with the tag bond, use {‘/proc/net/bonding/bond.*’: [‘bond’]}
- add_forbidden_path(forbidden)[source]¶
Specify a path, or list of paths, to not copy, even if it’s part of an
add_copy_spec()call- Parameters:
forbidden (
stror alistof strings) – A filepath to forbid collection from
- add_journal(units=None, boot=None, since=None, until=None, lines=None, allfields=False, output=None, timeout=None, identifier=None, catalog=None, sizelimit=None, pred=None, tags=None, priority=10)[source]¶
Collect journald logs from one of more units.
- Parameters:
units (
stror alistof strings) – Which journald units to collectboot (
str) – A boot index using the journalctl syntax. The special values ‘this’ and ‘last’ are also accepted.since (
str) – Start time for journal messagesuntil (
str) – End time forjournal messageslines (
int) – The maximum number of lines to be collectedallfields (
bool) – Include all journal fields regardless of size or non-printable charactersoutput (
str) – Journalctl output control string, for example “verbose”timeout (
int) – An optional timeout in secondsidentifier (
str) – An optional message identifiercatalog (
bool) – Augment lines with descriptions from the system catalogsizelimit (
int) – Limit to the size of output returned in MB. Defaults to the value of –log-size.
- add_service_status(services, **kwargs)[source]¶
Collect service status information based on the
InitSystemused- Parameters:
services (
stror alistof strings) – Service name(s) to collect statuses forkwargs – Optional arguments to pass to add_cmd_output (timeout, predicate, suggest_filename,..)
- add_string_as_file(content, filename, pred=None, plug_dir=False, tags=[])[source]¶
Add a string to the archive as a file
- Parameters:
content (
str) – The string to write to the archivefilename (
str) – The name of the file to write content topred (
SoSPredicate) – A predicate to gate if the string should be added to the archive or notplug_dir (
bool) – Should the string be saved under the plugin’s dir in sos_commands/? If false, save to sos_strings/tags (
stror alistof strings) – A tag or set of tags to add to the manifest entry for this collection
- architectures = None¶
- archive = None¶
- 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 plugins with more complex enablement checks this method may be overridden.
- Returns:
Trueif the plugin should be run for this system, elseFalse- Return type:
bool
- check_is_architecture()[source]¶
Checks whether or not the system is running on an architecture that the plugin allows. If not architecture is set, assume plugin can run on all arches.
- Returns:
Trueif the host’s architecture allows the plugin to run, elseFalse- Return type:
bool
- check_process_by_name(process)[source]¶
Checks if a named process is found in /proc/[0-9]*/cmdline.
- Parameters:
process (
str) – The name of the process- Returns:
Trueif the process exists, elseFalse- Return type:
bool
- check_timeout()[source]¶
Checks to see if the plugin has hit its timeout.
This is set when the sos.collect_plugin() method hits a timeout and terminates the thread. From there, a Popen() call can still continue to run, and we need to manually terminate it. Thus, check_timeout() should only be called in sos_get_command_output().
Since sos_get_command_output() is not plugin aware, this method is handed to that call to use as a polling method, to avoid passing the entire plugin object.
- Returns:
Trueif timeout has been hit, elseFalse- Return type:
bool
- cmd_predicate = None¶
- cmd_timeout = 300¶
- cmdtags = {}¶
- property cmdtimeout¶
Returns either the default command timeout value, the value as provided on the commandline via -k plugin.cmd-timeout=value, or the value of the global –cmd-timeout option.
- collect()[source]¶
If a plugin needs to manually compile some data for a collection, that should be specified here by overriding this method.
These collections are run last during a plugin’s execution, and as such are more likely to be interrupted by timeouts than file or command output collections.
- collect_cmd_output(cmd, suggest_filename=None, root_symlink=False, timeout=None, stderr=True, chroot=True, runat=None, env=None, binary=False, sizelimit=None, pred=None, changes=False, foreground=False, subdir=None, tags=[], runas=None)[source]¶
Execute a command and save the output to a file for inclusion in the report, then return the results for further use by the plugin
- Parameters:
cmd (
str) – The command to runsuggest_filename – Filename to use when writing to the archive
suggest_filename –
strroot_symlink (
bool) – Create a symlink in the archive roottimeout (
int) – Time in seconds to allow a cmd to runstderr (
bool) – Write stderr to stdout?chroot (
bool) – Perform chroot before running cmd?runat (
str) – Run the command from this location, overriding chrootenv (
dict) – Environment vars to set for the cmdbinary (
bool) – Is the output in binary?sizelimit (
int) – Maximum size in MB of output to savesubdir (
str) – Subdir in plugin directory to save tochanges (
bool) – Does this cmd potentially make a change on the system?foreground (
bool) – Run the cmd in the foreground with a TTYtags (
stror alistof strings) – Add tags in the archive manifestrunas (
str) – Run the cmd as the runas user
- Returns:
cmd exit status, output, and the filepath within the archive output was saved to
- Return type:
dict
- collection_file(fname, subdir=None, tags=[])[source]¶
Handles creating and managing files within a plugin’s subdirectory within the archive, and is intended to be used to save manually compiled data generated during a plugin’s
_collect_manual()step of the collection phase.Plugins should call this method using a
withcontext manager.- Parameters:
fname (
str) – The name of the file within the plugin directorysubdir (
str) – If needed, specify a subdir to write the file totags (
strorlistofstr) – Tags to be added to this file in the manifest
- commands = ()¶
- container_exists(name, runtime=None)[source]¶
If a container runtime is present, check to see if a container with a given name is currently running
- Parameters:
name (
str) – The name or ID of the container to check presence ofruntime (
str) – The runtime to use
- Returns:
Trueif name exists, elseFalse- Return type:
bool
- container_path_exists(path, container, runas=None)[source]¶
Check if a path exists inside a container before collecting a dir listing
- Parameters:
path (
str) – The canonical path for a specific file/directory in a containercontainer (
str) – The container where to check for the path
- Returns:
True if the path exists in the container, else False
- Return type:
bool
- containers = ()¶
- 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 sos
This is used to obfuscate sensitive information captured by command output collection via plugins.
- Parameters:
cmd (
str) – The command name/binary name for collected output that needs to be obfuscated. Internally globbed with a leading and trailing *regexp (
stror compilereobject) – A regex to match the contents of the command output againstsubst (
str) – The substitution string used to replace matches from regexp
- Returns:
Number of replacements made
- Return type:
int
- do_cmd_private_sub(cmd, desc='')[source]¶
Remove certificate and key output archived by sos report. Any matching instances are replaced with: ‘—–SCRUBBED’ and this function does not take a regexp or substituting string.
- Parameters:
cmd (
str) – The name of the binary to scrub certificate output fromdesc (
str) – An identifier to add to the SCRUBBED header line
- Returns:
Number of replacements made
- Return type:
int
- do_file_private_sub(pathregex, desc='')[source]¶
Scrub certificate/key/etc information from files collected by sos.
Files matching the provided pathregex are searched for content that resembles certificate, ssh keys, or similar information. Any matches are replaced with “—–SCRUBBED $desc” where desc is a description of the specific type of content being replaced, e.g. “—–SCRUBBED RSA PRIVATE KEY” so that support representatives can at least be informed of what type of content it was originally.
- Parameters:
pathregex (
str) – A string or regex of a filename to match againstdesc (
str) – A description of the replaced content
- do_file_sub(srcpath, regexp, subst)[source]¶
Apply a regexp substitution to a file archived by sos report.
- Parameters:
srcpath (
str) – Path in the archive where the file can be foundregexp (
stror compiledreobject) – A regex to match the contents of the filesubst (
str) – The substitution string to be used to replace matches within the file
- Returns:
Number of replacements made
- Return type:
int
- 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.
- Parameters:
pathexp (
stror compiledreobject) – A regex to match filenames within the archiveregexp (
stror compiledreobject) – A regex to match against the contents of each filesubst (
str) – The substituion string to be used to replace matches
- do_paths_http_sub(pathspecs)[source]¶
Obfuscate Basic_AUTH URL credentials in all files in the given list. Proxy setting without protocol is ignored, since that is not recommended setting and obfuscating that one can hit false positives.
- Parameters:
pathspecs (
stror alistof strings) – A filepath to obfuscate credentials in
- exec_cmd(cmd, timeout=None, stderr=True, chroot=True, runat=None, env=None, binary=False, pred=None, foreground=False, container=False, quotecmd=False, runas=None, runtime=None)[source]¶
Execute a command right now and return the output and status, but do not save the output within the archive.
Use this method in a plugin’s setup() if command output is needed to build subsequent commands added to a report via add_cmd_output().
- Parameters:
cmd (
str) – The command to runtimeout (
int) – Time in seconds to allow a cmd to runstderr (
bool) – Write stderr to stdout?chroot (
bool) – Perform chroot before running cmd?runat (
str) – Run the command from this location, overriding chrootenv (
dict) – Environment vars to set for the cmdbinary (
bool) – Is the output in binary?pred (
SoSPredicate) – A predicate to gate execution of the cmdforeground (
bool) – Run the cmd in the foreground with a TTYcontainer (
str) – Execute this command in a container with this namequotecmd (
bool) – Whether the cmd should be quoted.runas (
str) – Run the cmd as the runas userruntime (
str) – Specific runtime to use to execute the container command
- Returns:
Command exit status and output
- Return type:
dict
- file_grep(regexp, *fnames)[source]¶
Grep through file(s) for a specific string or regex
- Parameters:
regexp (
str) – The string or regex to search forfnames (
str,listof string, or open file objects) – Paths to grep through
- Returns:
Lines matching regexp
- Return type:
str
- files = ()¶
- filetags = {}¶
- filter_namespaces(ns_list, ns_pattern=None, ns_max=None)[source]¶
Filter a list of namespaces by regex pattern or max number of namespaces (options originally present in the networking plugin.)
- fmt_container_cmd(container, cmd, quotecmd=False, runtime=None, runas=None)[source]¶
Format a command to be executed by the loaded
ContainerRuntimein a specified container- Parameters:
container (
str) – The name of the container to execute the cmd incmd (
str) – The command to run within the containerquotecmd (
bool) – Whether the cmd should be quoted.runtime (
str) – The specific runtime to use to run the command within the containerrunas (
str) – What user runs the container. If set, we trust the container really runs (we dont keep them atm)
- Returns:
The command to execute so that the specified cmd will run within the container and not on the host
- Return type:
str
- generate_copyspec_tags()[source]¶
After file collections have completed, retroactively generate manifest entries to apply tags to files copied by generic copyspecs
- get_all_containers_by_regex(regex, get_all=False)[source]¶
Get a list of all container names and ID matching a regex
- Parameters:
regex (
str) – The regular expression to matchget_all (
bool) – Return all containers found, even terminated ones
- Returns:
All container IDs and names matching
regex- Return type:
listoftuplesas (id, name)
- get_cmd_output_path(name=None, make=True)[source]¶
Get the path where this plugin will save command output
- Parameters:
name (
strorNone) – Optionally specify a filename to use as part of the command output pathmake (
bool) – Attempt to create the command output path
- Returns:
The path where the plugin will write command output data within the archive
- Return type:
str
- get_container_by_name(name, runtime=None)[source]¶
Get the container ID for a specific container
- Parameters:
name (
str) – The name of the containerruntime (
str) – The runtime to use
- Returns:
The ID of the container if it exists
- Return type:
strorNone
- get_container_images(runtime=None)[source]¶
Return a list of all image names from the Policy’s ContainerRuntime
If runtime is not provided, use the Policy default. If the specified runtime is not loaded, return empty.
- Parameters:
runtime (
str) – The container runtime to use, if not using the default runtime detected by thePolicy- Returns:
A list of container images known to the runtime
- Return type:
list
- get_container_volumes(runtime=None)[source]¶
Return a list of all volume names from the Policy’s ContainerRuntime
If runtime is not provided, use the Policy default. If the specified runtime is not loaded, return empty.
- Parameters:
runtime (
str) – The container runtime to use, if not using the default runtime detected by thePolicy- Returns:
A list of container volumes known to the runtime
- Return type:
list
- get_containers(runtime=None, get_all=False)[source]¶
Return a list of all container IDs from the
PolicyContainerRuntimeIf runtime is not provided, use the
Policydefault- Parameters:
runtime (
str) – The container runtime to use, if not the default runtime detected and loaded by thePolicyget_all (
bool) – Return all containers known to the runtime, even those that have terminated
- Returns:
All container IDs found by the
ContainerRuntime- Return type:
list
- get_option(optionname, default=0)[source]¶
Retrieve the value of the requested option, searching in order: parameters passed from the command line, set via set_option(), or the global_plugin_options dict.
optionname may be iterable, in which case this function will return the first match.
- Parameters:
optionname (
str) – The name of the option to retrieve the value ofdefault – Optionally provide a default value to return if no option matching optionname is found. Default 0
- Returns:
The value of optionname if found, else default
- get_predicate(cmd=False, pred=None)[source]¶
Get the current default Plugin or command predicate.
- Parameters:
cmd (
bool) – If a command predicate is set, should it be used.pred (
SoSPredicate) – An optional predicate to pass if no command or plugin predicate is set
- Returns:
pred if neither a command predicate or plugin predicate is set. The command predicate if one is set and cmd is
True, else the plugin default predicate (which may beNone).- Return type:
SoSPredicateorNone
- get_process_pids(process)[source]¶
Get a list of all PIDs that match a specified name
- Parameters:
process (
str) – The name or regex of the process the get PIDs for- Returns:
A list of PIDs
- Return type:
list
- get_service_names(regex)[source]¶
Get all service names matching regex
- Parameters:
regex (
str) – A regex to match service names against- Returns:
All service name(s) matching the given regex
- Return type:
list
- get_service_status(name)[source]¶
Return the reported status for service $name
- Parameters:
name (
str) – The name of the service to check- Returns:
The state of the service according to the init system
- Return type:
str
- get_tags_for_cmd(cmd)[source]¶
Get the tag(s) that should be associated with the given command
- Parameters:
cmd (
str) – The command that tags should be applied to- Returns:
Any tags associated with the command
- Return type:
list
- get_tags_for_file(fname)[source]¶
Get the tags that should be associated with a file matching a given regex
- Parameters:
fname (
str) – A regex for filenames to be matched against- Returns:
The tag(s) associated with fname
- Return type:
listof strings
- is_installed(package_name)[source]¶
Is the package $package_name installed?
- Parameters:
package_name (
str) – The name of the package to check- Returns:
Trueid the package is installed, elseFalse- Return type:
bool
- is_module_loaded(module_name)[source]¶
Determine whether specified module is loaded or not
- Parameters:
module_name (
str) – Name of kernel module to check for presence- Returns:
Trueif the module is loaded, elseFalse- Return type:
bool
- is_service(name)[source]¶
Does the service $name exist on the system?
- Parameters:
name (
str) – The name of the service to check- Returns:
Trueif service is present on the system, elseFalse- Return type:
bool
- is_service_disabled(name)[source]¶
Is the service $name disabled?
- Parameters:
name (
str) – The name of the service to check- Returns:
Trueif service is disabled on the system, elseFalse- Return type:
bool
- is_service_enabled(name)[source]¶
Is the service $name enabled?
- Parameters:
name (
str) – The name of the service to check- Returns:
True if service is enabled on the system, else ``False- Return type:
bool
- is_service_running(name)[source]¶
Is the service $name currently running?
- Parameters:
name (
str) – The name of the service to check- Returns:
Trueif the service is running on the system, elseFalse- Return type:
bool
- is_snap = False¶
- is_snap_installed(package_name)[source]¶
Is the snap package $package_name installed?
- Parameters:
package_name (
str) – The name of the package to check- Returns:
Trueif the snap package is installed, elseFalse- Return type:
bool
- kernel_mods = ()¶
- listdir(path)[source]¶
Helper to call the sos.utilities wrapper that allows the corresponding os call to account for sysroot
- Parameters:
path (
str) – The canonical path for a specific file/directory- Returns:
Contents of path, if it is a directory
- Return type:
list
- log_skipped_cmd(cmd, pred, changes=False)[source]¶
Log that a command was skipped due to predicate evaluation.
Emit a warning message indicating that a command was skipped due to predicate evaluation. If
kmodsorservicesareTruethen the list of expected kernel modules or services will be included in the log message. Ifallow_changesisTruea message indicating that the missing data can be collected by using the “–allow-system-changes” command line option will be included.- Parameters:
cmd (
str) – The command that was skippedpred (
SoSPredicate) – The predicate that caused the command to be skippedchanges (
bool) – Is the –allow-system-changes enabled
- classmethod name()[source]¶
Get the name of the plugin
- Returns:
The name of the plugin, in lowercase
- Return type:
str
- option_list = []¶
- packages = ()¶
- path_exists(path)[source]¶
Helper to call the sos.utilities wrapper that allows the corresponding os call to account for sysroot
- Parameters:
path (
str) – The canonical path for a specific file/directory- Returns:
True if the path exists in sysroot, else False
- Return type:
bool
- path_isdir(path)[source]¶
Helper to call the sos.utilities wrapper that allows the corresponding os call to account for sysroot
- Parameters:
path (
str) – The canonical path for a specific file/directory- Returns:
True if the path is a dir, else False
- Return type:
bool
- path_isfile(path)[source]¶
Helper to call the sos.utilities wrapper that allows the corresponding os call to account for sysroot
- Parameters:
path (
str) – The canonical path for a specific file/directory- Returns:
True if the path is a file, else False
- Return type:
bool
- path_islink(path)[source]¶
Helper to call the sos.utilities wrapper that allows the corresponding os call to account for sysroot
- Parameters:
path (
str) – The canonical path for a specific file/directory- Returns:
True if the path is a link, else False
- Return type:
bool
- path_join(path, *p)[source]¶
Helper to call the sos.utilities wrapper that allows the corresponding os call to account for sysroot
- Parameters:
path (
str) – The leading path passed to os.path.join()p (
str) – Following path section(s) to be joined withpath, an empty parameter will result in a path that ends with a separator
- plugin_name = None¶
- plugin_timeout = 300¶
- predicate = None¶
- profiles = ()¶
- runtime = None¶
- services = ()¶
- set_cmd_predicate(pred)[source]¶
Set or clear the default predicate for command collection for this plugin. If set, this predecate takes precedence over the Plugin default predicate for command and journal data collection.
- Parameters:
pred (
SoSPredicate) – The predicate to use as the default command predicate
- set_default_cmd_environment(env_vars)[source]¶
Specify a collection of environment variables that should always be passed to commands being executed by this plugin.
- Parameters:
env_vars (
dict{ENV_VAR_NAME: ENV_VAR_VALUE}) – The environment variables and their values to set
- set_option(optionname, value)[source]¶
Set the named option to value. Ensure the original type of the option value is preserved
- Parameters:
optioname (
str) – The name of the option to setvalue – The value to set the option to
- Returns:
Trueif the option is successfully set, elseFalse- Return type:
bool
- set_plugin_manifest(manifest)[source]¶
Pass in a manifest object to the plugin to write to
- Parameters:
manifest (
SoSManifest) – The manifest that the plugin will add metadata to
- set_predicate(pred)[source]¶
Set or clear the default predicate for this plugin.
- Parameters:
pred (
SoSPredicate) – The predicate to use as the default for this plugin
- 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.
- short_desc = '<no description available>'¶
- signal_process_usr1(process)[source]¶
Send a SIGUSR1 to the pid(s) associated with the specified process name. Callers should be aware that a 1-second delay per signalled pid, up to 5 seconds at most, is expected as to allow sufficient time for the signalled process(es) to react to the received signal.
- Parameters:
process (
str) – The name or regex pattern of the process(es) to signal- Returns:
A list of pids that were successfully signalled
- Return type:
list
- strip_sysroot(path)[source]¶
Remove the configured sysroot from a filesystem path
- Parameters:
path (
str) – The filesystem path to strip sysroot from- Returns:
The stripped filesystem path
- Return type:
str
- sysroot = '/'¶
- test_predicate(cmd=False, pred=None)[source]¶
Test the current predicate and return its value.
- Parameters:
cmd –
Trueif the predicate is gating a command orFalseotherwise.pred – An optional predicate to override the current
Pluginor command predicate.
- Returns:
TrueorFalsebased on predicate evaluation, orFalseif no predicate- Return type:
bool
- property timeout¶
Returns either the default plugin timeout value, the value as provided on the commandline via -k plugin.timeout=value, or the value of the global –plugin-timeout option.
- timeout_from_options(optname, plugoptname, default_timeout)[source]¶
Get the timeout value for either the plugin or a command, as determined by either the value provided via the plugin.timeout or plugin.cmd-timeout option, the global timeout or cmd-timeout options, or the default value set by the plugin or the collection, in that order of precendence.
- Parameters:
optname (
str) – The name of the cmdline option being checked, either ‘plugin_timeout’ or ‘timeout’plugoptname (
str) – The name of the plugin option name being checked, either ‘timeout’ or ‘cmd-timeout’default_timeout (
int) – The timeout to default to if determination is inconclusive or hits an error
- Returns:
The timeout value in seconds
- Return type:
int
- class sos.report.plugins.PluginDistroTag[source]¶
Bases:
objectThe base tagging class for distro-specific classes used to signify that a Plugin is written for that distro.
Use IndependentPlugin for plugins that are distribution agnostic
- class sos.report.plugins.PluginOpt(name='undefined', default=None, desc='', long_desc='', val_type=None)[source]¶
Bases:
objectThis is used to define options available to plugins. Plugins will need to define options alongside their distro-specific classes in order to add support for user-controlled changes in Plugin behavior.
- Parameters:
name (
str) – The name of the plugin optiondefault (Any) – The default value of the option
desc (
str) – A short description of the effect of the optionlong_desc (
str) – A detailed description of the option. Will be used by sos infoval_type (A single type or a
listof types) – The type of object the option accepts for values. If not provided, auto-detect from the type ofdefault
- default = None¶
- desc = ''¶
- enabled = False¶
- long_desc = ''¶
- name = ''¶
- plugin = ''¶
- val_type = [None]¶
- value = None¶
- class sos.report.plugins.RedHatPlugin[source]¶
Bases:
PluginDistroTagTagging class for Red Hat’s Linux distributions
- class sos.report.plugins.SoSCommand(**kwargs)[source]¶
Bases:
objectA class to represent a command to be collected.
A SoSCommand() object is instantiated for each command handed to an _add_cmd_output() call, so that we no longer need to pass around a very long tuple to handle the parameters.
Any option supported by _add_cmd_output() is passed to the SoSCommand object and converted to an attribute. SoSCommand.__dict__ is then passed to _get_command_output_now() for each command to be collected.
- class sos.report.plugins.SoSPredicate(owner, dry_run=False, kmods=[], services=[], packages=[], cmd_outputs=[], arch=[], required={})[source]¶
Bases:
objectA class to implement collection predicates.
A predicate gates the collection of data by an sos plugin. For any add_cmd_output(), add_copy_spec() or add_journal() call, the passed predicate will be evaulated and collection will proceed if the result is True, and not otherwise.
Predicates may be used to control conditional data collection without the need for explicit conditional blocks in plugins.
- Parameters:
owner (
Plugin) – ThePluginobject creating the predicatedry_run (
bool) – Is sos running in dry_run mode?kmods (
list, orstrof single name) – Kernel module name(s) to check presence ofservices (
list, orstrof single name) – Service name(s) to check if runningpackages (
list, orstrof single name) – Package name(s) to check presence ofcmd_outputs (
listofdict``s, or single ``dicttaking form {‘cmd’: <command to run>, ‘output’: <string that output should contain>}) – Command to run, with output string to checkarch (
list, orstrof single architecture) – Architecture(s) that the local system is matched againstrequired (
dict, with keys matching parameter names and values being either ‘any’, ‘all’, or ‘none. Default ‘any’.) – For each parameter provided, should the checks require all items, no items, or any items provided
- arch = []¶
Allowed architecture(s) of the system
- cmd_outputs = []¶
- dry_run = False¶
Skip all collection?
- kmods = []¶
Kernel module enablement list
- packages = []¶
Package presence list
- report_failure()[source]¶
Used by Plugin() to obtain the error string based on if the reason was a failed check or a forbidden check
- services = []¶
Services enablement list
- class sos.report.plugins.SuSEPlugin[source]¶
Bases:
PluginDistroTagTagging class for SuSE Linux distributions
- class sos.report.plugins.UbuntuPlugin[source]¶
Bases:
PluginDistroTagTagging class for Ubuntu Linux