NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/lib/python3.6/site-packages/sos/collector/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/lib/python3.6/site-packages/sos/collector/__pycache__/sosnode.cpython-36.pyc
3

��Zh��@s�ddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZddlmZdd	lmZdd
lmZmZmZmZddlmZeeeeed�ZGd
d�d�ZdS)�N)�quote)�load)�
InitSystem)�JujuSSH)�SSHControlPersist)�LocalTransport)�OCTransport)�SaltStackMaster)�CommandTimeoutException�ConnectionException�UnsupportedHostException�InvalidTransportException)�sos_parse_version)�localZcontrol_persistZocZ	saltstackZjujuc@s�eZdZdhdd�Zedd��Zdd�Zd	d
�Zdd�Zed
d��Z	dd�Z
dd�Zdd�Zdd�Z
didd�Zedd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zdjd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zdkd:d;�Zd<d=�Zd>d?�Z d@dA�Z!dBdC�Z"dDdE�Z#dFdG�Z$dHdI�Z%dJdK�Z&dLdM�Z'dNdO�Z(dPdQ�Z)dRdS�Z*dTdU�Z+dVdW�Z,dXdY�Z-dZd[�Z.d\d]�Z/d^d_�Z0d`da�Z1dbdc�Z2ddde�Z3dfdg�Z4dS)l�SosNodeNTcCs�|j�|_||_|d|_|j�|d|_|d|_|d|_|d|_|jj	|_	|jj
|_
d|_d|_d|_
d|_i|_i|_|p�|jj|_|jjr�|jjr�|j|j_|r�||j_d|_d|_d|_g|_dgggg|dd�|_d	|_tjd
�|_tjd�|_|j|�|_ |j j!�r,|j j!dk|_y|j j"|j�Wn6t#k
�rt}z|j$d
|����WYdd}~XnX|j%�|_|j j|_|j�r�|jj&�r�d}|j'�r�|�r�|j�s�|j j(�dS|j�r�|j)��r�d|j_*|jj*�r�|j+�|j,�dS)NZcmdlineopts�tmpdir�hostlen�	need_sudo�sos_optionsF�sos_cmd)�version�enabled�disabled�options�presetsr�	sosreportZsosZsos_ui�rootzUnable to open remote session: )-�strip�address�commons�opts�_assign_config_optsrrrr�node_config_file�inherit_config_filer�host�cluster�hostname�sos_env_vars�	_env_vars�password�	_passwordZ
nopasswd_sudoZsudo_pw�sos_path�	retrievedZhash_retrieved�	file_list�sos_info�sos_bin�loggingZ	getLogger�soslog�ui_log�_load_remote_transport�
_transportZdefault_userZconnect�	Exception�	log_error�determine_host_policyZno_local�	connected�
disconnect�check_in_container�
containerized�create_sos_container�_load_sos_info)�selfrrr)Z
local_sudoZ
load_facts�err�r@�/usr/lib/python3.6/sosnode.py�__init__,sr














zSosNode.__init__cCs|jr|jjSdS)NT)r4r8)r>r@r@rAr8qszSosNode.connectedcCs|jj�dS)zDWrapper to close the remote session via our transport agent
        N)r4r9)r>r@r@rAr9xszSosNode.disconnectcCst|jdkrd|_t|j|�S|jjtkr<t|jj|j|�S|jjdkrh|jd|jj���t|jj��t|j|�S)z�Determine the type of remote transport to load for this node, then
        return an instantiated instance of that transport
        �	localhost�	127.0.0.1T�autoz4Connection failed: unknown or unsupported transport )rCrD)	rrrr �	transport�
TRANSPORTSr6r
r)r>rr@r@rAr3}s
zSosNode._load_remote_transportcCs|jd|jd���d|��S)N�<�z : )�	_hostnamer)r>�msgr@r@rA�_fmt_msg�szSosNode._fmt_msgcCsp|jsj|jrtjj�|_nP|jd�}|ddkrjx8|djd�D]&}|sJq@|jd�}|d|j|d<q@W|jS)Nz
env --null�statusr�output��=rI)r(r�os�environ�copy�run_command�split)r>�ret�ln�_valr@r@rA�env_vars�s

