File: //proc/self/root/lib/python3/dist-packages/sos/report/__pycache__/__init__.cpython-38.pyc
U
i��d33 � @ s8 d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dlZd dl m
Z
mZmZm
Z
mZmZmZ d dlmZ d dlZd dlmZmZ d dlZd dlmZ d dlmZ d dlmZ d dlZd d lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( d d
l)m*Z* ej+ej,fZ-dd
d�Z.dd� Z/dddgZ0G dd� 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�, c C s� g }| }|rt | �d }nd}|D ]:}t |�t |� t |� dkrP|�|� |}|| | }q"|t |� d � |kr�|d t |� � }|�|� |S )N� � �H )�len�append)Z
first_line�items�indent�sep�lines�line�newline�item� r( �5/usr/lib/python3/dist-packages/sos/report/__init__.py�_format_list) s
r* c C s t �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; s r. �auto�always�neverc 7 s� e Zd ZdZdZdZdddddddddg g dddg dg dg ddddd dd
g g g ddddddg deeg dddg ddddddddddd�6Z� fdd
�Ze dd� �Z
e dd� �Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd�d$d%�Zd&d'� Zd(d)� Zd*d+� Zd,d-� Zd.d/� Zd0d1� Zd2d3� Zed4d5� �Zd�d6d7�Zd8d9� Z d:d;� Z!d<d=� Z"d>d?� Z#d@dA� Z$dBdC� Z%d�dEdF�Z&dGdH� Z'dIdJ� Z(dKdL� Z)dMdN� Z*dOdP� Z+dQdR� Z,dSdT� Z-dUdV� Z.dWdX� Z/dYdZ� Z0d[d\� Z1d�d]d^�Z2d_d`� Z3dadb� Z4dcdd� Z5dedf� Z6dgdh� Z7didj� Z8dkdl� Z9dmdn� Z:dodp� Z;dqdr� Z<dsdt� Z=dudv� Z>dwdx� Z?dydz� Z@d{d|� ZAd}d~� ZBdd�� 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 archiveTFr r/ �d N� � /etc/sos/cleaner/default_mapping)6�
alloptions�all_logs�build�case_id�chroot�clean�container_runtime�keep_binary_files�desc�domains�disable_parsersZdry_run�
estimate_only�experimental�enable_plugins�journal_size�keywords�keyword_file�plugopts�label�list_plugins�list_presets�
list_profiles�log_sizeZlow_priority�map_file�
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_urlZupload_directoryZupload_userZupload_passZ
upload_methodZupload_no_ssl_verifyZupload_protocol�
add_preset�
del_presetc s� t t| ��|||� g | _g | _g | _t� | _d | _|| _ d| _
d | _i | _| �
� | �� | j�� | _| jj�d�| _| jj| jd kr�| j�| jj�| _| js�tj�d| jj � | j�� | _d| j_| js�| j�� | _| j�| jj� | �| j�| _t | jjd��r*| jjj!dk�r*| �"| jjj!� | �#� d}| jj
| _
| jj
�rPd }n| j�$� �rn| j
t%j&k�rnd
}| j'�(d| j
|f � | jj)t*k�r�| j'�+d| jj) � t,�-� | j.�/� | �0d
� | �1� | �2� | �3� d S )N�/�reportrX zUnknown preset: '%s'
T� verbosityr �default�cmdline�policyzset sysroot to '%s' (%s)zinvalid chroot mode: %s� )4�superr2 �__init__�loaded_plugins�skipped_plugins�all_options�set�env_vars�archiveZ_args�sysrootrX �estimated_plugsizes�print_header�
_set_debugri Zis_rootZ_is_root�manifestZ
components�add_section� report_md�opts�arg_defaults�find_preset�sys�stderr�writeZprobe_presetrJ �mergeZapply_options_from_cmdline�hasattrrf Zset_loggers_verbosity�_set_directoriesZin_container�osr# �soslog�debugr: �chroot_modes�error�logging�shutdown�
tempfile_utilr; �_exit�_check_container_runtime�_get_namespaces�_get_hardware_devices)�self�parser�argsrh �msg�� __class__r( r) rl � sX �
zSoSReport.__init__c
C sR |� dd�}|jddddddd � |jd
ddddd � |jd
ddd tdd� |jdddddd � |jddddd� |jddddddd � |jdddd � |jd!d"tdd#d$d%� |jd&dd'd(� |jd)dd*d(� |jd+dd,dd-d � |jd.d/d0d1td2g d3� |jd4td5d6d7d8� |jd9d:d;d0d<td=g d3� |jd>d?dd@dAd� |jdBdCddDddEd � |jdFddGd(� |jdHddIddJd � |jdKddLtdMdNdO� |jdPdddQdR� |jdSd dTd � |jdUdVd0dWtdXg d3� |jdYddZdd[d � |jd\dd]dd^d � |jd_dd`ddadb� |jdctdd#ddd%� |jdedfd0dgtdhg d3� |jdidtdjddk� |jdld dmd � |jdnd dod � |jdpdqdrd0dstg dtdO� |jdug d0dvdwdx� |jdyg d0dzd{dx� |jd|dd}dd~d � |jddd�dd�d � |jd�ddd�dR� |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�d d�d � |jd�ddd�d�gd�d�� |jd�ddd�d�� |jd�ddd�d�d�gd�d�� |�� }|jd�tdd�d�� |jd�tdd�d�� |� d�d��}|jd�d�d�d�ddd�d�� |jd�d�g d0d�d�� |jd�d0g d�d�d�� |jd�d0g d�d�d�� |jd�d d�d�d�� |jd�ddd�d�d�� |jd�d�d�d�d�� |jd�ddd�d�dx� |jd�d�g d0d�d�� d S )�NzReport Optionsz.These options control how report collects dataz-az--alloptions�
store_truer6 Fz%enable all options for loaded plugins)�action�destrg �helpz
--all-logsr7 z-collect all available logs regardless of sizez--sinceZstorer\ zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])r� r� rg �typer� z--buildr8 z;preserve the temporary directory and do not package resultsz --case-idr9 zspecify case identifier)r� r� r� z-cz--chrootr: r/ zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)rg r� z--descz
--descriptionr zDescription for a new preset)r� r� rg r� 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--experimentalrB zenable experimental pluginsz-ez--enable-plugins�extendrC zenable these plugins)r� r� r� r� rg z--journal-sizer3 rD z+limit the size of collected journals in MiB)r� rg r� r� z-kz--plugin-optionz
--plugoptsrG z7plugin options in plugname.option=value format (see -l)z--labelz--namerH z"specify an additional report labelz-lz--list-pluginsrI z)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrK zBdisplay a list of available profiles and plugins that they includez
--log-sizerL r4 z6limit the size of collected logs (not journals) in MiB)r� r� r� rg r� z--low-priorityz(generate report with low system priority)r� rg r� z--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrP zdisable these pluginsz--no-reportrR z disable plaintext/HTML reportingz
--no-env-varsrS z$Do not collect environment variablesz
--no-postprocrT zDisable all post-processing)rg r� r� r� z--notezBehaviour notes for new presetz-oz--only-pluginsrW zenable these plugins onlyz--presetzA preset identifier)r� r� r� rg z--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-commandsrN zdo not execute these commands)rg r� r� r� z--skip-filesrO zdo not collect these filesz--verifyr] z+perform data verification during collectionz--allow-system-changesr^ zJRun 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-methodZputZpostz HTTP method to use for uploading)rg �choicesr� z--upload-no-ssl-verifyz'Disable SSL verification for upload url)rg r� r� z--upload-protocolZhttpsZftpZsftpz$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--maskr; zObfuscate sensitive information)r� rg r� r� z --domainsr? z$Additional domain names to obfuscatez--disable-parsersr@ zCDisable specific parsers, so that those elements are not obfuscated)r� rg r� r� z
--keywordsrE zList of keywords to obfuscatez--keyword-filerF z&Provide a file a keywords to obfuscate)rg r� r� z--no-updaterU z%Do not update the default cleaner mapz
--map-filerM r5 z;Provide a previously generated mapping file for obfuscation)r� rg r� z--keep-binary-filesr= zGKeep unprocessable binary files in the archive instead of removing themz--usernamesr_ zList of usernames to obfuscate)Zadd_argument_group�add_argumentr. �str�intZadd_mutually_exclusive_group)�clsr� Z
report_grpZ
preset_grpZcleaner_grpr( r( r) �add_parser_options� s� �
� � � �
�
��
��� �
�
�
�
�
�� �
���
� � � ��
�
���
�
�
� � �
�������
�
�
��
�
� �
�� ���
�zSoSReport.add_parser_optionsc C s� |� d� |�d� |�d� |�d� |jdd�}|�d� |�d� |jd d�}|�d
td�td�f � |�d
td� � dddd�}d}|D ]}|jd�||| �dd� q�|�|� d S )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.aE Plugins 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.$pluginZpoliciesr z {:<36}{}F)r&