HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/sos/report/__pycache__/__init__.cpython-310.pyc
o

i��d33�@s6ddlZddlZddlZddlZddlZddlmZddlZddlZddl	m
Z
mZmZm
Z
mZmZmZddlmZddlZddlmZmZddlZddlmZddlmZddlmZddlZdd	lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(dd
l)m*Z*ej+ej,fZ-dd
d�Z.dd�Z/gd�Z0Gdd�de�Z1dS)�N)�datetime)�ImporterHelper�SoSTimeoutError�bold�sos_get_command_output�TIMEOUT_DEFAULT�listdir�
is_executable)�rmtree)�ThreadPoolExecutor�TimeoutError)�_sos)�__version__)�SoSComponent)
�Report�Section�Command�
CopiedFile�CreatedFile�Alert�Note�PlainTextReport�
JSONReport�
HTMLReport)�
SoSCleanerF�, cCs�g}|}|r
t|�d}nd}|D]}t|�t|�t|�dkr(|�|�|}|||}q|t|�d�|krC|dt|��}|�|�|S)N� ��H)�len�append)�
first_line�items�indent�sep�lines�line�newline�item�r)�5/usr/lib/python3/dist-packages/sos/report/__init__.py�_format_list)s

r+cCst�d�|�d�S)z� This function will format --since arg to append 0s if enduser
    didn't. It's used in the _get_parser.
    This will also be a good place to add human readable and relative
    date parsing (like '2 days ago') in the future z{:<014s}z%Y%m%d%H%M%S)r�strptime�format)�dater)r)r*�
