Repository: RedHatInsights/insights-core

Issue:
Output of "insights-info" is not so accurate
For example:
~~~
❱ insights-info release
insights.specs.default.DefaultSpecs.subscription_manager_release_show
insights.specs.default.DefaultSpecs.host_installed_rpms
insights.specs.default.DefaultSpecs.installed_rpms
insights.specs.Specs.subscription_manager_release_show
insights.specs.Specs.installed_rpms
insights.parsers.subscription_manager_release.SubscriptionManagerReleaseShow
insights.parsers.installed_rpms.InstalledRpms
insights.combiners.satellite_version.SatelliteVersion
            <-- Missed the "redhat_release"
❱ insights-info ss
insights.specs.default.DefaultSpecs.rabbitmq_queues  <-- Should not be there (ss in "messages")
insights.specs.default.DefaultSpecs.dig_dnssec
insights.specs.default.DefaultSpecs.lssap
insights.specs.default.DefaultSpecs.sshd_config_perms
insights.specs.default.DefaultSpecs.qpid_stat_g <-- Should not be there (ss in "--ssl")
insights.specs.default.DefaultSpecs.ss
insights.specs.default.DefaultSpecs.rpm_V_packages
insights.specs.default.DefaultSpecs.numeric_user_group_name
insights.specs.default.DefaultSpecs.rpm_V_packages                                                                                             
insights.specs.default.DefaultSpecs.numeric_user_group_name
insights.specs.default.DefaultSpecs.certificates_enddate
insights.specs.default.DefaultSpecs.openshift_certificates
insights.specs.default.DefaultSpecs.iscsiadm_m_session
insights.specs.default.DefaultSpecs.qpid_stat_q
insights.specs.default.DefaultSpecs.max_uid
insights.specs.default.DefaultSpecs.lsscsi
insights.specs.default.DefaultSpecs.passenger_status
insights.specs.default.DefaultSpecs.oc_get_egressnetworkpolicy
insights.specs.default.DefaultSpecs.qpid_stat_u
insights.specs.default.DefaultSpecs.dig
insights.specs.Specs.passenger_status
insights.specs.Specs.qpid_stat_g
insights.specs.Specs.certificates_enddate
insights.specs.Specs.lsscsi
insights.specs.Specs.numeric_user_group_name
insights.specs.Specs.oc_get_egressnetworkpolicy
insights.specs.Specs.dig_dnssec
insights.specs.Specs.sshd_config_perms
insights.specs.Specs.ss
insights.specs.Specs.dig
insights.specs.Specs.iscsiadm_m_session
insights.specs.Specs.rabbitmq_queues
insights.specs.Specs.max_uid
insights.specs.Specs.rpm_V_packages
insights.specs.Specs.lssap
insights.parsers.netstat.SsTULPN
insights.parsers.netstat.SsTUPNA
insights.parsers.rabbitmq.RabbitMQQueues
insights.parsers.openshift_get.OcGetEgressNetworkPolicy
insights.parsers.certificates_enddate.CertificatesEnddate
insights.parsers.numeric_user_group_name.NumericUserGroupName
insights.parsers.qpid_stat.QpidStatG
insights.specs.Specs.openshift_certificates
insights.specs.Specs.qpid_stat_q
insights.specs.Specs.qpid_stat_u
insights.parsers.lssap.Lssap
insights.parsers.iscsiadm_mode_session.IscsiAdmModeSession
insights.parsers.passenger_status.PassengerStatus
insights.parsers.lsscsi.LsSCSI
insights.parsers.qpid_stat.QpidStatQ
insights.parsers.qpid_stat.QpidStatU
~~~


Discussion:

Resolving patch:
diff --git a/insights/tools/query.py b/insights/tools/query.py
--- a/insights/tools/query.py
+++ b/insights/tools/query.py
@@ -130,23 +130,28 @@ def get_datasources():
 
 
 def matches(d, path):
+    def _simple_file(src):
+        if src.startswith(('insights_commands', 'sos_commands')):
+            src = src.split('/')[-1].split('_')[0]
+        return src
+
     if isinstance(d, sf.simple_file):
-        return d.path.strip("/").startswith(path.strip("/"))
+        return path.strip("/") in _simple_file(d.path.strip('/').split()[0])
 
     if isinstance(d, sf.glob_file):
-        return any(re.match(glob2re(pat), path) and not d.ignore_func(path) for pat in d.patterns)
+        return any(re.match(path, glob2re(_simple_file(pat))) and not d.ignore_func(path) for pat in d.patterns)
 
     if isinstance(d, sf.simple_command):
-        return path.strip("/") in d.cmd.strip("/")
+        return path.strip("/") in d.cmd.split()[0]
 
     if isinstance(d, sf.first_file):
-        return any(p.strip("/").startswith(path.strip("/")) for p in d.paths)
+        return any(path.strip("/") in _simple_file(p) for p in d.paths)
 
     if isinstance(d, sf.foreach_execute):
-        return path.strip("/") in d.cmd.strip("/")
+        return path.strip("/") in d.cmd.split()[0]
 
     if isinstance(d, sf.foreach_collect):
-        return d.path.strip("/").startswith(path.strip("/")) and not d.ignore_func(path)
+        return path.strip("/") in d.path and not d.ignore_func(path)
 
 
 def get_matching_datasources(paths):


Test patch: