diff --git a/docs/custom_datasources_index.rst b/docs/custom_datasources_index.rst index 8a18afb8cf..9ecda5ba6c 100644 --- a/docs/custom_datasources_index.rst +++ b/docs/custom_datasources_index.rst @@ -167,7 +167,7 @@ insights.specs.datasources.ps ----------------------------- .. automodule:: insights.specs.datasources.ps - :members: ps_eo_cmd, LocalSpecs + :members: jboss_runtime_versions, ps_eo_cmd, LocalSpecs :show-inheritance: :undoc-members: diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index a0cf3bb7d2..89277d3a46 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -279,6 +279,7 @@ class Specs(SpecSet): iscsiadm_m_session = RegistryPoint() jbcs_httpd24_httpd_error_log = RegistryPoint(filterable=True) jboss_domain_server_log = RegistryPoint(multi_output=True, filterable=True) + jboss_runtime_versions = RegistryPoint() jboss_standalone_main_config = RegistryPoint(multi_output=True) jboss_standalone_server_log = RegistryPoint(multi_output=True, filterable=True) jboss_version = RegistryPoint(multi_output=True) diff --git a/insights/specs/datasources/ps.py b/insights/specs/datasources/ps.py index 8daba2a126..30670024be 100644 --- a/insights/specs/datasources/ps.py +++ b/insights/specs/datasources/ps.py @@ -1,6 +1,9 @@ """ Custom datasources for ps information """ +import json +import os.path + from insights.core.context import HostContext from insights.core.dr import SkipComponent from insights.core.plugins import datasource @@ -11,7 +14,7 @@ class LocalSpecs(Specs): """ Local specs used only by ps datasources """ - ps_eo_args = simple_command("/bin/ps -eo pid,args") + ps_eo_args = simple_command("/bin/ps -ewwo pid,args") """ Returns ps output including pid and full args """ @@ -19,10 +22,10 @@ class LocalSpecs(Specs): def ps_eo_cmd(broker): """ Custom datasource to collect the full paths to all running commands on the system - provided by the ``ps -eo pid,args`` command. After collecting the data, all of the + provided by the ``ps -ewwo pid,args`` command. After collecting the data, all of the args are trimmed to leave only the command including full path. - Sample output from the ``ps -eo pid, args`` command:: + Sample output from the ``ps -ewwo pid, args`` command:: PID COMMAND 1 /usr/lib/systemd/systemd --switched-root --system --deserialize 31 @@ -76,3 +79,53 @@ def ps_eo_cmd(broker): return DatasourceProvider('\n'.join(data), relative_path='insights_commands/ps_eo_cmd') raise SkipComponent() + + +@datasource(LocalSpecs.ps_eo_args, HostContext) +def jboss_runtime_versions(broker): + """ + Custom datasource to collect the /version.txt. + + Sample output from the ``ps -ewwo pid, args`` command:: + + PID COMMAND + 1 /usr/lib/systemd/systemd --switched-root --system --deserialize 31 + 2 [kthreadd] + 3 [rcu_gp] + 4 [rcu_par_gp] + 6 [kworker/0:0H-events_highpri] + 8686 java -D[Standalone] -server -verbose:gc -Xms64m -Xmx512m -Djboss.home.dir=/opt/jboss-datagrid-7.3.0-server -Djboss.server.base.dir=/opt/jboss-datagrid-7.3.0-server/standalone + + + Get the Jboss home directory and read the version.txt:: + + -Djboss.home.dir=/opt/jboss-datagrid-7.3.0-server + /opt/jboss-datagrid-7.3.0-server/version.txt + + Returns: + str: string of dict {: } + + Raises: + SkipComponent: Raised if no data is available + """ + content = broker[LocalSpecs.ps_eo_args].content + jboss_home_dirs = set() + data = {} + for l in content: + if 'java ' in l: + jboss_home_labels = ['-jboss-home ', '-Djboss.home.dir=', '-Dcatalina.home=', + '-Dinfinispan.server.home.path='] + for jhl in jboss_home_labels: + if jhl in l: + jboss_home_str = l.split(jhl)[1] + if jboss_home_str.startswith('/'): + jboss_home_dirs.add(jboss_home_str.split()[0]) + if jboss_home_dirs: + for one_jboss_home_dir in jboss_home_dirs: + jboss_v_file = os.path.join(one_jboss_home_dir, 'version.txt') + if os.path.exists(jboss_v_file): + with open(jboss_v_file, 'r') as version_file: + data[one_jboss_home_dir] = version_file.read() + if len(data) > 0: + return DatasourceProvider(json.dumps(data), relative_path='insights_commands/jboss_versions') + raise SkipComponent() diff --git a/insights/specs/default.py b/insights/specs/default.py index 4b5fe4bec8..60c01aa8c4 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -285,6 +285,7 @@ class DefaultSpecs(Specs): ironic_inspector_log = first_file(["/var/log/containers/ironic-inspector/ironic-inspector.log", "/var/log/ironic-inspector/ironic-inspector.log"]) iscsiadm_m_session = simple_command("/usr/sbin/iscsiadm -m session") jbcs_httpd24_httpd_error_log = simple_file("/opt/rh/jbcs-httpd24/root/etc/httpd/logs/error_log") + jboss_runtime_versions = ps_datasource.jboss_runtime_versions journal_header = simple_command("/usr/bin/journalctl --no-pager --header") kdump_conf = simple_file("/etc/kdump.conf") kernel_config = glob_file("/boot/config-*") diff --git a/insights/tests/datasources/test_ps.py b/insights/tests/datasources/test_ps.py index c28066beb1..3bf7c17137 100644 --- a/insights/tests/datasources/test_ps.py +++ b/insights/tests/datasources/test_ps.py @@ -1,9 +1,12 @@ +import json +import tempfile import pytest +import shutil from mock.mock import Mock from insights.core.dr import SkipComponent from insights.core.spec_factory import DatasourceProvider -from insights.specs.datasources.ps import ps_eo_cmd, LocalSpecs +from insights.specs.datasources.ps import ps_eo_cmd, LocalSpecs, jboss_runtime_versions PS_DATA = """ PID COMMAND @@ -36,8 +39,19 @@ PS_EMPTY = """ PID COMMAND """ +jboss_home_1 = tempfile.mkdtemp(prefix='insights_test') +jboss_home_2 = tempfile.mkdtemp(prefix='insights_test') +PS_JBOSS_VERSION = """ + PID COMMAND + 1 /usr/lib/systemd/systemd --switched-root --system --deserialize 17 + 2 [kthreadd] + 3 [rcu_gp] + 8686 java -D[Standalone] -server -verbose:gc -Xloggc:/opt/jboss-datagrid-7.3.0-server/standalone/log/gc.log -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=/opt/jboss-datagrid-7.3.0-server/standalone/log/server.log -Dlogging.configuration=file:/opt/jboss-datagrid-7.3.0-server/standalone/configuration/logging.properties -jar /opt/jboss-datagrid-7.3.0-server/jboss-modules.jar -mp /opt/jboss-datagrid-7.3.0-server/modules org.jboss.as.standalone -Djboss.home.dir={0} -Djboss.server.base.dir=/opt/jboss-datagrid-7.3.0-server/standalone + 8880 /usr/lib/jvm/java-1.8.0-oracle/bin/java -D[Process Controller] -server -Xms64m -Xmx512m -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=/home/jboss/jboss-eap-7.1/domain/log/process-controller.log -Dlogging.configuration=file:/home/jboss/jboss-eap-7.1/domain/configuration/logging.properties -jar /home/jboss/jboss-eap-7.1/jboss-modules.jar -mp /home/jboss/jboss-eap-7.1/modules org.jboss.as.process-controller -jboss-home {1} -jvm /usr/lib/jvm/java-1.8.0-oracle/bin/java -mp /home/jboss/jboss-eap-7.1/modules -- -Dorg.jboss.boot.log.file=/home/jboss/jboss-eap-7.1/domain/log/host-controller.log -Dlogging.configuration=file:/home/jboss/jboss-eap-7.1/domain/configuration/logging.properties -server +""".format(jboss_home_1, jboss_home_2) RELATIVE_PATH = 'insights_commands/ps_eo_cmd' +JBOSS_VERSION_PATH = 'insights_commands/jboss_versions' def test_ps_eo_cmd(): @@ -68,3 +82,25 @@ def test_ps_eo_cmd_empty(): with pytest.raises(SkipComponent) as e: ps_eo_cmd(broker) assert e is not None + + +def test_jboss_versions(): + # create version.txt file + with open(jboss_home_1 + '/version.txt', 'w') as j_v: + j_v.write("Red Hat JBoss Enterprise Application Platform - Version 7.4.0.GA") + with open(jboss_home_2 + '/version.txt', 'w') as j_v: + j_v.write("Red Hat Data Grid - Version 8.3.1.GA") + ps_eo_args = Mock() + ps_eo_args.content = PS_JBOSS_VERSION.splitlines() + broker = {LocalSpecs.ps_eo_args: ps_eo_args} + result = jboss_runtime_versions(broker) + assert result is not None + assert isinstance(result, DatasourceProvider) + expected_content = {jboss_home_1: 'Red Hat JBoss Enterprise Application Platform - Version 7.4.0.GA', + jboss_home_2: 'Red Hat Data Grid - Version 8.3.1.GA'} + expected = DatasourceProvider(content=json.dumps(expected_content), relative_path=JBOSS_VERSION_PATH) + result_dict = json.loads(result.content[0]) + assert result_dict == expected_content + assert result.relative_path == expected.relative_path + shutil.rmtree(jboss_home_1) + shutil.rmtree(jboss_home_2)