diff options
-rw-r--r-- | sos/plugins/__init__.py | 4 | ||||
-rw-r--r-- | sos/policies/__init__.py | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 541e8822..cc284d06 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -517,6 +517,10 @@ class Plugin(object): """Return the reported status for service $name""" return self.policy.init_system.get_service_status(name)['status'] + def get_service_names(self, regex): + """Get all service names matching regex""" + return self.policy.init_system.get_service_names(regex) + def set_predicate(self, pred): """Set or clear the default predicate for this plugin. """ diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index f1a88b90..c12fc8c3 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -129,6 +129,13 @@ class InitSystem(object): """ return output + def get_service_names(self, regex): + """Get a list of all services discovered on the system that match the + given regex. + """ + reg = re.compile(regex, re.I) + return [s for s in self.services.keys() if reg.match(s)] + def get_service_status(self, name): """Returns the status for the given service name along with the output of the query command @@ -168,7 +175,7 @@ class SystemdInit(InitSystem): return 'unknown' def load_all_services(self): - svcs = shell_out(self.list_cmd).splitlines() + svcs = shell_out(self.list_cmd).splitlines()[1:] for line in svcs: try: name = line.split('.service')[0] |