zSosNode.env_varscCs`||_|jjd|j�|jjd|jj�|jjd|jd�|jjdd�|jjd|jj�dS)	z>Set the manifest section that this node will write to
        r&�policyZsos_versionr�final_sos_command�rFN)�manifest�	add_fieldrJr$�os_release_namer.r4�name)r>r]r@r@rA�set_node_manifest�szSosNode.set_node_manifestcCs<tjjd�r|jd�dStjjd�dk	r8|jd�dSdS)zV
        Tries to identify if we are currently running in a container or not.
        z/run/.containerenvz/Found /run/.containerenv. Running in container.TZ	containerNz/Found env var 'container'. Running in containerF)rQ�path�exists�	log_debugrR�get)r>r@r@rAr:�s

zSosNode.check_in_containercCs�|jjr�|jj|jj|j�|jjd�}|j|dd�}|ddkr�|ddkr�d|dkrf|jd	�t	�d
|dkr�|jd�t	�|j|jj
�dd�}|ddkr�|jd|jj�d
��dS|jd|d���t	�|jd|d���t	�dS)zJIf the host is containerized, create the container we'll be using
        )�imageZauthZ
force_pullT)�	need_rootrMr�}zunable to retrieve auth tokenrNzHCould not pull image. Provide either a username and password or authfilezunknown: Not foundz%Specified image not found on registryzTemporary container z createdz(Could not start container after create: z$Could not create container on host: F)rrh)
r$r;r<r rf�get_container_authZforce_pull_imagerTr6r5Zrestart_sos_container�log_infoZsos_container_name)r>�cmd�resrVr@r@rAr<�s2
zSosNode.create_sos_containercCsB|jjr$|jjdj|jj|jj�S|jjdj|jjp>|jj�S)zrDetermine what the auth string should be to pull the image used to
        deploy our temporary container
        �default)	r Z
registry_userr$ZruntimesZfmt_registry_credentialsZregistry_passwordZfmt_registry_authfileZregistry_authfileZcontainer_authfile)r>r@r@rAri�s
zSosNode.get_container_authFcCs:y |jd|��|d�}|ddkStk
r4dSXdS)z3Checks for the presence of fname on the remote nodezstat )rgrMrFN)rTr5)r>Zfnamergrlr@r@rA�file_exists�s
zSosNode.file_existscCs|jrd|jkr|jS|jS)NrC)r&r)r>r@r@rArJ�szSosNode._hostnamecCsd}tj|d|�S)zUAttempts to obfuscate sensitive information in log messages such as
        passwordsz>(?P<var>(pass|key|secret|PASS|KEY|SECRET).*?=)(?P<value>.*?\s)z\g<var>****** )�re�sub)r>rKZregr@r@rA�_sanitize_log_msg�szSosNode._sanitize_log_msgcCs|jj|j|��dS)z:Format a ui message that includes host name and formattingN)r2�inforL)r>rKr@r@rA�ui_msg�szSosNode.ui_msgcCs8tj�dd}d|j�d|�d|��}|jj|�dS)z#Used to print and log info messagesrI��[�:z] N)�inspect�stackrJr1rr)r>rK�caller�lmsgr@r@rArjszSosNode.log_infocCs8tj�dd}d|j�d|�d|��}|jj|�dS)z$Used to print and log error messagesrIrtrurvz] N)rwrxrJr1�error)r>rKryrzr@r@rAr6	szSosNode.log_errorcCsB|j|�}tj�dd}d|j�d|�d|��}|jj|�dS)z$Used to print and log debug messagesrIrtrurvz] N)rqrwrxrJr1�debug)r>rKryr@r@rArds
zSosNode.log_debugcCsR|jjdtjjd��dk}|jr(|r(|S|jjr>dt|���S|jrNd|��S|S)z�If we need to provide a sudo or root password to a command, then
        here we prefix the command with the correct bits
        ZUSERrzsu -c zsudo -S )	r(rerQrRrr �become_rootrr)r>rkZis_rootr@r@rA�_format_cmds

zSosNode._format_cmdc	Cs�d}d}|jjdkrN|jjj|jj�}|dk	r�dj|d�}|dr�|d}n8|j|jjddd�}|ddkr�|d	j�jd
�\}}}|r�t	|jd��dkr�|d7}y|d
|jd�d��7}Wn2t
k
r�}z|jd
|���WYdd}~XnX||jd<|jd�r"|j
d|jd���n$|j|jjk�s<|jd�d|_dS|jd��rXd|_|j�d�}|j|ddd�}|ddk�r�|j|d	�|jd��r�|j�dS)zLQueries the node for information about the installed version of sos
        N�.r�releaseT)�
use_containerrgrMrrN�-�z.0z#Unable to fully parse sos release: zsos version is z!sos is not installed on this nodeFz4.0z
sos reportz -lz3.6)r$Zcontainer_version_command�package_managerZpkg_versionZsos_pkg_name�joinrTrrU�lenr5rdr.rjrr Zprimaryr6r8�check_sos_versionr/�_load_sos_plugins�_load_sos_presets)	r>�verZrel�pkgZpkgs�_r?rk�sosinfor@r@rAr=#sF


"

zSosNode._load_sos_infocCsr|j�d�}|j|ddd�}|ddkrnxD|dj�D]4}|j�jd�r6|jd�dj�}|jd	j|�q6WdS)
Nz --list-presetsT)r�rgrMrrNzname:rIr)r/rT�
splitlinesr�
startswithrUr.�append)r>rkrl�lineZpnamer@r@rAr�WszSosNode._load_sos_presetscCs�d}d}d}d}d}|d|}|d|}|d|}	|dd}
|j||�|jd<|j||�|jd	<|j|	|�|jd
<|j|
|d�|jd<dS)
Nz,The following plugins are currently enabled:z-The following plugins are currently disabled:z4The following options are available for ALL plugins:z+The following plugin options are available:z	Profiles:z(.*?)z

rrrTZprofiles)�_regex_sos_helpr.)r>r�ZENABLEDZDISABLEDZALL_OPTIONSZOPTIONSZPROFILESZ	enableregZdisregZoptregZproregr@r@rAr�`szSosNode._load_sos_pluginsc
Cs�g}x�tj||tj�D]�}x�|j�D]z}|s�y|j�}|rH|j|d�Wq�tk
r|}z|jd|���WYdd}~Xq�Xq$|jd�}	|jdd�|	D��q$WqW|S)NrzError parsing sos help: �,css|]}|j�r|j�VqdS)N)r)�.0�pr@r@rA�	<genexpr>~sz*SosNode._regex_sos_help.<locals>.<genexpr>)	ro�findall�Sr�rUr�r5rd�extend)
r>Zregexr�Zis_listrl�resultr�Zlsr?�rr@r@rAr�qs$
zSosNode._regex_sos_helpcCsXy|jd|���|jj|�Stk
rR}z|jd|�d|���dSd}~XnXdS)z1Reads the specified file and returns the contentsz
Reading file zException while reading z: r\N)rjr4�	read_filer5r6)r>Zto_readr?r@r@rAr��szSosNode.read_filecCsz|jr(|jd|jdj���|jdSti|jjt�d|jj	|j
d�d�}|rh|jd|j�d��|S|jd�t�d	S)
z[Attempts to identify the host installation against supported
        distributions
        zusing local policy rZTz/etc/os-release)�cache�sysrootZinitZ
