Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.148.217.66
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/sosreport/sos/plugins/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/share/sosreport/sos/plugins/pulp.py
# Copyright (C) 2018 Red Hat, Inc., Jake Hunsaker <jhunsake@redhat.com>

# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos.plugins import Plugin, RedHatPlugin
from pipes import quote
from re import match


class Pulp(Plugin, RedHatPlugin):
    """Pulp platform"""

    plugin_name = "pulp"
    packages = ("pulp-server", "pulp-katello")
    option_list = [
        ('tasks', 'number of tasks to collect from DB queries', 'fast', 200)
    ]

    def setup(self):

        # get mongo DB host and port from line like:
        # seeds: host1:27017,host2:27017
        # take just the very first URI and ignore possible failover
        # if no such config is present, default to localhost:27017
        # further, take optional user credentials - here we assume the
        # credentials dont contain a whitespace character (that would
        # make the parsing more difficult)
        #
        # further, collect location of CA file for contacting qpid in section
        # [messaging]
        # certfile: /etc/pki/katello/qpid_client_striped.crt
        self.dbhost = "localhost"
        self.dbport = "27017"
        self.dbuser = ""
        self.dbpassword = ""
        self.messaging_cert_file = ""
        in_messaging_section = False
        try:
            for line in open("/etc/pulp/server.conf").read().splitlines():
                if match(r"^\s*seeds:\s+\S+:\S+", line):
                    uri = line.split()[1].split(',')[0].split(':')
                    self.dbhost = uri[0]
                    self.dbport = uri[1]
                if match(r"\s*username:\s+\S+", line):
                    self.dbuser = "-u %s" % line.split()[1]
                if match(r"\s*password:\s+\S+", line):
                    self.dbpassword = "-p %s" % line.split()[1]
                if line.startswith("[messaging]"):
                    in_messaging_section = True
                if in_messaging_section and line.startswith("certfile:"):
                    self.messaging_cert_file = line.split()[1]
                    in_messaging_section = False
        except IOError:
            # fallback when the cfg file is not accessible
            pass

        self.add_copy_spec([
            "/etc/pulp/*.conf",
            "/etc/pulp/server/plugins.conf.d/",
            "/etc/default/pulp*",
            "/var/log/httpd/pulp-http.log*",
            "/var/log/httpd/pulp-https.log*",
            "/var/log/httpd/pulp-http_access_ssl.log*",
            "/var/log/httpd/pulp-https_access_ssl.log*",
            "/var/log/httpd/pulp-http_error_ssl.log*",
            "/var/log/httpd/pulp-https_error_ssl.log*"
        ])

        num_tasks = self.get_option('tasks')

        mtasks = self.build_mongo_cmd(
            '\"DBQuery.shellBatchSize=%s;; '
            'db.task_status.find().sort({finish_time: -1})'
            '.pretty().shellPrint()\"' % num_tasks
        )

        mres = self.build_mongo_cmd(
            '\"DBQuery.shellBatchSize=%s;; '
            'db.reserved_resources.find().pretty().shellPrint()\"' % num_tasks
        )

        prun = self.build_mongo_cmd(
            r'"DBQuery.shellBatchSize=%s;; '
            r'db.task_status.find({state:{\$ne: \"finished\"}}).pretty()'
            r'.shellPrint()"' % num_tasks
        )

        # prints mongo collection sizes sorted from biggest and in human
        # readable output
        csizes = self.build_mongo_cmd(
            '\"function humanReadable(bytes) {'
            '  var i = -1;'
            '  var byteUnits = [\'kB\', \'MB\', \'GB\', \'TB\', \'PB\', '
            '                   \'EB\', \'ZB\', \'YB\'];'
            '  do {'
            '      bytes = bytes / 1024;'
            '      i++;'
            '  } while (bytes > 1024);'
            '  return Math.max(bytes, 0.1).toFixed(1) + \' \' + byteUnits[i];'
            '};'
            'var collectionNames = db.getCollectionNames(), stats = [];'
            'collectionNames.forEach(function (n) {'
            '                          stats.push(db[n].stats());'
            '                        });'
            'stats = stats.sort(function(a, b) {'
            '                     return b[\'size\'] - a[\'size\']; });'
            'for (var c in stats) {'
            '  print(stats[c][\'ns\'] + \': \' +'
            '        humanReadable(stats[c][\'size\']) + \' (\' +'
            '        humanReadable(stats[c][\'storageSize\']) + \')\'); }\"'
        )

        dbstats = self.build_mongo_cmd('\"db.stats()\"')

        self.add_cmd_output(mtasks, suggest_filename="mongo-task_status")
        self.add_cmd_output(mres, suggest_filename="mongo-reserved_resources")
        self.add_cmd_output(prun, suggest_filename="pulp-running_tasks")
        self.add_cmd_output(csizes, suggest_filename="mongo-collection_sizes")
        self.add_cmd_output(dbstats, suggest_filename="mongo-db_stats")
        self.add_cmd_output([
            "qpid-stat -%s --ssl-certificate=%s -b amqps://localhost:5671" %
            (opt, self.messaging_cert_file) for opt in "quc"
        ])

    def build_mongo_cmd(self, query):
        _cmd = "bash -c %s"
        _mondb = "--host %s --port %s %s %s" % (self.dbhost, self.dbport,
                                                self.dbuser, self.dbpassword)
        _moncmd = "mongo pulp_database %s --eval %s"
        return _cmd % quote(_moncmd % (_mondb, query))

    def postproc(self):

        # Handle all ".conf" files under /etc/pulp - note that this includes
        # files nested at several distinct directory levels. For this reason we
        # use a regex that matches all these path components with ".*", and
        # ensure that the path ends with ".conf".
        etcreg = r"(([a-z].*(passw|token|cred|secret).*)\:(\s))(.*)"
        repl = r"\1 ********"
        self.do_path_regex_sub(r"/etc/pulp/(.*)\.conf$", etcreg, repl)

        # Now handle JSON-formatted data in the same /etc/pulp directory
        # structure. We use a different substitution string here to preserve
        # the file's JSON syntax.
        jreg = r"(\s*\".*(passw|cred|token|secret).*\"\s*:\s*\")(.*)(\")"
        repl = r"\1********\4"
        self.do_path_regex_sub("/etc/pulp(.*)(.json$)", jreg, repl)

# vim: set et ts=4 sw=4 :

Anon7 - 2022
AnonSec Team