_format_since;sr/)�auto�always�nevercsneZdZdZdZdZidd�dd�dd�dd	�d
d�dd�d
d�dd�dd	�dg�dg�dd�dd�dd�dg�dd�dg�idd�dg�dd	�dd�dd�dd�d d!�d"d�d#d$�d%g�d&g�d'g�d(d�d)d�d*d�d+d�d,d��id-d	�d.g�d/d�d0e�d1e�d2g�d3d�d4d�d5d�d6g�d7d�d8d�d9d�d:d�d;d�d<d�d=d��dd	d	d>��Z�fd?d@�Ze	dAdB��Z
e	dCdD��ZdEdF�ZdGdH�Z
dIdJ�ZdKdL�ZdMdN�ZdOdP�ZdQdR�ZdSdT�ZdUdV�Zd�dWdX�ZdYdZ�Zd[d\�Zd]d^�Zd_d`�Zdadb�Zdcdd�Zdedf�Zedgdh��Zd�didj�Zdkdl�Z dmdn�Z!dodp�Z"dqdr�Z#dsdt�Z$dudv�Z%d�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��Z0d�d��Z1d�d�d��Z2d�d��Z3d�d��Z4d�d��Z5d�d��Z6d�d��Z7d�d��Z8d�d��Z9d�d��Z:d�d��Z;d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZG�ZHS)��	SoSReportzaRun a set of commands and file collections and save them to a report for
    future analysis
    z.Collect files and command output in an archiveT�
alloptionsF�all_logs�build�case_idr�chrootr0�clean�container_runtime�keep_binary_files�desc�domains�disable_parsers�dry_run�
estimate_only�experimental�enable_plugins�journal_size�d�keywords�keyword_fileN�plugopts�label�list_plugins�list_presets�
list_profiles�log_size��low_priority�map_file� /etc/sos/cleaner/default_mapping�
skip_commands�
skip_files�skip_plugins�
namespaces�	no_report�no_env_vars�no_postproc�	no_update�note�only_plugins�preset�plugin_timeout�cmd_timeout�profiles�since�verify�allow_system_changes�	usernames�upload�
upload_url�upload_directory�upload_user�upload_pass�
upload_method�upload_no_ssl_verify)�upload_protocol�
add_preset�
del_presetcs�tt|��|||�g|_g|_g|_t�|_d|_||_	d|_
d|_i|_|�
�|��|j��|_|jj�d�|_|jj|jdkre|j�|jj�|_|jsetj�d|jj�|j��|_d|j_|jsn|j��|_|j�|jj�|�|j�|_t |jjd�r�|jjj!dkr�|�"|jjj!�|�#�d}|jj
|_
|jj
r�d	}n
|j�$�r�|j
t%j&kr�d
}|j'�(d|j
|f�|jj)t*vr�|j'�+d|jj)�t,�-�|j.�/�|�0d
�|�1�|�2�|�3�dS)N�/�reportr[zUnknown preset: '%s'
T�	verbosityr�default�cmdline�policyzset sysroot to '%s' (%s)zinvalid chroot mode: %s�)4�superr3�__init__�loaded_plugins�skipped_plugins�all_options�set�env_vars�archive�_args�sysrootr[�estimated_plugsizes�print_header�
_set_debugrr�is_root�_is_root�manifest�
components�add_section�	report_md�opts�arg_defaults�find_preset�sys�stderr�write�probe_presetrJ�merge�apply_options_from_cmdline�hasattrro�set_loggers_verbosity�_set_directories�in_container�osr$�soslog�debugr8�chroot_modes�error�logging�shutdown�
tempfile_utilr9�_exit�_check_container_runtime�_get_namespaces�_get_hardware_devices)�self�parser�argsrq�msg��	__class__r)r*ru�sV


zSoSReport.__init__c
CsL|�dd�}|jddddddd	�|jd
ddddd	�|jd
dddtdd�|jdddddd	�|jddddd�|jddddddd	�|jdddd �|jd!d"tdd#d$d%�|jd&dd'd(�|jd)dd*d(�|jd+dd,dd-d	�|jd.d/d0d1td2gd3�|jd4td5d6d7d8�|jd9d:d;d0d<td=gd3�|jd>d?dd@dAd�|jdBdCddDddEd	�|jdFddGd(�|jdHddIddJd	�|jdKddLtdMdNdO�|jdPdddQdR�|jdSddTd �|jdUdVd0dWtdXgd3�|jdYddZdd[d	�|jd\dd]dd^d	�|jd_dd`ddadb�|jdctdd#ddd%�|jdedfd0dgtdhgd3�|jdidtdjddk�|jdlddmd �|jdnddod �|jdpdqdrd0dstgdtdO�|jdugd0dvdwdx�|jdygd0dzd{dx�|jd|dd}dd~d	�|jddd�dd�d	�|jd�ddd�dR�|jd�dd�d �|jd�dd�d �|jd�dd�d �|jd�dd�d �|jd�dgd��d�d��|jd�ddd�d��|jd�dgd��d�d��|��}|jd�tdd�d��|jd�tdd�d��|�d�d��}|jd�d�d�d�ddd�d��|jd�d�gd0d�d��|jd�d0gd�d�d��|jd�d0gd�d�d��|jd�dd�d�d��|jd�ddd�d�d��|jd�d�d�d�d��|jd�ddd�d�dx�|jd�d�gd0d�d��dS)�NzReport Optionsz.These options control how report collects dataz-az--alloptions�
store_truer4Fz%enable all options for loaded plugins)�action�destrp�helpz
--all-logsr5z-collect all available logs regardless of sizez--since�storer_zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])r�r�rp�typer�z--buildr6z;preserve the temporary directory and do not package resultsz	--case-idr7zspecify case identifier)r�r�r�z-cz--chrootr8r0zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)rpr�z--descz
--descriptionrzDescription for a new preset)r�r�rpr�z	--dry-runz#Run plugins but do not collect data)r�r�z--estimate-onlyzzApproximate disk space requirements for a real sos run; disables --clean and --collect, sets --threads=1 and --no-postprocz--experimentalrAzenable experimental pluginsz-ez--enable-plugins�extendrBzenable these plugins)r�r�r�r�rpz--journal-sizerDrCz+limit the size of collected journals in MiB)r�rpr�r�z-kz--plugin-optionz
--plugoptsrGz7plugin options in plugname.option=value format (see -l)z--labelz--namerHz"specify an additional report labelz-lz--list-pluginsrIz)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrKzBdisplay a list of available profiles and plugins that they includez
--log-sizerLrMz6limit the size of collected logs (not journals) in MiB)r�r�r�rpr�z--low-priorityz(generate report with low system priority)r�rpr�z--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrSzdisable these pluginsz--no-reportrUz disable plaintext/HTML reportingz
--no-env-varsrVz$Do not collect environment variablesz
--no-postprocrWzDisable all post-processing)rpr�r�r�z--notezBehaviour notes for new presetz-oz--only-pluginsrZzenable these plugins onlyz--presetzA preset identifier)r�r�r�rpz--plugin-timeoutzset a timeout for all pluginsz
--cmd-timeoutz%set a command timeout for all pluginsz-pz	--profilez
--profilesr^z)enable plugins used by the given profilesz--skip-commandsrQzdo not execute these commands)rpr�r�r�z--skip-filesrRzdo not collect these filesz--verifyr`z+perform data verification during collectionz--allow-system-changesrazJRun commands even if they can change the system (e.g. load kernel modules)z--uploadz+Upload archive to a policy-default locationz--upload-urlz&Upload the archive to specified serverz--upload-directoryz$Specify upload directory for archivez
--upload-userz'Username to authenticate to server withz
--upload-passz'Password to authenticate to server withz--upload-method)r0�put�postz HTTP method to use for uploading)rp�choicesr�z--upload-no-ssl-verifyz'Disable SSL verification for upload url)rpr�r�z--upload-protocol)r0�https�ftp�sftpz$Manually specify the upload protocol�--add-presetz#Add a new named command line preset)r�r�r�z--del-presetz$Delete the named command line presetzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz	--cleanerz--maskr9zObfuscate sensitive information)r�rpr�r�z	--domainsr=z$Additional domain names to obfuscatez--disable-parsersr>zCDisable specific parsers, so that those elements are not obfuscated)r�rpr�r�z
--keywordsrEzList of keywords to obfuscatez--keyword-filerFz&Provide a file a keywords to obfuscate)rpr�r�z--no-updaterXz%Do not update the default cleaner mapz
--map-filerOrPz;Provide a previously generated mapping file for obfuscation)r�rpr�z--keep-binary-filesr;zGKeep unprocessable binary files in the archive instead of removing themz--usernamesrbzList of usernames to obfuscate)�add_argument_group�add_argumentr/�str�int�add_mutually_exclusive_group)�clsr��
report_grp�
preset_grp�cleaner_grpr)r)r*�add_parser_options�s��
����
�
��
����
�
�
�
�
���
���
�����
�
���
�
�
���
��������
�
��
�
��
�����

�zSoSReport.add_parser_optionscCs�|�d�|�d�|�d�|�d�|jdd�}|�d�|�d�|jd	d�}|�d
td�td�f�|�d
td��dddd�}d}|D]}|jd�|||�dd�qJ|�|�dS)NzSoS Report Detailed Helpz�The report command is the most common use case for SoS, and aims to collect relevant diagnostic and troubleshooting data to assist with issue analysis without actively performing that analysis on the system while it is in use.z�Additionally, sos report archives can be used for ongoing inspection for pre-emptive issue monitoring, such as that done by the Insights project.z�The typical result of an execution of 'sos report' is a tarball that contains troubleshooting command output, copies of config files, and copies of relevant sections of the host filesystem. Root privileges are required for collections.zHow Collections Are Determined)�titlez�SoS report performs it's collections by way of 'plugins' that individually specify what files to copy and what commands to run. Plugins typically map to specific components or software packages.aEPlugins may specify different collections on different distributions, and some plugins may only be for specific distributions. Distributions are represented within SoS by 'policies' and may influence how other SoS commands or options function. For examplepolicies can alter where the --upload option defaults to or functions.zSee Alsoz>For information on available options for report, see %s and %szsos report --helpzman sos-reportz.The following %s sections may be of interest:
zsos helpz'Information on the plugin design of sosz!Information on a specific $pluginz+How sos operates on different distributions)zreport.pluginszreport.plugins.$plugin�policiesrz		{:<36}{}F)r')�	set_title�add_textr�rr-)r��section�psec�ssec�
help_lines�helpln�lnr)r)r*�display_help�sH
�����	�����zSoSReport.display_helpcCstdtdtf��dS)Nz
%s
zsosreport (version %s))�print�_r�r�r)r)r*r�szSoSReport.print_headercCs(|��|��d�|��|��d�|_dS)N)�block�fibre)�storage�network�namespaced_network)�_get_block_devs�_get_fibre_devs�_get_network_devs�_get_network_namespace_devices�devicesr�r)r)r*r��s��zSoSReport._get_hardware_devicescCs�|jjdkrc|jj��}|dvri|j_|j�d�dS|jjs,d|}|j�|�dS||jj��vrJd�	dd�|jj��D��}t
d||f��|jj||jjd	<|j�d
|jjd	j�dSdS)a[Check the loaded container runtimes, and the policy default runtime
        (if set), against any requested --container-runtime value. This can be
        useful for systems that have multiple runtimes, such as RHCOS, but do
        not have a clearly defined 'default' (or one that is determined based
        entirely on configuration).
        r0)�none�off�diabledz0Disabled all container runtimes per user option.zZWARNING: No container runtimes are active, ignoring option to set default runtime to '%s'
rcss�|]	}|dkr|VqdS)rpNr)��.0�pr)r)r*�	<genexpr>�s���z5SoSReport._check_container_runtime.<locals>.<genexpr>zSCannot use container runtime '%s': no such runtime detected. Available runtimes: %srpz%Set default container runtime to '%s'N)r�r:�lowerrr�runtimesr��info�warning�keys�join�	Exception�name)r��crunr��validr)r)r*r��s0������z"SoSReport._check_container_runtimec
Cszz g}gd�}|D]}tj�d|�r|�t�d|��q	|WSty<}z|j�d|�gWYd}~Sd}~ww)z�Enumerate a list of fibrechannel devices on this system so that
        plugins can iterate over them

        These devices are used by add_device_cmd() in the Plugin class.
        )�fc_host�fc_transport�fc_remote_ports�	fc_vportsz
/sys/class/%sz/sys/class/%s/*z#Could not get fibre device list: %sN)r��path�isdirr��globr�r�r�)r��devs�devdirs�devdir�errr)r)r*r��s���zSoSReport._get_fibre_devsc
s�zDdd�t�d�D�}td�}g�|ddkr/|d��D]}|��d�dd	�}��|�q�fd
d�|D�}tt|�t|��}|WSt	y`}z|j
�d|�gWYd}~Sd}~ww)
z�Enumerate a list of block devices on this system so that plugins
        can iterate over them

        These devices are used by add_device_cmd() in the Plugin class.
        cSsg|]}d|�qS)z/dev/%sr))r��dr)r)r*�
<listcomp>sz-SoSReport._get_block_devs.<locals>.<listcomp>z
/sys/blockzlosetup --all --noheadings�statusr�output�:rcs"g|]
}|�d�r|�vr|�qS)�loop��
startswith�r��dev��real_loop_devicesr)r*r�s��z#Could not get block device list: %sN)r�rr�
splitlines�split�replacer �listryr�r�r�)r��device_list�loop_devices�loop_dev�loop_device�ghost_loop_devs�dev_listr�r)r�r*r��s ��zSoSReport._get_block_devscCsd|��i|_dS)Nr�)�_get_network_namespacesrTr�r)r)r*r�s
�zSoSReport._get_namespacesc
Cs�ggggd�}z,td|jjd�r|�|���|ds1|j�d�|�|���|��|d<W|SW|St	yO}z|j�
d|���WYd}~|Sd}~ww)	aHelper to encapsulate network devices probed by sos. Rather than
        probing lists of distinct device types like we do for storage, we can
        do some introspection of device enumeration where a single interface
        may have multiple device types. E.G an 'ethernet' device could also be
        a bond, and that is pertinent information for device iteration.

        :returns:   A collection of enumerated devices sorted by device type
        :rtype:     ``dict`` with keys being device types
        )�ethernet�bridge�team�bond�nmcli)r}r	zZNetwork devices not enumerated by nmcli. Will attempt to manually compile list of devices.r
z%Could not enumerate network devices: N)r	r�r}�update�_get_nmcli_devsr�r��
_get_eth_devs�_get_bridge_devsr�r�)r��_devsr�r)r)r*r�s,���	���zSoSReport._get_network_devscCs*i}|jdD]}d|�|�i||<q|S)zqEnumerate the network devices that exist within each network
        namespace that exists on the system
        r�r	)rTr)r��_nmdevs�nmspr)r)r*r�5s


�z(SoSReport._get_network_namespace_devicesc
Cs�i}zBtd�}|ddkr8|d��dd�D] }|��\}}||vr)|g||<n||�|�|d�|�qtt|d��|d<W|Sty_}z|j�d|�WYd}~|Sd}~ww)	z�Use nmcli, if available, to enumerate network devices. From this
        output, manually grok together lists of devices.
        znmcli --fields DEVICE,TYPE devr�rr�rsNr	z!Could not parse nmcli devices: %s)	rr�r�r rryr�r�r�)r�r�_ndevsr��dname�dtyper�r)r)r*r@s"���zSoSReport._get_nmcli_devsc
s�dg�g}|s�fdd�td|jj�D�}n?z"d|}t|�}|ddkr7|d��D]}|�vr6|�|�q+WntyT}z|j�d	||f�WYd
}~nd
}~ww|dd�|D�dd�|D�d
�S)a8Enumerate a list of ethernet network devices so that plugins can
        reliably iterate over the same set of devices without doing piecemeal
        discovery.

        These devices are used by `add_device_cmd()` when `devices` includes
        "ethernet" or "network".

        :param namespace:   Inspect this existing network namespace, if
                            provided
        :type namespace:    ``str``

        :returns:   All valid ethernet devices found, potentially within a
                    given namespace
        :rtype:     ``list``
        �bonding_masterscsg|]}|�vr|�qSr)r)r���	filt_devsr)r*r�gs