probe_runtimeZremote_execZremote_checkzloaded policy z	 for hostz4Unable to determine host installation. Ignoring nodeN)
rrjrr_rr r�rr4rTr�r6r)r>r$r@r@rAr7�s

zSosNode.determine_host_policycCsPy|jd}t|�t|�kStk
rJ}z|jd|���dSd}~XnXdS)a�Checks to see if the sos installation on the node is AT LEAST the
        given ver. This means that if the installed version is greater than
        ver, this will still return True

        :param ver: Version number we are trying to verify is installed
        :type ver:  ``str``

        :returns:   True if installed version is at least ``ver``, else False
        :rtype:     ``bool``
        rzError checking sos version: FN)r.rr5r6)r>r�Z	_node_verr?r@r@rAr��s
zSosNode.check_sos_versioncCs|js
dS|jjj|�dk	S)z2Checks if a given package is installed on the nodeFN)r$r�Zpkg_by_name)r>r�r@r@rA�is_installed�szSosNode.is_installed�rEc
Cs�|jrt|jrt|jd�y$|jj|j�}|s<|jd�t�Wn4tk
rr}z|jd|����WYdd}~XnX|r�|jj	r�|jj
|�}|r�|j|�}|r�|j}	|	j
|�}|jj|||||�S)a�Runs a given cmd, either via the SSH session or locally

        :param cmd:     The full command to be run
        :type cmd:      ``str``

        :param timeout: Time in seconds to wait for `cmd` to complete
        :type timeout:  ``int``

        :param use_shell: If a shell is needed to run `cmd`, set to True
        :type use_shell:  ``bool`` or ``auto`` for transport-determined

        :param use_container: Run this command in a container *IF* the host
                              is a containerized host
        :type use_container: ``bool``

        :param env: Pass environment variables to set for this `cmd`
        :type env:  ``dict``
        z-Node is disconnected, attempting to reconnectzFailed to reconnect to nodez!Error while trying to reconnect: N)r8rrdr4Z	reconnectr*rr5r$r;Zformat_container_commandr~rY�updaterT)
