aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2019-05-02 11:24:18 -0400
committerBryn M. Reeves <bmr@redhat.com>2019-09-24 16:15:32 +0100
commit66c8f7e53ecf7f99d301fd8ee68f8e17ba54390f (patch)
treed31d04fd4bc50966d4226806f08cf50ac7822735
parent08e87d1736f7f958b203aa5eeb55ab8a15d912f6 (diff)
downloadsos-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__.py22
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):