�z+SoSReport._get_eth_devs.<locals>.<listcomp>z/sys/class/netz"ip netns exec %s ls /sys/class/netr�rr�z6Could not determine network namespace '%s' devices: %sNcS�g|]	}|�d�r|�qS)rr�)r��bdr)r)r*r�z�cSr)�tunr�)r��tdr)r)r*r�{r)r	rr)	rr�r}rr�r r�r�r�)r��	namespace�	_eth_devs�_nscmd�_nsout�_nsethr�r)rr*rTs4
�
������zSoSReport._get_eth_devscCs�g}ztddd�}Wnty$}z|j�d|�WYd}~nd}~ww|ddkr_|d��d	d�D])}z|�|��d�Wq5ty^}z|j�d
||f�WYd}~q5d}~ww|S)z�Enumerate a list of bridge devices so that plugins can reliably
        iterate over the same set of bridges.

        These devices are used by `add_device_cmd()` when `devices` includes
        "bridge" or "network".
        z
brctl show���timeoutz&Unable to enumerate bridge devices: %sNr�rr�rsz)Could not parse device from line '%s': %s)rr�r�r�r�r r�r�)r��_bridges�_boutr��_bliner)r)r*r~s(������zSoSReport._get_bridge_devscCs\g}td�}|ddkr,|d��D]}|��s |dd���r!q|�|�d�d�q|S)z�Enumerate a list of network namespaces on this system so that
        plugins can iterate over them

        Note that stderr is not collected, so no handling of error lines.
        zip netnsr�rr�Nrsr)rr��isspacer �	partition)r��out_ns�ip_netnsr&r)r)r*r�sz!SoSReport._get_network_namespacescCs4|j|j|j|j|j|j|j|jj|j|j	|j
d�S)N)�cmddir�logdir�rptdir�tmpdirr�rrr}ro�cmdlineoptsr�rT)r/r0r1r2r�rrr}r�ror�rTr�r)r)r*�get_commons�s�zSoSReport.get_commonscCs
|j��S�N)r��newr�r)r)r*�
get_temp_file��
zSoSReport.get_temp_filecCs4|j�|jd�|j�|jd�|j�|jd�dS)Ni�)r{�makedirsr/r0r1r�r)r)r*�_make_archive_paths�szSoSReport._make_archive_pathscCsd|_d|_d|_dS)N�sos_commands�sos_logs�sos_reports)r/r0r1r�r)r)r*r��s
zSoSReport._set_directoriescCs$|jjr
|jt_d|_dSd|_dS)NTF)r�r��
_exceptionr��
excepthook�
raise_pluginsr�r)r)r*r��s

zSoSReport._set_debugcCsNttd�s
tj��st�|||�dStj|||dtjd�t�t	�
�dS)z* Wrap exception in debugger if not in tty �ps1�)�limit�fileN)r�r�r��isatty�__excepthook__�	traceback�print_exception�stdoutr��pdb�pm)�etype�eval_�etracer)r)r*r>�s�zSoSReport._exceptioncCs^|js|jrt��\}}}tj|||tjd�t�t�	|�|r+|r-|�
||�dSdSdS)N)rD)r@�exit_processr��exc_inforGrHrIr�rJ�post_mortem�_log_plugin_exception)r��plugname�funcrL�val�tbr)r)r*�handle_exception�s
�zSoSReport.handle_exceptioncCsXt|dd�r|jj|jtj�dd�d�t|dd�r*|jj|jtj�dd�d�dSdS)N�sos_log_filer<�sos.log�r��sos_ui_log_file�ui.log)�getattrr{�add_filerXr�r�r�r[r�r)r)r*�
_add_sos_logs�s
�

��zSoSReport._add_sos_logscsT�jj}t�jj�sdSt|d�sdS|r��|���sdSt�fdd�|jD��S)NTr^Fcsg|]}|�jjv�qSr))r�r^r�r�r)r*r��sz,SoSReport._is_in_profile.<locals>.<listcomp>)r�rZrr^r��_is_not_specifiedr��any)r��plugin_classrZr)r�r*�_is_in_profile�s
zSoSReport._is_in_profilecCs||jjvSr5)r�rS�r��plugin_namer)r)r*�_is_skipped�szSoSReport._is_skippedcC�*||�����o||jjvo||jjvSr5)r4�
check_enabledr�rBrZ�r�re�pluginClassr)r)r*�_is_inactive��

�
�zSoSReport._is_inactivecCrgr5)r4�default_enabledr�rBrZrir)r)r*�_is_not_defaultrlzSoSReport._is_not_defaultcCs|jjo	||jjvSr5)r�rZrdr)r)r*r`s
�zSoSReport._is_not_specified�unknowncCs"|j�|��||���|f�dSr5)rwr r�r4)r�rb�reasonr)r)r*�_skip
s


�zSoSReport._skipcCs |j�|��||���f�dSr5)rvr r�r4)r�rbr)r)r*�_loads

�zSoSReport._loadcCs�tjjj}ttjj�}|��}g|_t�|_t	|j
j�}|jj}g}|j
j
r.|�tjjj�t||�}|jj}t|j
j�}	|D]�}
tj�|
�\}}z�|||�}
t	|
�sVWq@|j�|
�}|||j
j
d�s~|j�td�|
�|j
jdkr~|�|td��Wq@|j�|�|�|�}|s�|�|td��Wq@|�|�r�|�|td��Wq@|�||�r�|�|td��Wq@|�||�r�|�|td��Wq@t |d	�r�|j�!|j�|o�|}|�"|�r�|r�|�|td
��Wq@|jD]}||	vr�|	�#|�q�|�$|�Wq@t%�y}z|j�td�|
|f�|�&�WYd}~q@d}~wwt	|	�dk�r>|j�'td�d
�(|	��|�)�|�*d�dSdS)N)rAz%plugin %s does not validate, skippingrzdoes not validate�excluded�skipped�inactive�optionalr^z
not specifiedz(plugin %s does not install, skipping: %sz+Unknown or inactive profile(s) provided: %srrs)+�sosrn�plugins�
import_pluginr�get_modules�plugin_namesryr^rr�rr�valid_subclassesrAr �ExperimentalPlugin�tuple�validate_pluginrr�r��splitext�match_pluginr�r�r�rorqrcrfrkrnr�rr`�removerrr�rWr�r�rKr�)r�ry�helperrx�using_profiles�policy_classes�
extra_classes�valid_plugin_classesr�remaining_profiles�plug�plugbase�ext�plugin_classesrb�
in_profile�default_profile�i�er)r)r*�load_pluginss�

�
�





������zSoSReport.load_pluginscCs@|jjr|jD]\}}|j��D]
}t|jvrd|_qqdSdS)NT)r�r4rv�options�values�bool�val_type�value)r�rSr��optr)r)r*�_set_all_optionsfs
���zSoSReport._set_all_optionscCs�|jjr�i}|jjD]o}z	|�d�\}}Wnty d}Ynwt|t�rH|��}|dvr1d}n|dvr8d}nzt|�}Wn	tyGYnwz	|�d�\}}Wn
ty^|}d}Ynwz||Wn
tyri||<Ynw||||<q
|j	D]^\}}||vr�||D]N}||j
vr�|j�d||f�|�
d�z|j
|�|||�|j�d	||j
|f�Wq�ty�}z|j�|�|�
d�WYd}~q�d}~ww||=q}|��D]
}|j�d
|�q�|��r�|j�d�dSdSdS)N�=T)�on�enable�enabled�true�yes)r��disable�disabled�false�noF�.z#no such option "%s" for plugin (%s)rszSet %s plugin option to %szGWARNING: unable to set option for disabled or non-existing plugin (%s).r)r�rGr��
ValueError�
isinstancer�r�r��KeyErrorrvr�r�r�r��	set_valuer�r�r�)r�r�r�rUr�rSr�r)r)r*�
_set_tunablesmsz�
���
�
�������7zSoSReport._set_tunablescCs�ddl}|�|jj|jj�D]}|�d�d}||jvr)|j�d|�|�	d�q|jj
D]}||jvr=|j�d|�q.dS)Nrr�z=a non-existing plugin (%s) was specified in the command line.rsz+Requested to skip non-existing plugin '%s'.)�	itertools�chainr�rZrBr�r{r��fatalr�rSr�)r�r��pluginrer)r)r*�_check_for_unknown_plugins�s$
�
�
�
���z$SoSReport._check_for_unknown_pluginscCs2|jD]\}}|jD]}|j�|j|�q
qdSr5)rvr�rxr )r�rer�r�r)r)r*�_set_plugin_options�s

��zSoSReport._set_plugin_optionscCs�d}g}|jjdkr|d|jjg7}d|j_|jjs$|dg7}d|j_|jjs1|dg7}d|j_|jjr>|dg7}d|j_|jjrK|d	g7}d|j_|rW|d
d�|�7}n|d7}|d
7}|S)Nz
Estimate-only mode enabledrsz--threads=%s overriden to 1z--build enabledTz--no-postproc enabledz--clean disabledFz--upload* options disabledz", which overrides some options:
  z
  r�z

)r��threadsr6rWr9rcr�)r�r��ext_msgr)r)r*�_set_estimate_only�s,



zSoSReport._set_estimate_onlycCs^|j�d�t|j�r|j�dt|j�t|j�f�n|j�dt|j��|j�d�dS)Nrz %d profiles, %d pluginsz %d profiles)�ui_logr�rrvr^r�r)r)r*�_report_profiles_and_plugins�s
�z&SoSReport._report_profiles_and_pluginsc
Cs�|js|js|j�td��dS|jr6|j�td��|j�d�|jD]\}}|j�d||��f�q$n|j�td��|j�d�|jrk|j�td��|j�d�|jD]\}}}|j�d|||��f�qX|j�d�|j�r|j�td��|jd	d
�	�}|D]=}||}|j
}|j
dkr�|dkr�|jjp�t
}n
|d
kr�|jjp�t
}nt
}|jdkr�|jj}|j�d|j||jf�q�|j�d�|j�td��|jD]:}|jdvr�|j
|jkr�q�t|j
t�r�|j
dur�d}	nd}	n|j
}	|	dur�d	}	|j�d|jd|j|	|jf�q�n|j�td��|j�d�t|j�}
|
��td|
dd�}|D]}|j�d|��q3|��dS)Nzno valid plugins foundz,The following plugins are currently enabled:rz	 %-20s %szNo plugin enabled.z-The following plugins are currently disabled:z %-20s %-14s %sz4The following options are available for ALL plugins:rrs���r'�cmd-timeout�postprocz %-25s %-15s %sz+The following plugin options are available:)r'r�r�Tr�r�r�zNo plugin options available.z
Profiles: �r#� %s)rvrwr�r�r�r�r��get_descriptionrx�get_default_plugin_optsr�r�r\rr]r�rWr<rpr�r�r�rr^�sortr+r�)
r�rSr��	plugclassrp�	_defaults�_optr�rU�tmpoptr^r%r&r)r)r*rI�s~

��
�






��
zSoSReport.list_pluginsc	Cs�|js
|j�td��dS|j�td��|j�d�dd�}t|j�}|��|D]0}g}|jD]\}}||�rC||jvrC|�	|�q1t
d||dd�}|D]
}|j�d	|�qOq*|��dS)
Nzno valid profiles foundz%The following profiles are available:rcSs
t|d�S)Nr^)r�)�cr)r)r*�	_has_prof3r8z*SoSReport.list_profiles.<locals>._has_profz%-15s Tr�r�)r^r�r�r�r�r�rr�rvr r+r�)	r�r�r^�profilerxr�r�r%r&r)r)r*rK,s&

��zSoSReport.list_profilescCs�|jjs|j�td��dS|j�td��|j�d�|jj��D]W}|s'q"|j�|�}|j�dd|j	f�|j�dd|j
f�|jrQ|j�dd|jf�|jj
dkrs|j��}d	d
}t||ddd
�}|D]}|j�|�qj|j�d�q"dS)Nzno valid presets foundz$The following presets are available:rz%14s %szname:zdescription:znote:rz%14s zoptions:Tr)r#r$)rr�presetsr�r�r�r�r�r�r�r�r<rYr�ro�to_argsr+)r�r[r��options_strr%r&r)r)r*rJBs*
�zSoSReport.list_presetsc
Cs�|j}|�|�r|j�d|�dS|p|jj}|p|jj}z|j||||jd�WntyE}z|j�d|�WYd}~dSd}~ww|j	�
d�}|j	d|�|j	|dd�}|j�d	|d
�|�f�dS)z�Add a new command line preset for the current options with the
            specified name.

            :param name: the name of the new preset
            :returns: True on success or False otherwise
        z"A preset named '%s' already existsF)r�r<rYr�zCould not add preset: %sNr�rrBz"Added preset '%s' with options %s