r>rk�timeout�	use_shellrgr��envZreconnectedr?Z_cmd_envr@r@rArT�s&



zSosNode.run_commandcCsvy6|j�}|r|j|�n
|jd�|jr4|j�|_Wn2tk
rh}z|jd|���WYdd}~XnX|j�dS)z.Run an sos report on the node, then collect itz'Unable to determine path of sos archivezError during sos execution: N)�execute_sos_command�finalize_sos_pathr6r+�retrieve_sosreportr,r5�cleanup)r>rbr?r@r@rAr�s
"zSosNode.sosreportcCs||jdkS)z/Verifies if the given preset exists on the noder)r.)r>�presetr@r@rA�_preset_exists�szSosNode._preset_existscs&t�fdd�|jd|jdgD��S)z/Verifies if the given plugin exists on the nodec3s|]}�|kVqdS)Nr@)r��s)�pluginr@rAr��sz)SosNode._plugin_exists.<locals>.<genexpr>rr)�anyr.)r>r�r@)r�rA�_plugin_exists�szSosNode._plugin_existscCs||jdkS)z6Checks to see if the plugin is default enabled on noder)r.)r>r�r@r@rA�_check_enabled�szSosNode._check_enabledcCs||jdkS)z7Checks to see if the plugin is default disabled on noder)r.)r>r�r@r@rA�_check_disabled�szSosNode._check_disabledcCsR|jd�d}|j|�sdS|j|�r6||jjkr6dS|j|�rN||jdkSdS)z�Attempts to verify that the given option is available on the node.
        Note that we only get available options for enabled plugins, so if a
        plugin has been force-enabled we cannot validate if the plugin option
        is correct or notrrFrT)rUr�r�r �enable_pluginsr�r.)r>�opt�plugr@r@rA�_plugin_option_exists�s


zSosNode._plugin_option_existscsdj�fdd�|D��S)z^Returns a comma delimited list for sos plugins that are confirmed
        to exist on the noder�c3s|]}�j|�r|VqdS)N)r�)r��o)r>r@rAr�sz,SosNode._fmt_sos_opt_list.<locals>.<genexpr>)r�)r>r r@)r>rA�_fmt_sos_opt_listszSosNode._fmt_sos_opt_listcCs
