diff --git a/docs/shared_parsers_catalog/pcp_openmetrics_log.rst b/docs/shared_parsers_catalog/pcp_openmetrics_log.rst new file mode 100644 index 0000000000..c3c1453a4a --- /dev/null +++ b/docs/shared_parsers_catalog/pcp_openmetrics_log.rst @@ -0,0 +1,3 @@ +.. automodule:: insights.parsers.pcp_openmetrics_log + :members: + :show-inheritance: diff --git a/insights/parsers/pcp_openmetrics_log.py b/insights/parsers/pcp_openmetrics_log.py new file mode 100644 index 0000000000..97e049fa40 --- /dev/null +++ b/insights/parsers/pcp_openmetrics_log.py @@ -0,0 +1,32 @@ +""" +PcpOpenmetricsLog - file ``/var/log/pcp/pmcd/openmetrics.log`` +-------------------------------------------------------------- +""" +from insights.specs import Specs +from insights import LogFileOutput, parser + + +@parser(Specs.pcp_openmetrics_log) +class PcpOpenmetricsLog(LogFileOutput): + """ + Parse the ``/var/log/pcp/pmcd/openmetrics.log`` log file. + + .. note:: + Please refer to its super-class :class:`insights.core.LogFileOutput` + + Sample input:: + + [Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 55% {: + [Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }: + [Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 95% {: + [Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }: + [Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store };: + + Examples: + + >>> "Error: cannot parse/store" in log + True + >>> len(log.get('pmdaopenmetrics')) == 5 + True + """ + pass diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index a5ee81748d..9bffd1b6e3 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -514,6 +514,7 @@ class Specs(SpecSet): password_auth = RegistryPoint() pci_rport_target_disk_paths = RegistryPoint() pcp_metrics = RegistryPoint() + pcp_openmetrics_log = RegistryPoint(filterable=True) pcs_config = RegistryPoint() pcs_quorum_status = RegistryPoint() pcs_status = RegistryPoint() diff --git a/insights/specs/default.py b/insights/specs/default.py index 4d2b69d881..a0f6dd4bcf 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -454,6 +454,7 @@ class DefaultSpecs(Specs): password_auth = simple_file("/etc/pam.d/password-auth") pci_rport_target_disk_paths = simple_command("/usr/bin/find /sys/devices/ -maxdepth 10 -mindepth 9 -name stat -type f") pcp_metrics = simple_command("/usr/bin/curl -s http://127.0.0.1:44322/metrics --connect-timeout 5", deps=[pcp_enabled]) + pcp_openmetrics_log = simple_file("/var/log/pcp/pmcd/openmetrics.log") pcs_quorum_status = simple_command("/usr/sbin/pcs quorum status") pcs_status = simple_command("/usr/sbin/pcs status") php_ini = first_file(["/etc/opt/rh/php73/php.ini", "/etc/opt/rh/php72/php.ini", "/etc/php.ini"]) diff --git a/insights/tests/parsers/test_pcp_openmetrics_log.py b/insights/tests/parsers/test_pcp_openmetrics_log.py new file mode 100644 index 0000000000..decb4232e9 --- /dev/null +++ b/insights/tests/parsers/test_pcp_openmetrics_log.py @@ -0,0 +1,26 @@ +import doctest +from insights.parsers import pcp_openmetrics_log +from insights.tests import context_wrap + + +PCP_OPENMETRICS_LOG = """ +[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 55% {: +[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }: +[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 95% {: +[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }: +[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store };: +""".strip() + + +def test_pcp_openmetrics_log(): + log = pcp_openmetrics_log.PcpOpenmetricsLog(context_wrap(PCP_OPENMETRICS_LOG)) + assert "Error: cannot parse/store" in log + assert len(log.get('pmdaopenmetrics')) == 5 + + +def test_documentation(): + failed_count, tests = doctest.testmod( + pcp_openmetrics_log, + globs={'log': pcp_openmetrics_log.PcpOpenmetricsLog(context_wrap(PCP_OPENMETRICS_LOG))} + ) + assert failed_count == 0