rT)
rrr�r�r�r�r<rYrkr�rq�indexr�r�)r�r�r<rYrrr��	arg_indexr�r)r)r*rkZs&
�� �zSoSReport.add_presetc
Cs�|j}|�|�s|j�d|�dSz|j|d�Wnty7}z|j�t|�d�WYd}~dSd}~ww|j�d|�dS)z�Delete a named command line preset.

            :param name: the name of the preset to delete
            :returns: True on success or False otherwise
        zPreset '%s' not foundF�r��
NzDeleted preset '%s'
T)rrr�r�r�rlr�r�r�)r�r�rrr�r)r)r*rlws
��zSoSReport.del_presetc
Cs�|j��}|jjr||��7}|jjr|j�|�dS|td�7}zt	|�WdSt
y=|j�d�|�d�YdSt
yU}z
|�d|�WYd}~dSd}~ww)Nz,Press ENTER to continue, or CTRL-C to quit.
zExiting on user cancel�rs)rr�get_msgr�r@r��batchr�r�r��input�KeyboardInterruptr�r�r�)r�r�r�r)r)r*r��s
��zSoSReport.batchcCsdt��}d}d|}tj�|j|�}|j�d|||f�|j�d|�|jj	d||dd�dS)Nz!caught exception in plugin methodz%s-plugin-errors.txtz%s "%s.%s()"zwriting traceback to %s�%s
�a)�mode)
rG�
format_excr�r�r�r0r�r�r{�
add_string)r�r��method�tracer��plugin_err_log�logpathr)r)r*rR�szSoSReport._log_plugin_exceptionc
Cs�|j��z|j�td��|��|��WdSttfyH}z"|j	t
vr7td�td|j�td�ntd|��WYd}~n,d}~wt
yo}z|j�d�|j�d�t��|j�|�WYd}~nd}~ww|�d�dS)Nz Setting up archive ...rz %s while setting up archivezError setting up archive: %sz) Unexpected exception setting up archive:rs)rr�pre_workr�r�r��
setup_archiver:�OSError�IOError�errno�fatal_fs_errorsr��strerrorr�r�rG�	print_excr��r�r�r)r)r*�prework�s.


