Repository: RedHatInsights/insights-core

Issue:
Handle hammer_ping from sos archive
Sos Archive has output like this : 
+COMMAND> hammer ping
+
+candlepin:
+    Status:          ok
+    Server Response: Duration: 20ms
+    Status:          ok
+    Server Response: Duration: 14ms
+pulp:
+    Status:          ok
+    Server Response: Duration: 101ms
+pulp_auth:
+    Status:          ok
+    Server Response: Duration: 75ms
+foreman_tasks:
+    Status:          ok
+    Server Response: Duration: 3ms
+



Discussion:

Resolving patch:
diff --git a/insights/parsers/hammer_ping.py b/insights/parsers/hammer_ping.py
--- a/insights/parsers/hammer_ping.py
+++ b/insights/parsers/hammer_ping.py
@@ -34,7 +34,8 @@
     >>> hammer.services_of_status('OK')
     ['elasticsearch', 'foreman_tasks']
 """
-from .. import parser, CommandParser
+from insights import parser, CommandParser
+from insights.parsers import get_active_lines
 from insights.specs import Specs
 
 
@@ -74,6 +75,7 @@ def parse_content(self, content):
         self.are_all_ok = False
 
         # The first line should be a service
+        content = get_active_lines(content, comment_char="COMMAND>")
         if len(content[0].split()) > 1:
             self.errors.append(content[0])
         # Each service occupies 3 lines
diff --git a/insights/specs/sos_archive.py b/insights/specs/sos_archive.py
--- a/insights/specs/sos_archive.py
+++ b/insights/specs/sos_archive.py
@@ -51,6 +51,7 @@ class SosSpecs(Specs):
     foreman_proxy_log = first_of([simple_file("/var/log/foreman-proxy/proxy.log"), simple_file("sos_commands/foreman/foreman-debug/var/log/foreman-proxy/proxy.log")])
     foreman_satellite_log = first_of([simple_file("/var/log/foreman-installer/satellite.log"), simple_file("sos_commands/foreman/foreman-debug/var/log/foreman-installer/satellite.log")])
     foreman_ssl_access_ssl_log = first_file(["var/log/httpd/foreman-ssl_access_ssl.log", r"sos_commands/foreman/foreman-debug/var/log/httpd/foreman-ssl_access_ssl.log"])
+    hammer_ping = first_file(["sos_commands/foreman/hammer_ping", "sos_commands/foreman/foreman-debug/hammer-ping"])
     getcert_list = first_file(["sos_commands/ipa/ipa-getcert_list", "sos_commands/ipa/getcert_list"])
     gluster_v_info = simple_file("sos_commands/gluster/gluster_volume_info")
     gluster_v_status = simple_file("sos_commands/gluster/gluster_volume_status")


Test patch:
diff --git a/insights/parsers/tests/test_hammer_ping.py b/insights/parsers/tests/test_hammer_ping.py
--- a/insights/parsers/tests/test_hammer_ping.py
+++ b/insights/parsers/tests/test_hammer_ping.py
@@ -45,6 +45,27 @@
     server Response: Duration: 1ms
 """.strip()
 
+HAMMERPING_COMMAND = """
+COMMAND> hammer ping
+
+candlepin:
+    Status:          ok
+    Server Response: Duration: 20ms
+candlepin_auth:
+    Status:          ok
+    Server Response: Duration: 14ms
+pulp:
+    Status:          ok
+    Server Response: Duration: 101ms
+pulp_auth:
+    Status:          ok
+    Server Response: Duration: 75ms
+foreman_tasks:
+    Status:          ok
+    Server Response: Duration: 3ms
+
+""".strip()
+
 HAMMERPING = """
 candlepin:
     Status:          FAIL
@@ -99,6 +120,20 @@ def test_hammer_ping_ok():
     assert 'nonexistent' not in status.response_of_service
 
 
+def test_hammer_ping_command():
+    status = HammerPing(context_wrap(HAMMERPING_COMMAND))
+
+    assert status.are_all_ok
+    assert status.service_list == [
+        'candlepin', 'candlepin_auth', 'pulp', 'pulp_auth',
+        'foreman_tasks'
+    ]
+    assert status.services_of_status('FAIL') == []
+    assert 'nonexistent' not in status.service_list
+    assert 'nonexistent' not in status.status_of_service
+    assert 'nonexistent' not in status.response_of_service
+
+
 def test_hammer_ping():
     status = HammerPing(context_wrap(HAMMERPING))