||_dS)zVExpose the node to the cluster profile determined for the
        environment
        N)r%)r>r%r@r@rA�set_clusterszSosNode.set_clusterc	s>|jjr0|js|jj|_n|jd|jj�d��|jjr`x&|jjD]}||jkrB|jj|�qBW|jjr�x,|jjD] ��|jkrr|jj�|j�<qrW|jjr�xJ|jjD]>�t	�fdd�|j
D��s���d|jj���}|j
j|�q�W|jj|��r|jj�|jj
|�WdQRXn |jj�|jj|�WdQRXdS)a+This is used to modify the sos report command run on the nodes.
        By default, sos report is run without any options, using this will
        allow the profile to specify what plugins to run or not and what
        options to use.

        This will NOT override user supplied options.
        zCluster specified preset z> but user has also defined a preset. Using user specification.c3s|]}�|kVqdS)Nr@)r�r�)r�r@rAr�3sz2SosNode.update_cmd_from_cluster.<locals>.<genexpr>rPN)r%Z
sos_presetr�rjZsos_pluginsr�r�rZsos_plugin_optionsr��plugoptsZcheck_node_is_primary�lockZset_primary_optionsZset_node_options)r>r�Zoptionr@)r�rA�update_cmd_from_clusters,



zSosNode.update_cmd_from_clustercCsJt|jj�|_t|jj�|_t|jj�|_t|jj�|_t|jj�|_dS)z�From the global opts configuration, assign those values locally
        to this node so that they may be acted on individually.
        N)�listr �only_plugins�skip_pluginsr�r�r�)r>r@r@rAr!?s
zSosNode._assign_config_optscs��jd}�j�}|r*|�dt|��d�}g}�jd�r`�jjdkr`|jdtt�jj������jd�r��jjr�|jdtt�jj������jd�r܈jj	r�|jd	��jj
r�|jd
��jjr�|jdt�jj�����jd��r8�jj�r|jd
tdj
�jj������jj�r8|jdtdj
�jj������jd��rj�jj�rj|jdtt�jj������jd��s��jd��rˆjjdk�r�|jd�jj����jj�r�|jd�jj����jd��r�jj�r�|jd�jj����jj�r|jd��j�|jdtjj
�jj�j��}x:�jD]0}�j|}|jd|�d|�rP|nd����q,W�j�r��fdd��jD�}|�r�|jdtdj
d d!�|D�������j�r�j�j��r�|jd"t�j����n�jd#�j�d$���j �r��fd%d��j D�}t!|�t!�j �k�r@t"t#�j �t#|��}�jd&|�d'���j$�j �}	|	�rf|jd(t|	����|�ddj
|����_%�j&d)�j%����j'j(d*�j%�d+S�j)�r�fd,d��j)D�}
t!|
�t!�j)�k�r�t"t#�j)�t#|
��}�jd-|�d.���j$|
�}|�r|jd/t|�����j*�r��fd0d��j*D�}t!|�t!�j*�k�rvt"t#�j*�t#|��}
�jd1|
�d2���j$|�}|�r�|jd3t|����|�ddj
|����_%�j&d)�j%����j'j(d*�j%�d+S)4zZUse host facts and compare to the cluster type to modify the sos
        command if neededr� z3.6�z
--threads=z3.7z--plugin-timeout=z3.8z--allow-system-changesz
--no-env-varsz--since=z4.1z--skip-commands=r�z
--skip-files=z4.2z--cmd-timeout=z4.3z4.2-13rEz--container-runtime=z
--namespaces=z4.5.2z--journal-size=z--low-priorityrz--r\cs8g|]0}�j|jd�d�r�j|jd�d�r|�qS)rrrP)r�rUr�)r�r�)r>r@rA�
<listcomp>�sz,SosNode.finalize_sos_cmd.<locals>.<listcomp>z-k css|]
}|VqdS)Nr@)r�r�r@r@rAr��sz+SosNode.finalize_sos_cmd.<locals>.<genexpr>z	--preset=zRequested to enable preset z" but preset does not exist on nodecsg|]}�j|�r|�qSr@)r�)r�r�)r>r@rAr��szRequested plugins z. were requested to be enabled but do not existz--only-plugins=zFinal sos command set to r[Ncsg|]}�j|�r|�qSr@)r�)r�r�)r>r@rAr��szRequested to skip plugins z%, but plugins are already not enabledz--skip-plugins=cs.g|]&}|�jkr�j|�r�j|�r|�qSr@)r�r�r�)r�r�)r>r@rAr��s
zRequested to enable plugins z1, but plugins are already enabled or do not existz--enable-plugins=)+r.�determine_sos_labelrr�r Zthreadsr��strZplugin_timeoutZallow_system_changesZno_env_varsZsinceZ
skip_commandsr�Z
skip_filesZcmd_timeoutZcontainer_runtimeZ
namespacesZjournal_sizeZlow_priorityr��replacerQrbr$Zsos_bin_pathr/rr�r�r�rdr�r�r��setr�rrjr]r^r�r�)r>r�labelZsos_optsr�rXr ZplugsZnot_onlyZonly�skipZnot_skipZskiplnZnot_on�enabler@)r>rA�finalize_sos_cmdJs�













&$

zSosNode.finalize_sos_cmdcCs�d}||jj|�7}|jjr<||s,|jj�nd|jj��7}|sDdS|jd|���|jd�rdd}nd}|jjd�d	�d|��}|�d
|��S)z?Determine what, if any, label should be added to the sos reportr\r�NzLabel for sos report set to z3.6z--labelz--namerrrP)r%Zget_node_labelr r�rdr�rrU)r>r�Zlcmdr@r@rAr��s
zSosNode.determine_sos_labelcCs^|jj}|r|j|d�}|j�d}|jd|���||_|jd�d|_|jjd|j�dS)	z\Use host facts to determine if we need to change the sos path
        we are retrieving fromr\rzFinal sos path: �/rIZcollected_archiveN���)	r$Zsos_path_stripr�rUrjr+�archiver]r^)r>rbZpstripr@r@rAr��szSosNode.finalize_sos_pathcCsT|d
krdS|dkr d|kr dS|dkr,dSt|�dkrJ|jd�dd�Sd	|��S)NrIz+sos report process received SIGKILL on nodeZsudozsudo attempt failed�z4sos report terminated unexpectedly. Check disk spacer�
zsos exited with code r�)r�rU)r>Zrc�stdoutr@r@rA�determine_sos_error�szSosNode.determine_sos_errorcCs:|jd��y�d}d}d}|jjr2d|jj��}nR|jjr�|jsvd|jjd�d"�d�}|jj|jj	|�d|��}nd|jj	��}|r�|j
�d	|��|_
|j|j
|jjd
d
d
|j
d�}|dd
k�r�xZ|dj�D]J}tj|d�r�|j�}|jd#��r|jd�d}q�|jd�r�|j�d}q�W|�r�|jjd|�t|�dk�rT|jjdd�n,t|�dk�rr|jjdd�n|jjdd�n|jjdd�n:|j|d|d�}|jd|d�d|d���t|��|Stk
�r�|jd��YnFtk
�r4}z(|jd|���|jd |����WYd!d!}~XnXd!S)$z2Run sos report and capture the resulting file pathzGenerating sos report...Fr\z--config-file=z/tmp/r�rIz.confr�T)r�r�rgr�r�rMrrNz*sosreport-*tar*� sha256	� md5	�	zThe checksum is: rt�checksum� Z
checksum_typeZmd5�@Zsha256�unknownzError running sos report. rc = z msg = zTimeout exceededz'Exception during sos report execution: zError running sos report: Nr�)r�r�)rsr r"r#rrrUr4Zcopy_file_to_remoteZconfig_filerrTr�r'r��fnmatchrr�r]r^r�r�rdr5r
r6rj)r>rbr�Zconfig_file_argZ
remote_configrlr�r?r@r@rAr��sd



zSosNode.execute_sos_commandcCs�|jd}tjj||jd�d�}yD|j|�rR|jd|�d|���|jj||�S|j	d|�d��dSt
k
r�}z|j	d|�d	|���dSd
}~XnXd
S)z7Copies the specified file from the host to our temp dirr�rIzCopying remote z
 to local zAttempting to copy remote file z%, but it does not exist on filesystemFzFailed to retrieve z: Nr�)rrQrbr�rUrnrjr4�
retrieve_filerdr5)r>rbZdestdir�destr?r@r@rAr�6s

zSosNode.retrieve_filecCs�dj|j��}y|t|jd��dkr8|jd|�d��dS|j|�rv|jd|���d|��}|j|d	d
�}|ddkS|jd
|�d��dStk
r�}z|jd|�d|���dSd}~XnXdS)z|Removes the spciefied file from the host. This should only be used
        after we have retrieved the file already
        r\r�r�zRefusing to remove path z0: appears to be incorrect and possibly dangerousFzRemoving file zrm -f T)rgrMrz!Attempting to remove remote file z%, but it does not exist on filesystemzFailed to remove z: N)r�rUr�rdrnrjrTr5)r>rbrkrl�er@r@rA�remove_fileEs

zSosNode.remove_filecCs�|js|jjr>y|j|j�Wntk
r<|jd�dSX|jd|j���|j	d�y|j
|j�}Wn*tk
r�}z|j|�dSd}~XnX|r�|j	d�|jj|jj
d�d�d	S|j	d
�dS)z,Collect the sos report archive from the nodezFailed to make archive readableFzRetrieving sos report from zRetrieving sos report...Nz!Successfully collected sos reportr�rITzFailed to retrieve sos reportr�)rr r}�make_archive_readabler+r5r6rjrrsr�r-r�rU)r>rVr?r@r@rAr�[s&




zSosNode.retrieve_sosreportcCsT|jdks|jrdSd|jkr6|jd|j�d��dS|j|j�}|sP|jd�dS)zvRemove the sos report archive from the node, since we have
        collected it and it would be wasted space otherwiseNrzNode sos report path z/ looks incorrect. Not attempting to remove pathzFailed to remove sos report)r+rrdr�r6)r>Zremovedr@r@rA�remove_sos_archiveqs
zSosNode.remove_sos_archivecCsN|j�|jr.xdD]}|j|j|�rPqW|jj�}|rJ|j|dd�dS)z<Remove the sos archive from the node once we have it locally�.sha256�.md5T)rgN)r�r�)r�r+r�r$Zset_cleanup_cmdrT)r>Zextr�r@r@rAr��s

zSosNode.cleanupcCs�x�|D]�}y�|js|jjrty|j|�WnJtk
rr}z.|jd|���|jd|�d|���wWYdd}~XnX|j|�}|r�|jj	|j
d�d�|j|�n|jd|���Wqtk
r�}zd|��}|j|�WYdd}~XqXqWdS)	z4Collect the file created by a cluster outside of soszUnable to retrieve file zFailed to make file z readable: Nr�rIz/Error collecting additional data from primary: r�)rr r}r�r5r6rdr�r-r�rUr�)r>�	filenames�filenamer?rVr�rKr@r@rA�collect_extra_cmd�s"


zSosNode.collect_extra_cmdcCsLd|��}|j|ddd�}|ddkr*dSd}|j|||df�t�dS)	z�Used to make the given archive world-readable, which is slightly
        better than changing the ownership outright.

        This is only used when we're not connecting as root.
        z
chmod o+r �
T)r�rgrMrz6Exception while making %s readable. Return code was %sN)rTr6r5)r>�filepathrkrlrKr@r@rAr��s
zSosNode.make_archive_readable)NNT)F)F)r�rEFFN)5�__name__�
__module__�__qualname__rB�propertyr8r9r3rLrYrar:r<rirnrJrqrsrjr6rdr~r=r�r�r�r�r7r�r�rTrr�r�r�r�r�r�r�r�r!r�r�r�r�r�r�r�r�r�r�r�r�r@r@r@rAr*sh
D
(

4	
	
'(<r)r�rwr0rQroZshlexrZsos.policiesrZsos.policies.init_systemsrZsos.collector.transports.jujurZ(sos.collector.transports.control_persistrZsos.collector.transports.localrZsos.collector.transports.ocrZ"sos.collector.transports.saltstackr	Zsos.collector.exceptionsr
rrr
Z
sos.utilitiesrrGrr@r@r@rA�<module>
s(

NineSec Team - 2022