����zSoSReport.preworkcCsZ|j�td��|jD]�\}}zM|jj�|�|�t|jj|��t	�
�}|j�d|�|j
|_
|��|��|j�|j�|jjrG|��t	�
�}|j�d|�|j�d||�Wqtyd�ttfy�}z+|jtvr�|j�d�|j�d|j�|j�d�|�d�|�|d�WYd}~qd}~wty�|�|d�YqwdS)	Nz Setting up plugins ...�setup_start�	setup_end�
setup_timerz %s while setting up pluginsrs�setup) r�r�r�rvr�rxr��set_plugin_manifestr]r�nowr��	add_fieldr{�add_default_collectionsr�rzr�	_env_varsr�r`�setup_verifyr�r�r�r�r�r�r�r�rWr�)r�rSr��start�endr�r)r)r*r��sD�
�
���zSoSReport.setupcCs,g}|�dt�|jjd�|�dd�dS)zWFetch version information from all plugins and store in the report
        version filez
sosreport: %sr�zversion.txt)�contentr�N)r rr{r�r�)r��versionsr)r)r*�version�s

�zSoSReport.versioncCs�|j�td��|j�d�d}g|_g|_|jD]}|d7}|j�||df�qz:g}t|jj	��}|�
|jt|j��}Wd�n1sHwY|D]}|s[|j
�d|�qO|j�d�WdStyy|j�d�t�d�YdSw)Nz! Running plugins. Please wait ...rrrsz!Unexpected plugin task result: %sz
Exiting on user cancel
)r�r�r��pluglist�
running_plugsrvr rr�r��map�_collect_pluginrr�r�r�r�r�r�)r��plugruncountr��results�executor�resr)r)r*�collect�s4
�����zSoSReport.collectc	Cs�td���}z>|j|ddd}|�|j|�}|jpd}t��}|j�d|�|j	|d�t��}|j�d|�|j�d||�Wn=t
y�d|d}|j�d	|�|j
�|�|j�|d�|j|ddd��|jd
d�|j��YnwWd�n1s�wY|jjr�|j��}	ztd|	�}
t|
d
��d�|j|d<Wnty�d|j|d<Ynwt�|	�D]}tj �!|	|�}tj �"|�r�tj �#|�s�t$|�q�t�%|�q�d
S)zaWraps the collect_plugin() method so we can apply a timeout
        against the plugin as a wholersrN�
start_timer&�end_time�run_timezPlugin %s timed outz
 %s
T)�waitz
du -sB1 %sr�)&rrv�submit�collect_pluginr'rr�r�r��resultrr�r�r�r�r�r��set_timeout_hitr��_threads�clearr�r@r{�get_tmp_dirrr�r�r~r�r�rr�r�r��islinkr
�unlink)r�r��pool�_plug�tr'r�r�r�r2�du�fr)r)r*r��sJ

���
��
zSoSReport._collect_pluginc	
Cs�z|\}}|j|dd}|j�|�Wn
tyYdSwt|j�}dd||f|dd�dd�|jD��f}|�|�z^|��z|j�	|�Wn	t
yVYnwz|j�	|�Wn	t
yhYnwd	}t|j�t|jj
�kr�|jr�d
ddd�dd�|jD��f}|js�|js�d}|r�|�|�WdSWdSty�YdSttfy�}z)|jtvr�|j�d
|j�|j�d|j�t�d�|�|d�WYd}~dSd}~wty�|�|d�YdSw)NrsFz  Starting %-5s %-15s %sz%d/%dz
[Running: %s]rcs��|]}|VqdSr5r)r�r)r)r*r�;��z+SoSReport.collect_plugin.<locals>.<genexpr>rz  Finishing plugins %-12s %scsrr5r)r�r)r)r*r�Pr
z
  Finished running pluginsz!
 %s while collecting plugin dataz& Data collected still available at %s
r�)rvr�r r�rr��ui_progressr�r�r�r�r�r�r�rr�r�r�r�r�r�r�r2r�r�rW)	r�r��countrSr��numplugs�status_liner�r�r)r)r*r�0sn�

�
�����
��
��zSoSReport.collect_plugincCsR|jjdkr|jjsd|�d�}nd|}|jjs'tj�|�tj��dSdS)Nrz
%s�Zr�)	r�ror��ljust�quietr�rIr��flush)r�rr)r)r*res�zSoSReport.ui_progresscCs@|jsdSd�dd�dd�|jD�D��d}|j�|d�dS)Nr�cSsg|]
\}}d||f�qS)z%s=%sr))r�r�rUr)r)r*r�qs�z.SoSReport.collect_env_vars.<locals>.<listcomp>cSs0g|]}tj�|�dur|dtj�|�f�qS)Nz%s)r��environ�get)r�r�r)r)r*r�ss��environment)rzr�r{r�)r��envr)r)r*�collect_env_varsns
��zSoSReport.collect_env_varsc
Cs�t�}|jD]p\}}t|d�}|jD]	}|�t|��q|jr'|�t|j��|jD]}|�t	|dd|dd��q*|j
D]}|�t|ddtj
�d|��d|d	�d
��q?|jD]\}}}	|�t|tj
�d|�d��q]|�|�qtddftd
dftddff}
|
D]d\}}}
z*|��}||���}|�dd���}|�|�|��|jj|tj
�d|�d�Wq�ttfy�}z'|jt vr�|j!�"d�|j!�"d|j#|
f�|j!�"d�|�$d�WYd}~q�d}~wwdS)Nr��srcpathz..�dstpath)r��href�cmdrr/rD)r��return_coderzsos.txt�textzsos.json�JSONzsos.html�HTMLzutf-8rr=rZrz %s while writing %s reportrs)%rrvr�alerts�addr�custom_textr�copied_filesr�executed_commandsrr�r�r�r4�copy_stringsrrrrr7�unicode�encode�decoder�rr{r^r�r�r�r�r�r�r�r�)r�rnrSr�r��alertrrr��tags�
formatlist�class_�filename�type_�fdr�r�r)r)r*�generate_reportsxsb




�

�
�
��
�
�
���zSoSReport.generate_reportscCs�|jD]_\}}z|�d�r|��n|j�d|�WqttfyT}z+|jtvrD|j	�
d�|j	�
d|j�|j	�
d�|�d�|�
|d�WYd}~qd}~wtyb|�
|d�YqwdS)Nr�zSkipping postproc for plugin %srz% %s while post-processing plugin datars)rv�
get_optionr�r�r�r�r�r�r�r�r�r�r�rWr�)r�rSr�r�r)r)r*r��s,

��
�
���zSoSReport.postproccCsr|sdSz$d}t|d�}t�|�}	|�|�}|sn|�|�q|��W|��Sty8|��Y|��Sw)NFi�rb)	�open�hashlibr6�readr�closer�rW�	hexdigest)r�r{�	hash_name�	hash_size�
archive_fp�digest�hashdatar)r)r*�_create_checksum�s$



�
�
�zSoSReport._create_checksumcCs0t|d|d�}|r|�|d�|��dS)Nr��wr�)r6r�r9)r�r{r;�checksum�fpr)r)r*�_write_checksum�szSoSReport._write_checksumc
sd}d}d}|��d}|jjrPz%|j|j|j|j|jd�}td|d�}|�|j	�
��|��\}}d}WntyO}zt
td|��WYd}~nd}~ww|��|jdura|j	�|jj�|r�tj�|j|j	j�}	|jtj�|	dd�dd�|jtj�|	dd	�d	d�|jtj�|	d
d�dd�|jjr�|��|jj�rdd
lm�ddlm}
|
|j�}tdd�|�d�D��|j d<�t|j �!���}|j"�#d|�t$|j �%�dd�dd�dd�}
d��fdd�|
D��}|j"�#d|�|j"�#d�|j"�#d�|j"�#d�|j"�#d�|jj&�s�t�'d�}|jj�s#t
td ��zgz|�r.|j	�(|�|j	�)|jj�}WnLt*t+f�ym}z't
d�t
td!|j,|j	�
�f��t
d�|j-t.v�rc|�/d"�WYd}~nd}~wt�y�|jj0�rz�YWt�'|�dSwWt�'|�nQt�'|�w|jj1�s�|jj2�r�|j"�3d#�|j	�
�}tj�4|�}|�r�|�5|�}ztj�|j|�}t�6||�|}Wnt*t+f�y�t
td$|��YdSwd}|jj&�s�|�s�t
d%�n�z
|j�7�}|�8||�}Wnt�y	t
td&��YdSwz	|�9|||�Wnt*t+f�y't
td'|��Ynwtj�4|�}|�r:|�5|�:d(d)��}tj�|j|�}t�;|�}|d*|}|d*|}z
t�6||�|}Wnt*t+f�yrt
td+|��YdSwzt�6||�Wnt*t+f�y�t
td,|��Ynw|jj<|||||d-�n
|jj<||||d-�|jj=�s�|jj>�r�|jj&�s�z|j�?|�|j"�#td.��Wn#t�y�}z|j"�@d/|�WYd}~n
d}~wwd0}|j"�@|�tA�B�|jC�r�|jC��|j�rtj�D|j��rtE|j�dS)1NF)rrr2�sys_tmpr�r�T)�in_place�hook_commonsz%ERROR: Unable to obfuscate report: %sr<rY)�
short_namer\r=z
manifest.jsonr��get_human_readable)�PathcSsg|]}|��j�qSr))�lstat�st_size)r�rr)r)r*r�sz(SoSReport.final_work.<locals>.<listcomp>z**/*�sos_logs_reportszPEstimated disk space requirement for whole uncompressed sos report directory: %scSs|dS)Nrsr))�xr)r)r*�<lambda>sz&SoSReport.final_work.<locals>.<lambda>)�key�reverse�z,  c3s(�|]\}}d|�|dd�fVqdS)z%s: %sr)�	precisionNr))r�r��vrIr)r*r�s���z'SoSReport.final_work.<locals>.<genexpr>zFive biggest plugins:  %srz>Please note the estimation is relevant to the current options.z�Be aware that the real disk space requirements might be different. A rule of thumb is to reserve at least double the estimation.�?zCreating compressed archive...z %s while finalizing archive %srszQ
Unable to encrypt when using --build. Encryption is only available for archives.zError moving directory: %sz Creating archive tarball failed.z:Error generating archive checksum after archive creation.
z#Error writing checksum for file: %sz.tarz-obfuscated.tarr�zError moving archive file: %szError moving checksum file: %s)rOzUploaded archive successfullyzUpload attempt failed: %szEUnable to upload archive when using --build as no archive is created.)F�generate_manifest_tag_summaryr�r9rrr2rEr�r�set_target_pathr{�get_archive_path�executer�r�r�r_�add_final_manifest_data�compression_typer�r�r��_name�obfuscate_filer�add_ui_log_to_stdoutr@�
sos.utilitiesrJ�pathlibrK�sumr�r~r�r�r��sortedr"r6�umask�rename_archive_root�finalizer�r�r�r�r�r�r��encrypt_pass�encrypt_keyr��basename�obfuscate_string�rename�get_preferred_hash_namer@rDr�stat�display_resultsrcrd�upload_archiver�r�r�r�r�r
)r�r{�	directoryrO�do_cleanrG�cleaner�_pathsr��_dirrK�tmpdir_path�_sum�
bigplugins�bp_out�	old_umaskr��dir_name�	final_dirrBr;�base_archive�
final_name�archivestat�archive_hash�
final_hashr�r)rIr*�
final_work�sF���
���


��
���


��
�
��

�


��
�
����
��

zSoSReport.final_workcCs|js
|j�td��dSdS)Nzno valid plugins were enabledFT)rvr�r�r�r�r)r)r*�verify_plugins�szSoSReport.verify_pluginscCs|j�d|j�|j�d|jr|jjnd�|j�d|jj�d}td�r?t	dt
�����}|dd	kr?|d
��d	�
d�}|j�d�|jj�d
|�|jj�dt
�d	��|j�d�|j��D]\}}|jj�||�qc|j�d|jj�|j�d|jj�|j�d�dS)zgAdd 'global' data to the manifest, that is any information that is
        not plugin-specific
        r}r[�unsetr^ro�ionicez
ionice -p r�rr�r��priority�io_class�nicenessr��enabled_plugins�disabled_pluginsrxN)r�r�r}r[r��add_listr�r^r	rr��getpidr��stripr�r��nicer�r"rBrS)r��	_io_class�_iorQr�r)r)r*�add_manifest_data�s&�zSoSReport.add_manifest_datacs|d�fdd�	}i�|jjD]!}|jD]}||�q|jD]}||d�q|jD]}||�q'q
|j�dtt������dS)acAdd a section to the manifest that contains a dict summarizing the
        tags that were created and assigned during this report's creation.

        This summary dict can be used for easier inspection of tagged items by
        inspection/analyzer projects such as Red Hat Insights. The format of
        this dict is `{tag_name: [file_list]}`.
        �filepathc	s~|dD]8}||r|s
qz�|}Wntyg}Ynw|�t||t�r,||n||g�ttt|����|<qdS)Nr-)r�r�r�rrcry)�entrQ�tagr���tag_summaryr)r*�compile_tags�s���z=SoSReport.generate_manifest_tag_summary.<locals>.compile_tags�files_copiedr�N)r�)	r�rx�commands�files�collectionsr��dictrcr")r�r�r�r�_file�
collectionr)r�r*rW�s





��z'SoSReport.generate_manifest_tag_summaryc	Cszd}|j�|tdd�|j�f�|jj��}dtd|jjd�|�f}|j�|�|j�dtdd�|j���f�dS)Nz[%s:%s] executing 'sos %s'r�rz'[%s:%s] using '%s' preset defaults (%s)z![%s:%s] effective options now: %s)	r�r��__name__r�rqr[r�r�r�)r�r��preset_argsr)r)r*�_merge_preset_options�s�
�zSoSReport._merge_preset_optionsc
Cs�z�|j�|���|��|��|��|��|��|��|j	j
r+|�
�t�|j	jr5|��t�|j	j
r?|�
�t�|j	jrK|�|j	j�WS|j	jrW|�|j	j�WS|��s^WdS|��|��|��|��|��|j	jsz|��|j	js�|��|j	js�|��n|j�d�|��|��WSt y�|j	j!r��t"�#dd�dks�|�$�Yn;t%y�|j�&d�|�$�|�'d�Yn$ty�}zt"�#dd�dks�|�$�t(�)|j*�WYd}~nd}~ww|�'d�dS)NFz)Skipping postprocessing of collected data�
SOS_TEST_LOGS�keepz
Exiting on user cancelr�rs)+rr�set_commonsr4r�r�r�r�r�r�r�rI�
SystemExitrKrJrkrlr�r�r�r�r�r�rVrrUr3rWr�r�r�r�r�r�r�r��getenv�cleanupr�r�r�r��exit�coder�r)r)r*rZ�sl

���zSoSReport.executer5)NN)ro)rr)Ir��
__module__�__qualname__�__doc__r<�
root_requiredrr�ru�classmethodr�r�rr�r�r�r�r�r�r�rrrrr4r7r:r�r��staticmethodr>rWr_rcrfrkrnr`rqrrr�r�r�r�r�r�r�rIrKrJrkrlr�rRr�r�r�r�r�r�rrr3r�r@rDr�r�r�rWr�rZ�
__classcell__r)r)r�r*r3Gsd��������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�9<
<
7

*



O;
K
	
15	
7O r3)Fr)2r�rGr�r�r�rr��sos.report.pluginsrwr`rrrrrrr	�shutilr
r7�concurrent.futuresrrrJr
r�r�
sos.componentr�sos.policies�sos.report.reportingrrrrrrrrrr�sos.cleanerr�ENOSPC�EROFSr�r+r/r�r3r)r)r)r*�<module>s0
$0