<commit_before># Copyright (C) 2014 Red Hat, Inc., <NAME> <<EMAIL>>
# Copyright (C) 2014 Red Hat, Inc., <NAME> <<EMAIL>>
# Copyright (C) 2010 Red Hat, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import os
import re
import signal


import sos.plugintools


# Class name must be the same as file name and method names must not change
class ovirt(sos.plugintools.PluginBase):
    """oVirt related information"""

    DB_PASS_FILES = re.compile(
        flags=re.VERBOSE,
        pattern=r"""
        ^
        /etc/
        (rhevm|ovirt-engine|ovirt-engine-dwh)/
        (engine.conf|ovirt-engine-dwhd.conf)
        (\.d/.+.conf)?
        $
        """
    )

    DEFAULT_SENSITIVE_KEYS = (
        'ENGINE_DB_PASSWORD:ENGINE_PKI_TRUST_STORE_PASSWORD:'
        'ENGINE_PKI_ENGINE_STORE_PASSWORD:DWH_DB_PASSWORD'
    )

    optionList = [
        (
            'jbosstrace', 'Enable oVirt Engine JBoss stack trace collection',
            '', True
        ),
        (
            'sensitive_keys', 'Sensitive keys to be masked', '',
            DEFAULT_SENSITIVE_KEYS
        )
    ]

    def __init__(self, pluginname, commons):
        sos.plugintools.PluginBase.__init__(self, pluginname, commons)
        self.packages = (
            'ovirt-engine',
            'ovirt-engine-dwh',
            'ovirt-engine-reports'
        )

    def setup(self):
        if self.getOption('jbosstrace'):
            engine_pattern = "^ovirt-engine\ -server.*jboss-modules.jar"
            pgrep = "pgrep -f '%s'" % engine_pattern
            lines = self.callExtProg(pgrep)['output'].splitlines()
            engine_pids = [int(x) for x in lines]
            if not engine_pids:
                self.soslog.error('Unable to get ovirt-engine pid')
                self.add_alert('Unable to get ovirt-engine pid')
            for pid in engine_pids:
                try:
                    # backtrace written to '/var/log/ovirt-engine/console.log
                    os.kill(pid, signal.SIGQUIT)
                except OSError as e:
                    self.soslog.error('Unable to send signal to %d' % pid, e)

        self.addForbiddenPath('/etc/ovirt-engine/.pgpass')
        self.addForbiddenPath('/etc/rhevm/.pgpass')
        # Copy engine config files.
        self.addCopySpecs([<commit_msg>sos2: fix callExtProg usage<commit_after># Copyright (C) 2014 Red Hat, Inc., <NAME> <<EMAIL>>
# Copyright (C) 2014 Red Hat, Inc., <NAME> <<EMAIL>>
# Copyright (C) 2010 Red Hat, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import os
import re
import signal


import sos.plugintools


# Class name must be the same as file name and method names must not change
class ovirt(sos.plugintools.PluginBase):
    """oVirt related information"""

    DB_PASS_FILES = re.compile(
        flags=re.VERBOSE,
        pattern=r"""
        ^
        /etc/
        (rhevm|ovirt-engine|ovirt-engine-dwh)/
        (engine.conf|ovirt-engine-dwhd.conf)
        (\.d/.+.conf)?
        $
        """
    )

    DEFAULT_SENSITIVE_KEYS = (
        'ENGINE_DB_PASSWORD:ENGINE_PKI_TRUST_STORE_PASSWORD:'
        'ENGINE_PKI_ENGINE_STORE_PASSWORD:<PASSWORD>DB_PASSWORD'
    )

    optionList = [
        (
            'jbosstrace', 'Enable oVirt Engine JBoss stack trace collection',
            '', True
        ),
        (
            'sensitive_keys', 'Sensitive keys to be masked', '',
            DEFAULT_SENSITIVE_KEYS
        )
    ]

    def __init__(self, pluginname, commons):
        sos.plugintools.PluginBase.__init__(self, pluginname, commons)
        self.packages = (
            'ovirt-engine',
            'ovirt-engine-dwh',
            'ovirt-engine-reports'
        )

    def setup(self):
        if self.getOption('jbosstrace'):
            engine_pattern = "^ovirt-engine\ -server.*jboss-modules.jar"
            pgrep = "pgrep -f '%s'" % engine_pattern
            lines = self.callExtProg(pgrep)[1].splitlines()
            engine_pids = [int(x) for x in lines]
            if not engine_pids:
                self.soslog.error('Unable to get ovirt-engine pid')
                self.add_alert('Unable to get ovirt-engine pid')
            for pid in engine_pids:
                try:
                    # backtrace written to '/var/log/ovirt-engine/console.log
                    os.kill(pid, signal.SIGQUIT)
                except OSError as e:
                    self.soslog.error('Unable to send signal to %d' % pid, e)

        self.addForbiddenPath('/etc/ovirt-engine/.pgpass')
        self.addForbiddenPath('/etc/rhevm/.pgpass')
        # Copy engine config files.
        self.addCopySpecs([
{'fraction_non_alphanumeric': 0.0988936170212766, 'fraction_numerical': 0.00748936170212766, 'mean_word_length': 2.271714922048998, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2817193', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1733, 'n_words': 530}