diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2019-05-02 11:24:18 -0400 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-09-24 16:15:32 +0100 |
commit | 66c8f7e53ecf7f99d301fd8ee68f8e17ba54390f (patch) | |
tree | d31d04fd4bc50966d4226806f08cf50ac7822735 | |
parent | 08e87d1736f7f958b203aa5eeb55ab8a15d912f6 (diff) | |
download | sos-66c8f7e53ecf7f99d301fd8ee68f8e17ba54390f.tar.gz |
[Plugin] Add method to collect service status based on InitSystem
Adds a method to Plugin() to allow plugins to capture service status
information based on a policy-defined InitSystem() to use. This will
allow plugins to not need to account for host installation when trying
to collect service information, such as from 'systemctl status'
commands.
Resolves: #1667
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 5e59aa68..56af847a 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -1186,6 +1186,28 @@ class Plugin(object): """ self.custom_text += text + def add_service_status(self, services, timeout=None, pred=None): + '''Collect service status information based on the InitSystem used. + + :param services: A string, or list of strings, specifying the services + to collect + :param timeout: Optional timeout in seconds + :param pred: An optional predicate to gate collection + ''' + if isinstance(services, six.string_types): + services = [services] + + query = self.policy.init_system.query_cmd + if not query: + # No policy defined InitSystem, cannot use add_service_status + self._log_debug('Cannot add service output, policy does not define' + ' an InitSystem to use') + return + + for service in services: + self._add_cmd_output(cmd="%s %s" % (query, service), pred=pred, + timeout=timeout) + def add_journal(self, units=None, boot=None, since=None, until=None, lines=None, allfields=False, output=None, timeout=None, identifier=None, catalog=None, sizelimit=None, pred=None): |