
    -_g:                    d   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dl	m
Z
 d dl	mZ d dlmZ d dlZd dlmZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZ d dlZd d
lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ ejX                  ejZ                  fZ.ddZ/d Z0g dZ1 G d de      Z2y)    N)datetime)ThreadPoolExecutor)TimeoutError)rmtree)ImporterHelperSoSTimeoutErrorboldsos_get_command_outputTIMEOUT_DEFAULTlistdiris_executable)_sos)__version__)SoSComponent)
ReportSectionCommand
CopiedFileCreatedFileAlertNotePlainTextReport
JSONReport
HTMLReport)
SoSCleanerc                 (   g }| }|rt        |       dz  }nd}|D ]C  }t        |      t        |      z   t        |      z   dkD  r|j                  |       |}||z   |z   }E |t        |       d  |k(  r|d t        |        }|j                  |       |S )N  H   )lenappend)
first_lineitemsindentseplineslinenewlineitems           5/usr/lib/python3/dist-packages/sos/report/__init__.py_format_listr+   -   s    EDj/C' !t9s4y 3s8+b0LLDd{S 	!
 SXIJ3Jc#hY	LLL    c                 2    t        j                  | 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<014sz%Y%m%d%H%M%S)r   strptime)dates    r*   _format_sincer0   ?   s    
 U|n==r,   )autoalwaysneverc                       e Zd ZdZdZdZi dddddddd	d
ddddddddd	dg dg dg dddddddg ddi dg dddg dd	ddddd dd!d"d#dd$d%d&g d'g d(g d)dd*dd+dd,di d-dd.d	d/g d0dd1ed2ed3g d4dd5dd6dd7g d8dd9dd:dd;dd<dd=dddddddddd	d	d>
Z fd?Ze	d@        Z
e	dA        ZdB ZdC ZdD ZdE ZdF ZdG ZdH ZdI ZdJ Zd~dKZdL ZdM ZdN ZdO ZdP ZdQ ZdR ZdS ZedT        ZddUZ dV Z!dW Z"dX Z#dY Z$dZ Z%d[ Z&dd\Z'd] Z(d^ Z)d_ Z*d` Z+da Z,db Z-dc Z.dd Z/de Z0df Z1dg Z2ddhZ3di Z4dj Z5dk Z6dl Z7dm Z8dn Z9do Z:dp Z;dq Z<dr Z=ds Z>dt Z?du Z@dv ZAdw ZBdx ZCdy ZDdz ZEd{ ZFd| ZGd} ZH xZIS )	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   chrootr1   cleancontainer_runtimekeep_binary_filesdescdomainsdisable_parsersskip_cleaning_filesdry_runestimate_onlyexperimentalenable_pluginsjournal_sized   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upload_s3_endpointupload_s3_regionupload_s3_bucketupload_s3_access_keyupload_s3_secret_keyupload_s3_object_prefix
add_preset
del_presetc                 <   t         |   |||       g | _        g | _        g | _        t               | _        || _        d| _        i | _	        | j                          | j                          | j                  j                         | _        | j                  j                   j#                  d      | _        | j'                          d}| j                  j                  | _        | j(                  j                  rd}n9| j                  j+                         r| j                  t,        j.                  k7  rd}| j0                  j3                  d| j                   d| d       | j(                  j4                  t6        vrq| j0                  j9                  d	| j(                  j4                          t;        j<                          | j>                  jA                          | jC                  d
       | jE                          | jG                          | jI                          y )N/reportdefaultcmdlinepolicyzset sysroot to 'z' ()zinvalid chroot mode:    )%super__init__loaded_pluginsskipped_pluginsall_optionssetenv_vars_argssysrootestimated_plugsizesprint_header
_set_debugr{   is_root_is_rootmanifest
componentsadd_section	report_md_set_directoriesoptsin_containerosr%   soslogdebugr:   chroot_modeserrorloggingshutdowntempfile_utilr;   _exit_check_container_runtime_get_namespaces_get_hardware_devices)selfparserargsrz   msg	__class__s        r*   r   zSoSReport.__init__   s   w/ !
#% ++- 11==hG{{**99C[[%%'DLLBFF,BC,T\\N#cU!DE99</KK 5dii6F6F5GHI$$&JJqM%%'""$r,   c           
      *   |j                  dd      }|j                  dddddd	       |j                  d
dddd	       |j                  dddd t        d       |j                  ddddd	       |j                  dddd       |j                  dddddd	       |j                  ddd        |j                  d!d"t        dd#d$%       |j                  d&dd'(       |j                  d)dd*(       |j                  d+dd,dd-	       |j                  d.d/d0d1t        d2g 3       |j                  d4t        d5d6d78       |j                  d9d:d;d0d<t        d=g 3       |j                  d>d?dd@dA       |j                  dBdCddDddE	       |j                  dFddG(       |j                  dHddIddJ	       |j                  dKddLt        dMdNO       |j                  dPdddQR       |j                  dSd dT        |j                  dUdVd0dWt        dXg 3       |j                  dYddZdd[	       |j                  d\dd]dd^	       |j                  d_dd`ddab       |j                  dct        dd#dd%       |j                  dedfd0dgt        dhg 3       |j                  didt        djdk       |j                  dld dm        |j                  dnd do        |j                  dpdqdrd0dst        g dtO       |j                  dug d0dvdwx       |j                  dyg d0dzd{x       |j                  d|dd}dd~	       |j                  ddddd	       |j                  ddddR       |j                  dd d        |j                  dd d        |j                  dd d        |j                  dd d        |j                  ddg dd       |j                  dddd       |j                  dd d        |j                  dd d        |j                  dd d        |j                  dd d        |j                  dd d        |j                  dd d        |j                  ddg dd       |j                         }|j                  dt        dd       |j                  dt        dd       |j                  dd      }|j                  ddddddd       |j                  ddg d0d       |j                  dd0g dd       |j                  ddd0g dd       |j                  dd0g dd       |j                  dd dd       |j                  dddddì       |j                  ddddǬȫ       |j                  dddddˬx       |j                  ddg d0dά       y )NzReport Optionsz.These options control how report collects dataz-az--alloptions
store_truer6   Fz%enable all options for loaded plugins)actiondestry   helpz
--all-logsr7   z-collect all available logs regardless of sizez--sincestorerb   zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])r   r   ry   typer   z--buildr8   z;preserve the temporary directory and do not package resultsz	--case-idr9   zspecify case identifier)r   r   r   z-cz--chrootr:   r1   zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)ry   r   z--descz--descriptionr   zDescription for a new preset)r   r   ry   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--experimentalrD   zenable experimental pluginsz-ez--enable-pluginsextendrE   zenable these plugins)r   r   r   r   ry   z--journal-sizerG   rF   z+limit the size of collected journals in MiB)r   ry   r   r   z-kz--plugin-optionz
--plugoptsrJ   z7plugin options in plugname.option=value format (see -l)z--labelz--namerK   z"specify an additional report labelz-lz--list-pluginsrL   z)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrN   zBdisplay a list of available profiles and plugins that they includez
--log-sizerO   rP   z6limit the size of collected logs (not journals) in MiB)r   r   r   ry   r   z--low-priorityz(generate report with low system priority)r   ry   r   z--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrV   zdisable these pluginsz--no-reportrX   z disable plaintext/HTML reportingz--no-env-varsrY   z$Do not collect environment variablesz--no-postprocrZ   zDisable all post-processing)ry   r   r   r   z--notezBehaviour notes for new presetz-oz--only-pluginsr]   zenable these plugins onlyz--presetzA preset identifier)r   r   r   ry   z--plugin-timeoutzset a timeout for all pluginsz--cmd-timeoutz%set a command timeout for all pluginsz-pz	--profilez
--profilesra   z)enable plugins used by the given profilesz--skip-commandsrT   zdo not execute these commands)ry   r   r   r   z--skip-filesrU   zdo not collect these filesz--verifyrc   z+perform data verification during collectionz--allow-system-changesrd   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-method)r1   putpostz HTTP method to use for uploading)ry   choicesr   z--upload-no-ssl-verifyz'Disable SSL verification for upload url)ry   r   r   z--upload-s3-endpointz#Endpoint to upload to for S3 bucketz--upload-s3-regionz!Region to upload to for S3 bucketz--upload-s3-bucketz"Name of the S3 bucket to upload toz--upload-s3-access-keyzAccess key for the S3 bucketz--upload-s3-secret-keyzSecret key for the S3 bucketz--upload-s3-object-prefixzPrefix for the S3 object/keyz--upload-protocol)r1   httpsftpsftps3z$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 presetzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz	--cleanerz--maskr;   zObfuscate sensitive information)r   ry   r   r   z	--domainsr?   z$Additional domain names to obfuscatez--disable-parsersr@   zCDisable specific parsers, so that those elements are not obfuscated)r   ry   r   r   z--skip-cleaning-filesz--skip-masking-filesrA   zBList of files to skip/ignore during cleaning. Globs are supported.z
--keywordsrH   zList of keywords to obfuscatez--keyword-filerI   z&Provide a file a keywords to obfuscate)ry   r   r   z--no-updater[   z%Do not update the default cleaner mapz
--map-filerR   rS   z;Provide a previously generated mapping file for obfuscation)r   ry   r   z--keep-binary-filesr=   zGKeep unprocessable binary files in the archive instead of removing themz--usernamesre   zList of usernames to obfuscate)add_argument_groupadd_argumentr0   strintadd_mutually_exclusive_group)clsr   
report_grp
preset_grpcleaner_grps        r*   add_parser_optionszSoSReport.add_parser_options   s=   ..<
 	n\%15%L 	  	N 	\%/&/ 	  	0 		'%,d&@ 	  	A
 		,%,e&; 	  	< 	G)%> 	  	@j%-v&L 	  	M 	 5v&O 	  	P 	/'.%C 	  	F 	L%J 	  	L 1,&5 	  	6
 	 0%3U%B 	  	D 	&8%5C%;R 	  	I 	 0sC%3&. 	  	/ 	&7'/%/c&7@B	 	  	D
 		8G%,%I 	  	K 	&6|%3U&/ 	  	0 	 0%J 	  	L 1,%4e&B 	  	C 	W:%("&= 	  	> 	 0(-%O 	  	" 	&F 	  	G 	&6x%3#%<b 	  	J 	l%0%%G 	  	I 	%2E%K 	  	M 	%2<%B 	  	D 	s7B%E 	  	G&6x%3#%@" 	  	N 	
7%:F 	  	L 2D%D 	  	F%L 	  	Nk<'/js(*&0 	  	1
 	 12h%4%D 	  	F 	8%1%A 	  	C 	
<%-u&2 	  	3 	 8%;U&J 	  	K 	
<&0 	  	1 	%M 	  	O 4d%K 	  	M%N 	  	P%N 	  	P 16(?%G 	  	I 	 8%'3%N 	  	P 	 6%J 	  	L 4d%H 	  	J 4d%I 	  	K 8$%C 	  	E 8$%C 	  	E ;T%C 	  	E 3V)/%K 	  	M  <<>
S%J 	  	LS%K 	  	M //%E
 	  K&-).|&G 	! 	I 	  9b(0&L 	! 	N 	  !4X)+2C(K 	! 	M 	  !8!7)+2G(H 	! 	J
 	  h&0&E 	! 	G 	  !14&4&N 	! 	P 	  |).[&M 	! 	O 	  J)K(? 	! 	A 	  !6(4&9'I 	! 	J
 	  ["(0&F 	! 	Hr,   c                 :   |j                  d       |j                  d       |j                  d       |j                  d       |j                  d      }|j                  d       |j                  d       |j                  d	      }|j                  d
t        d       dt        d              |j                  dt        d       d       dddd}d}|j	                         D ]  \  }}|j                  d|d| d         |j                  |       y )NzSoS Report Detailed HelpzThe 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.zAdditionally, sos report archives can be used for ongoing inspection for pre-emptive issue monitoring, such as that done by the Insights project.zThe 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.zHow Collections Are Determined)titlezSoS report performs its 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.aF  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 example policies can alter where the --upload option defaults to or functions.zSee Alsoz5For information on available options for report, see zsos report --helpz and zman sos-reportzThe following zsos helpz sections may be of interest:
z'Information on the plugin design of sosz!Information on a specific $pluginz+How sos operates on different distributions)zreport.pluginszreport.plugins.$pluginpoliciesr   	z<36F)r(   )	set_titleadd_textr   r	   r#   )r   sectionpsecssec
help_lineshelplnlnvalues           r*   display_helpzSoSReport.display_help  sN   45.	
 	'	
 	<	
 "")I"J	
 		
 """4C'()t4D/E.FH	
 	tJ'7&8 9$ $ 	% H&IE


 #))+ 	?IBMMBr#hug.M>	?fr,   c                 D    t        dt        dt         d       d       y )N
zsos report (version r|   )print_r   r   s    r*   r   zSoSReport.print_header  s#    1+K=:;<B?@r,   c                     | j                         | j                         d| j                         | j                         | j	                         d| _        y )N)blockfibre)storagenetworknamespaced_networkfstype)_get_block_devs_get_fibre_devs_get_network_devs_get_network_namespace_devices_get_devices_by_fstypedevicesr   s    r*   r   zSoSReport._get_hardware_devices  sP     --/--/ --/"&"E"E"G113
r,   c                    | j                   j                  dk7  ro| j                   j                  j                         }|dv r-i | j                  _        | j
                  j                  d       y| j                  j                  s"d| d}| j
                  j                  |       y|| j                  j                  j                         vrKdj                  d | j                  j                  j                         D              }t        d| d	|       | j                  j                  |   | j                  j                  d
<   | j
                  j                  d| j                  j                  d
   j                   d       yy)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).
        r1   )noneoffdiabledz0Disabled all container runtimes per user option.zVWARNING: No container runtimes are active, ignoring option to set default runtime to ''
, c              3   *   K   | ]  }|d k7  r|  yw)ry   N .0ps     r*   	<genexpr>z5SoSReport._check_container_runtime.<locals>.<genexpr>  s      "5%&)^ #$ "5s   zCannot use container runtime 'z1': no such runtime detected. Available runtimes: ry   z"Set default container runtime to ''N)r   r<   lowerr{   runtimesr   infowarningkeysjoin	Exceptionname)r   crunr   valids       r*   r   z"SoSReport._check_container_runtime  s^    99&&&099..446D11')$  F [[))<<@6F##C(T[[116688		 "5T[[-A-A-F-F-H "5 5"@ GN#('!+ , , 37++2F2Ft2L$$Y/  ,,Y7<<=Q@' 1r,   c                 $   	 g }g d}|D ]M  }t         j                  j                  d|       s&|j                  t	        j                  d| d             O |S # t
        $ r*}| j                  j                  d|        g cY d}~S d}~ww xY w)zEnumerate 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/z/*z!Could not get fibre device list: N)r   pathisdirr   globr   r   r   )r   devsdevdirsdevdirerrs        r*   r   zSoSReport._get_fibre_devs  s    	DG " E77==;vh!78KK		Kxr*B CDE K 	KK A#GHI	s"   -A +A 	B%B
B
Bc                    	 t        j                  d      D cg c]  }d| 	 }}t        d      }g }|d   dk(  rL|d   j                         D ]6  }|j	                         d   j                  dd      }|j                  |       8 |D cg c]  }|j                  d	      r||vr| }}t        t        |      t        |      z
        }	|	S c c}w c c}w # t        $ r*}
| j                  j                  d
|
        g cY d}
~
S d}
~
ww xY w)zEnumerate 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.
        z
/sys/blockz/dev/zlosetup --all --noheadingsstatusr   output:r   loopz!Could not get block device list: N)r   r   r
   
splitlinessplitreplacer!   
startswithlistr   r   r   r   )r   ddevice_listloop_devicesreal_loop_devicesloop_devloop_devicedevghost_loop_devsdev_listr   s              r*   r   zSoSReport._get_block_devs  s#   	02

<0HI1U1#;IKI12NOL "H%* ,X 6 A A C :H"*.."21"5"="=c2"FK%,,[9: /: @s"%.."8"%->">  # @O @ C,s?/CCDHO J@
  	KK A#GHI	s:   C CA'C C*#C 
C 	D!D DDc                 2    d| j                         i| _        y )Nr   )_get_network_namespacesrW   r   s    r*   r   zSoSReport._get_namespaces  s    t335
r,   c                    g g g g d}	 t        d| j                  j                        r|j                  | j	                                |d   sM| j
                  j                  d       |j                  | j                                | j                         |d<   |S # t        $ r)}| j
                  j                  d|        Y d}~|S d}~ww xY w)	a  Helper 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   s      r*   r   zSoSReport._get_network_devs  s     	
	OWdii.?.?@T1134$!!8 T//12"&"7"7"9h   	OKK"Gu MNN	Os   BB 	C&C

Cc                 ^    i }| j                   d   D ]  }d| j                  |      i||<    |S )zqEnumerate the network devices that exist within each network
        namespace that exists on the system
        r   r  )rW   r  )r   _nmdevsnmsps      r*   r   z(SoSReport._get_network_namespace_devices=  sC     OOI. 	DD..t4GDM	 r,   c                    i }	 t        d      }|d   dk(  ra|d   j                         dd D ]H  }|j                         \  }}||vr|g||<   n||   j                  |       |d   j                  |       J t	        t        |d               |d<   |S # t        $ r)}| j                  j                  d|        Y d}~|S d}~ww xY w)	zUse nmcli, if available, to enumerate network devices. From this
        output, manually grok together lists of devices.
        znmcli --fields DEVICE,TYPE devr  r   r  r}   Nr  zCould not parse nmcli devices: )	r
   r  r  r!   r
  r   r   r   r   )r   r   _ndevsr  dnamedtyper   s          r*   r  zSoSReport._get_nmcli_devsH  s     	G+,LMFh1$!(+668< 4C#&99;LE5E)(-wee++E2*%,,U34 !%Sz):%; <E*   	GKK ?uEFF	Gs   BB 	CCCc                 ^   dg}g }|s	 t        dd      D cg c]  }||vr|
 }}nH	 d| d}t	        |      }|d   dk(  r.|d	   j                         D ]  }||vs|j                  |        ||D 	cg c]  }	|	j                  d      s|	 c}	|D 
cg c]  }
|
j                  d      s|
 c}
dS c c}w # t        $ r(}| j                  j                  d|        Y d}~wd}~ww xY w# t        $ r+}| j                  j                  d
| d|        Y d}~d}~ww xY wc c}	w c c}
w )a8  Enumerate 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_mastersz/sys/class/netNz.Failed to manually determine network devices: zip netns exec z ls /sys/class/netr  r   r  z'Could not determine network namespace 'z' devices: r  tun)r  r  r*  )r   r   r   r   r
   r  r!   r	  )r   	namespace	filt_devs	_eth_devsr  r   _nscmd_nsout_nsethbdtds              r*   r  zSoSReport._get_eth_devs\  sf     ''		
 $++;T#B)+ 	 ))4FG/7(#q("("2"8"8": 5!2%,,V45 ""+EBr}}V/DRE!*C2bmmE.BBC
 	
+  ##DSEJ   ##=i[ I  #u&  FCs\   B: B5B: 3C. C. 4D%D%D*,D*5B: :	C+C&&C+.	D"7!DD"c                    g }	 t        dd      }d   dk(  r>|d   j	                         d	d D ]%  }	 |j                  |j                         d          ' |S # t        $ r(}| j                  j                  d|        Y d}~td}~ww xY w# t        $ r+}| j                  j                  d
| d|        Y d}~d}~ww xY w)zEnumerate 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: Nr  r   r  r}   z"Could not parse device from line 'z': )r
   r   r   r   r  r!   r  r   )r   _bridges_boutr   _blines        r*   r  zSoSReport._get_bridge_devs  s     	N*<DE ?a/446qr: OOFLLN1$56   	NKK"Fse LMM	N ! KK$$<VHCuM s.   A "B	B
"BB
	C!B<<Cc                     g }t        d      }|d   dk(  r_|d   j                         D ]I  }|j                         s|dd j                         r'|j                  |j	                  d      d          K |S )zEnumerate 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.
        zip netnsr  r   r  Nr}   r   )r
   r  isspacer!   	partition)r   out_nsip_netnsr'   s       r*   r  z!SoSReport._get_network_namespaces  s{     )*5H" *557 6<<>T"1X%5%5%7dnnS1!456 r,   c                 V   i }t        d      }|d   dk7  r|S |d   j                         D ]{  }|j                         j                         }t	        |      dk(  r|j                  dd       d|d   v rd|d<   |j                  |d   g        ||d      j                  |d          } |S )	Nzlsblk -snrpo FSTYPE,NAMEr  r   r  r}   unknownextext4)r
   r  stripr  r    insert
setdefaultr!   )r   _dev_fstypesr   r'   helpers        r*   r   z SoSReport._get_devices_by_fstype  s    &'AB?a8_//1 	6DZZ\'')F6{aa+q	!"q	##F1Ir2#**6!95	6 r,   c                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  j                  | j                  | j                  | j                  dS )N)cmddirlogdirrptdirtmpdirr   r{   r   	verbositycmdlineoptsr   rW   )rI  rJ  rK  rL  r   r{   r   r   rM  r   rW   r   s    r*   get_commonszSoSReport.get_commons  s_    kkkkkkkkkkkk||,,99||//
 	
r,   c                 6    | j                   j                         S N)r   newr   s    r*   get_temp_filezSoSReport.get_temp_file  s    !!%%''r,   c                     | j                   j                  | j                  d       | j                   j                  | j                  d       | j                   j                  | j                  d       y )Ni  )archivemakedirsrI  rJ  rK  r   s    r*   _make_archive_pathszSoSReport._make_archive_paths  sJ    dkk51dkk51dkk51r,   c                 .    d| _         d| _        d| _        y )Nsos_commandssos_logssos_reports)rI  rJ  rK  r   s    r*   r   zSoSReport._set_directories  s    $ #r,   c                 x    | j                   j                  r| j                  t        _        d| _        y d| _        y )NTF)r   r   
_exceptionsys
excepthookraise_pluginsr   s    r*   r   zSoSReport._set_debug  s(    99??!__CN!%D!&Dr,   c                    t        t        d      st        j                  j                         st        j                  | ||       yt        j                  | ||dt        j                         t                t        j                          y)z* Wrap exception in debugger if not in tty ps1   )limitfileN)hasattrr^  stderrisatty__excepthook__	tracebackprint_exceptionstdoutr   pdbpm)etypeeval_etraces      r*   r]  zSoSReport._exception  s^     3cjj&7&7&9 ueV4 %%eUF!+.::7GFFHr,   c                     | j                   s| j                  r^t        j                         \  }}}t	        j
                  |||t        j                         t                t        j                  |       |r|r| j                  ||       y y y )N)re  )r`  exit_processr^  exc_inforj  rk  rl  r   rm  post_mortem_log_plugin_exception)r   plugnamefuncro  valtbs         r*   handle_exceptionzSoSReport.handle_exception  sj    !2!2"||~UC%%eS"3::FGOOB&&x6 8r,   c                 N   t        | dd       rE| j                  j                  | j                  t        j
                  j                  dd             t        | dd       rF| j                  j                  | j                  t        j
                  j                  dd             y y )Nsos_log_filerZ  sos.logr   sos_ui_log_fileui.log)getattrrU  add_filer}  r   r   r   r  r   s    r*   _add_sos_logszSoSReport._add_sos_logs  s    
 4.LL!!$"3"3')ww||J	'J " L4*D1LL!!$"6"6')ww||J'I " K 2r,   c                       j                   j                  } j                   j                  syt        |d      sy|r  j	                  |j                               syt         fd|j                  D              S )NTra   Fc              3   N   K   | ]  }|j                   j                  v   y wrQ  )r   ra   )r   r   r   s     r*   r   z+SoSReport._is_in_profile.<locals>.<genexpr>  s      Jq1		***Js   "%)r   r]   ra   rf  _is_not_specifiedr   any)r   plugin_classr]   s   `  r*   _is_in_profilezSoSReport._is_in_profile  sb    yy--yy!!|Z0 6 6|7H7H7J KJL4I4IJJJr,   c                 2    || j                   j                  v S rQ  )r   rV   r   plugin_names     r*   _is_skippedzSoSReport._is_skipped  s    dii4444r,   c                      || j                               j                          xr2 || j                  j                  vxr || j                  j                  vS rQ  )rO  check_enabledr   rE   r]   r   r  pluginClasss      r*   _is_inactivezSoSReport._is_inactive  sR     0 0 23AACC :499#;#;;:499#9#99	;r,   c                      || j                               j                          xr2 || j                  j                  vxr || j                  j                  vS rQ  )rO  default_enabledr   rE   r]   r  s      r*   _is_not_defaultzSoSReport._is_not_default  sR     0 0 23CCEE :499#;#;;:499#9#99	;r,   c                 b    | j                   j                  xr || j                   j                  vS rQ  )r   r]   r  s     r*   r  zSoSReport._is_not_specified$  s+    		&& :499#9#99	;r,   c                     | j                   j                  |j                          || j                               |f       y rQ  )r   r!   r   rO  )r   r  reasons      r*   _skipzSoSReport._skip(  s;    ##))+,%
 	r,   c                     | j                   j                  |j                          || j                               f       y rQ  )r   r!   r   rO  )r   r  s     r*   _loadzSoSReport._load/  s8    ""))+,$
 	r,   c           
      \   t         j                  j                  j                  }t	        t         j                  j                        }|j                         }g | _        t               | _        t        | j                  j                        }| j                  j                  }g }| j                  j                  r3|j                  t         j                  j                  j                         t!        ||z         }| j                  j"                  }t%        | j                  j                        }	|D ]?  }
t&        j(                  j+                  |
      \  }}	  |||      }|s3| j                  j-                  |      } ||| j                  j                        s]| j.                  j1                  t3        d|
 d             | j                  j4                  dkD  r| j7                  |t3        d             | j                  j                  |       | j9                  |      }|s| j7                  |t3        d             | j;                  |      r| j7                  |t3        d             B| j=                  ||      r| j7                  |t3        d             q| j?                  ||      r| j7                  |t3        d	             tA        |d
      r%| j                  jC                  |j                         | xr |}| jE                  |      r|r| j7                  |t3        d             |j                  D ]  }||	v s|	jG                  |        | jI                  |       B t        |	      dkD  rX| j.                  jO                  t3        ddjQ                  |	                    | jS                          | jU                  d       y y # tJ        $ rE}| j.                  j1                  t3        d|
 d|              | jM                          Y d }~d }~ww xY w)N)rD   zplugin z does not validate, skippingr   zdoes not validateexcludedskippedinactiveoptionalra   znot specifiedz does not install, skipping: z)Unknown or inactive profile(s) provided: r   r}   )+sosrx   pluginsimport_pluginr   get_modulesplugin_namesr   ra   r    r   r{   valid_subclassesrD   r!   ExperimentalPlugintuplevalidate_pluginr
  r   r   splitextmatch_pluginr   r   r   rM  r  r  r  r  r  rf  r  r  remover  r   r{  r   r   rN   r   )r   r  rG  r  using_profilespolicy_classesextra_classesvalid_plugin_classesr  remaining_profilesplugplugbase__plugin_classesr  
in_profiledefault_profileies                      r*   load_pluginszSoSReport.load_plugins5  s}   

**88

 2 23$$&TYY//05599!!  !3!3!F!FG$^m%CD++55!$))"4"45  7	(D77++D1LHb5(!.x9M!N%#{{77G&|48II4J4JLKK''GD6)EFGIyy**Q.

<3F1GH  !!((2!00>
!JJ|Qz];##H-JJ|Qy\:$$X|<JJ|Qz];'',?JJ|Qz]; <4MM(()>)>? '5"4"C))(3JJ|Q-?@%.. 5A..*11!45 

<(g7	(p !"Q&KKa !$$(II.@$A#B!D E F JJqM	 '	  (##Av 6334#'7 %8 9%%''(sK   O&BO<A	O,O5-O$-OA&O;O$O	P+&:P&&P+c                     | j                   j                  rN| j                  D ]>  \  }}|j                  j	                         D ]  }t
        |j                  v sd|_         @ y y )NT)r   r6   r   optionsvaluesboolval_typer   )r   r  r  opts       r*   _set_all_optionszSoSReport._set_all_options  s\    99 // )D<<..0 )Cs||+$(	))  r,   c           	         | j                   j                  ri }| j                   j                  D ]t  }	 |j                  d      \  }}t	        |t
              r*|j                         }|dv rd}n|dv rd}n	 t        |      }	 |j                  d      \  }}	 ||    |||   |<   v | j                  D ]  \  }}||v s||   D ]  }||j                  vr3| j                  j                  d| d| d	       | j                  d
       	 |j                  |   j                  ||   |          | j                  j                  d| d|j                  |            ||=  |D ]!  }| j                  j                  d| d       # |j#                         r| j                  j                  d       y y y # t        $ r d}Y {w xY w# t        $ r Y Qw xY w# t        $ r |}d}Y Pw xY w# t        $ r	 i ||<   Y _w xY w# t         $ r7}| j                  j                  |       | j                  d
       Y d }~xd }~ww xY w)N=T)onenableenabledtrueyes)r   disabledisabledfalsenoF.zno such option "z" for plugin (r|   r}   zSet z plugin option to zCWARNING: unable to set option for disabled or non-existing plugin (z).r   )r   rJ   r  
ValueError
isinstancer   r   r   KeyErrorr   r  r   r   r   	set_valuer   r   r   )r   r   r  ry  r  rw  r   s          r*   _set_tunableszSoSReport._set_tunables  sz   99Dyy)) &"yy~HC c3'))+CHH" MM#!"%c(C
 #		#ID#
$J #&T
3=&@ #'"5"5 '$t##H~ *dll2 KK--0@ F99A
!/E F JJqM* LL-77Xs8KL KK--"&xj0B#'<<#4"5!78* X'  ! K!! #==EJb#J KK
 yy{!!"% o 
 " C  * ! ! " DC   $!#DJ$   ) * KK--c2 JJqMM*s`   F57GGG+AH 5GG	GGG('G(+G=<G= 	I 	,H;;I c                    dd l }|j                  | j                  j                  | j                  j                        D ]U  }|j                  d      d   }|| j                  vs&| j                  j                  d| d       | j                  d       W | j                  j                  D ]0  }|| j                  vs| j                  j                  d| d       2 y )Nr   r  za non-existing plugin (z$) was specified in the command line.r}   z'Requested to skip non-existing plugin 'z'.)	itertoolschainr   r]   rE   r  r  r   fatalr   rV   r   )r   r  pluginr  s       r*   _check_for_unknown_pluginsz$SoSReport._check_for_unknown_plugins  s    oodii&<&<&*ii&>&>@ 	F ,,s+A.K$"3"33!!$;K= IC #C D

1	 ii,, 	FT...##=fXRH	r,   c                     | j                   D ]>  \  }}|j                  D ]*  }| j                  j                  |j                  |          , @ y rQ  )r   r  r   r!   )r   r  r  r  s       r*   _set_plugin_optionszSoSReport._set_plugin_options  sK    -- 	=JB~~ =  ''s(;<=	=r,   c                 N   d}g }| j                   j                  dkD  r/|d| j                   j                   dgz  }d| j                   _        | j                   j                  s|dgz  }d| j                   _        | j                   j                  s|dgz  }d| j                   _        | j                   j                  r|dgz  }d	| j                   _        | j                   j
                  r|d
gz  }d	| j                   _        |r|ddj                  |      z   z  }n|dz  }|dz  }|S )Nz
Estimate-only mode enabledr}   z
--threads=z overriden to 1z--build enabledTz--no-postproc enabledz--clean disabledFz--upload* options disabledz", which overrides some options:
  z
  r  z

)r   threadsr8   rZ   r;   rf   r   )r   r   ext_msgs      r*   _set_estimate_onlyzSoSReport._set_estimate_only  s    -99q *TYY%6%6$7GJJG !DIIyy),,G"DIIOyy$$/22G$(DII!99??*--G#DIIO99477G$DII86;;w;OOOC3JCv
r,   c                 ~   | j                   j                  d       | j                  rI| j                   j                  dt        | j                         dt        | j                         d       n2| j                   j                  dt        | j                         d       | j                   j                  d       y )Nr   r   z profiles, z pluginsz	 profiles)ui_logr   r   r    ra   r   s    r*   _report_profiles_and_pluginsz&SoSReport._report_profiles_and_plugins  s    KKqT]]!3 4K #D$7$7 89C D KKqT]]!3 4I>?r,   c           
      	   | j                   s1| j                  s%| j                  j                  t	        d             y | j                   r| j
                  j                  t	        d             | j
                  j                  d       | j                   D ]5  \  }}| j
                  j                  d|dd|j                                 7 n$| j
                  j                  t	        d             | j
                  j                  d       | j                  r| j
                  j                  t	        d             | j
                  j                  d       | j                  D ]:  \  }}}| j
                  j                  d|dd|dd|j                                 < | j
                  j                  d       | j                  r| j
                  j                  t	        d	             | j                   d
   d   j                         }|D ]  }||   }|j                  }|j                  dk(  rN|dk(  r| j                  j                  xs t        }n*|dk(  r| j                  j                  xs t        }nt        }|j                  dk(  r| j                  j                    }| j
                  j                  d|j                  dd|dd|j"                           | j
                  j                  d       | j
                  j                  t	        d             | j                  D ]  }|j                  dv r|j                  |j$                  k(  r+t'        |j                  t(              r|j                  du rd}	nd}	n|j                  }	|	d
}	| j
                  j                  d|j*                   d|j                   dd|	dd|j"                           n$| j
                  j                  t	        d             | j
                  j                  d       t-        | j.                        }
|
j1                          t3        d|
d      }|D ]   }| j
                  j                  d|        " | j5                          y )Nzno valid plugins foundz,The following plugins are currently enabled:r   r   z<20zNo plugin enabled.z-The following plugins are currently disabled:z<14z4The following options are available for ALL plugins:r   r}   r6  cmd-timeoutpostprocz<25<15z+The following plugin options are available:)r6  r  r  Tr  r   r  zNo plugin options available.z
Profiles: r$   )r   r   r   r  r   r  r   get_descriptionr   get_default_plugin_optsr   r   r_   r   r`   r   rZ   r>   ry   r  r  r  r
  ra   sortr+   r  )r   rw  r  	plugclassr  	_defaults_optr  ry  tmpoptra   r&   r'   s                r*   rL   zSoSReport.list_plugins  s   ""4+?+?KKa 89:KKQMNOKKR $($7$7 N 4  1XcN!D4H4H4J3K!LMN KKQ345KKQ  + , -KKR 151E1E C-9f  1XcN!F3<q$-$=$=$?#@"B CC 	KKQ  * + ,++A.q1IIKI! Joii99?y("ii66I/."ii33F-88z)"ii333C  1SXXcN!C9AchhZ!HIJ KKR KKQLMN'' =88EEyyCKK/ cii.yyD(!%!& YYF>F  1

|1SXXJ%?$DA$*3<q
"< =!=& KKQ=>?&\8DA 	)DKKqZ(	)))+r,   c                 J   | j                   s%| j                  j                  t        d             y | j                  j                  t        d             | j                  j                  d       d }t        | j                         }|j                          |D ]v  }g }| j                  D ].  \  }} ||      s||j                   v s|j                  |       0 t        |d|d      }|D ]   }| j                  j                  d|        " x | j                          y )	Nzno valid profiles foundz%The following profiles are available:r   c                     t        | d      S )Nra   )rf  )cs    r*   	_has_profz*SoSReport.list_profiles.<locals>._has_profO  s    1j))r,   r  Tr  r   )ra   r   r  r   r  r   r
  r  r   r!   r+   r  )	r   r  ra   profiler  r   r  r&   r'   s	            r*   rN   zSoSReport.list_profilesH  s   }}KKa 9:;BCD	* & 	-GG $ 3 3 )fV$FOO)CNN4() !GC=74HE -  1TF,-	- 	))+r,   c                    | j                   j                  s%| j                  j                  t	        d             y | j
                  j                  t	        d             | j
                  j                  d       | j                   j                  j                         D ]3  }|s| j                   j                  |      }| j
                  j                  ddd|j                          | j
                  j                  ddd|j                          |j                  r+| j
                  j                  ddd|j                          | j                  j                  d	kD  rQ|j                  j                         }d
dd}t        ||dd      }|D ]  }| j
                  j                  |        | j
                  j                  d       6 y )Nzno valid presets foundz$The following presets are available:r   zname:z>14r   zdescription:znote:r   zoptions:T)r$   r%   )r{   presetsr   r  r   r  r   r   find_presetr   r>   r\   r   rM  to_argsr+   )r   r^   r   options_strr&   r'   s         r*   rM   zSoSReport.list_presets^  sw   {{""KKa 89:ABCkk))..0 	!F[[,,V4FKK}Afkk];<KKs31V[[MBC{{  GC=&++!?@yy""Q&{{**,!+C 02$[$tM! +DKK$$T*+KKR 	!r,   c                 j   | j                   }|j                  |      r | j                  j                  d| d       y|xs | j                  j
                  }|xs | j                  j                  }	 |j                  |||| j                         | j                  j                  d      }| j                  d| | j                  |d	z   d z   }| j                  j                  d
| ddj                  |       d       y# t        $ r(}| j                  j                  d|        Y d}~yd}~ww xY w)zAdd 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 'z' already existsF)r   r>   r\   r   zCould not add preset: Nr   r   rc  zAdded preset 'z' with options r   r   T)r{   r  r  r   r   r>   r\   rt   r   rz   indexr   r   )r   r   r>   r\   r{   r  	arg_indexr   s           r*   rt   zSoSReport.add_presetv  s    d#KK 06FGH%tyy~~%tyy~~	4dDIIN LL&&~6	||Ai(4<<	A+GGTF/#((4.1AD	F  	KK 6qc:;	s   3D 	D2
D--D2c                 \   | j                   }|j                  |      s | j                  j                  d| d       y	 |j	                  |       | j                  j                  d| d       y	# t
        $ r1}| j                  j                  t        |       d       Y d}~yd}~ww xY w)
zDelete a named command line preset.

            :param name: the name of the preset to delete
            :returns: True on success or False otherwise
        zPreset 'z' not foundFr   r   NzDeleted preset 'r   T)r{   r  r  r   ru   r   r   r   )r   r   r{   r  s       r*   ru   zSoSReport.del_preset  s     !!$'KKk:;	4(
 	+D656  	KKQm,	s   A1 1	B+:'B&&B+c                    | j                   j                         }| j                  j                  r|| j	                         z  }| j                  j
                  r| j                  j                  |       y |t        d      z  }	 t        |       y # t        $ r/ | j                  j                  d       | j                  d       Y y t        $ r}| j                  d|       Y d }~y d }~ww xY w)Nz,Press ENTER to continue, or CTRL-C to quit.
zExiting on user cancel   r}   )r{   get_msgr   rC   r  batchr  r   r   inputKeyboardInterruptr   r   r   )r   r   r  s      r*   r  zSoSReport.batch  s    kk!!#99""4**,,C99??KKS!1DEEC!c
$  !!":;

3 !

1a  !s   B 5C,C,C''C,c                 T   t        j                         }d}| d}t        j                  j	                  | j
                  |      }| j                  j                  | d| d| d       | j                  j                  d|        | j                  j                  | d|d	       y )
Nz!caught exception in plugin methodz-plugin-errors.txtz "r  z()"zwriting traceback to r   a)mode)
rj  
format_excr   r   r   rJ  r   r   rU  
add_string)r   r  methodtracer   plugin_err_loglogpaths          r*   rv  zSoSReport._log_plugin_exception  s    $$&1"8#56'',,t{{N;SEF81VHC891';<5'gC@r,   c                    | j                   j                          	 | j                  j                  t	        d             | j                          | j                          y # t        $ r[}|j                  t        v r0t        d       t        d|j                   d       t        d       nt        d|         Y d }~n~d }~wt        $ ro}| j                  j                  d       | j                  j                  d       t        j                          | j                  j                  |       Y d }~nd }~ww xY w| j!                  d       y )Nz Setting up archive ...r   r   z while setting up archivezError setting up archive: z) Unexpected exception setting up archive:r}   )r{   pre_workr  r   r   setup_archiverW  OSErrorerrnofatal_fs_errorsr   strerrorr   r   rj  	print_excr   r   r  s     r*   preworkzSoSReport.prework  s   	!KKQ89: $$& 
	 ww/)b	!**%>?@b	21#67   	!KKb!KKIJ!KKa  		!
 	

1s&   AA! !	D;*AC  D;A%D66D;c                    | j                   j                  t        d             | j                  D ]V  \  }}	 | j                  j
                  j                  |       |j                  t        | j                  j
                  |             t        j                         }|j                  j                  d|       | j                  |_        |j                          |j                          | j                   j#                  |j$                         | j&                  j(                  r|j+                          t        j                         }|j                  j                  d|       |j                  j                  d||z
         Y y # t,        $ r t,        t.        $ r}|j0                  t2        v rp| j                   j5                  d       | j                   j5                  d|j6                   d       | j                   j5                  d       | j9                  d       | j;                  |d	       Y d }~d }~wt<        $ r | j;                  |d	       Y -w xY w)
Nz Setting up plugins ...setup_start	setup_end
setup_timer   r   z while setting up pluginsr}   setup)r  r   r   r   r   r  r   set_plugin_manifestr  r   nowr   	add_fieldrU  add_default_collectionsr  r   r  	_env_varsr   rc   setup_verifyr  r  r  r  r   r  r   r{  r   r   rw  r  startendr  s         r*   r  zSoSReport.setup  s   456"11 	9NHd9&&228<((1G1G19*; < ''u=#||,,.

$$T^^499##%%'lln''S9''cEkB	9  % ('' 977o-KK%%b)KK%%AJJ<'@ACKK%%b)JJqM%%h88 9%%h89s   EFI#BH==IIc                     g }|j                  dt                | j                  j                  dj	                  |      d       y)zWFetch version information from all plugins and store in the report
        version filezsos report: r   zversion.txt)contentr   N)r!   r   rU  r	  r   )r   versionss     r*   versionzSoSReport.version  sA     ,{m45		((;%2 	  	4r,   c                    | j                   j                  t        d             | j                   j                  d       d}g | _        g | _        | j
                  D ]'  }|dz  }| j                  j                  ||d   f       ) 	 g }t        | j                  j                        5 }|j                  | j                  t        | j                              }d d d        |D ]#  }|r| j                  j                  d|        % | j                   j                  d       y # 1 sw Y   MxY w# t        $ r3 | j                   j!                  d       t#        j$                  d       Y y w xY w)Nz! Running plugins. Please wait ...r   r   r}   zUnexpected plugin task result: z
Exiting on user cancel
)r  r   r   pluglistrunning_plugsr   r!   r   r   r  map_collect_pluginr
  r   r   r  r   r   r   )r   plugruncountr  resultsexecutorress         r*   collectzSoSReport.collect  sA   >?@$$ 	7AALMM  ,!!56	7	G#DII$5$56 <(",,t';';'+DMM':<<  OKK%%(Gu&MNO KKR < < ! 	KK:;HHQK	s0   !D0 (0D$D0 (;D0 $D-)D0 09E,+E,c                    t        d      5 }	 | j                  |d   dz
     d   }|j                  | j                  |      }|j                  xs d}t        j                         }|j                  j                  d|       |j                  |       t        j                         }|j                  j                  d|       |j                  j                  d||z
         ddd       | j*                  j,                  r| j.                  j1                         }		 t3        d|	       }
t5        |
d   j7                         d         | j8                  |d   <   t=        j>                  |	      D ]  }t<        j@                  jC                  |	|      }t<        j@                  jE                  |      r+t<        j@                  jG                  |      stI        |       mt=        jJ                  |        y# t        $ r d|d    d	}| j                  j                  d
| d       | j                  j                  |       | j                  j!                  |d          | j                  |d   dz
     d   j#                          |j%                  d       |j&                  j)                          Y w xY w# 1 sw Y   xY w# t:        $ r d| j8                  |d   <   Y w xY w)zaWraps the collect_plugin() method so we can apply a timeout
        against the plugin as a wholer}   r   N
start_timer5  end_timerun_timezPlugin z
 timed out
 r   T)waitzdu -sB1 r  )&r   r   submitcollect_pluginr6  r   r  r   r  resultFuturesTimeoutErrorr  r   r   r   r,  r  set_timeout_hitr   _threadsclearr   rC   rU  get_tmp_dirr
   r   r  r   r   r   r   r   r   r   islinkr   unlink)r   r  pool_plugtr6  r$  r%  r   rL  dufs               r*   r.  zSoSReport._collect_plugin  sj     " 	&d&++F1IaK8;KK 3 3V<  --/4 ((u=)lln((S9((S5[A	&0 99"" \\--/F8+hvh,?@8**,Q/0 ((3 ZZ' !GGLL+77==#BGGNN1,=1IIIaL! ? ' 
&q	{*5 !!CuB-0  %""))&)4##F1IaK03CCE4(##%
&	& 	&@  867((38s<   J6CG3=K 3B<J3/J62J33J66K K"!K"c           	      N   	 |\  }}| j                   |dz
     d   }| j                  j                  |       t	        | j                         }d| d| dd|dddj                  d	 | j                  D               d
}| j                  |       	 |j                          	 | j                  j                  |       	 | j                  j                  |       d}t	        | j                        t        | j                  j                        k  r6| j                  r*dddddj                  d | j                  D               d
}| j                  s| j                  sd}|r| j                  |       y # t        $ r Y yw xY w# t        $ r" | j                  j                  d| d       Y w xY w# t        $ r# | j                  j                  d| d       Y w xY w# t         $ r Y y t"        $ r}|j$                  t&        v rg| j(                  j+                  d|j,                   d       | j(                  j+                  d| j.                   d       t1        j2                  d       | j5                  |d       Y d }~y d }~wt        $ r | j5                  |d       Y y w xY w)Nr}   Fz  Starting rw   z<5r   r  z [Running: c              3       K   | ]  }|  y wrQ  r   r   s     r*   r   z+SoSReport.collect_plugin.<locals>.<genexpr>T  s     ,K1Q,K   ]zCould not remove z from plugin list, ignoring...z& from running plugin list, ignoring...r   z  Finishing plugins z<12c              3       K   | ]  }|  y wrQ  r   r   s     r*   r   z+SoSReport.collect_plugin.<locals>.<genexpr>m  s     %DAa%DrK  z
  Finished running pluginsr8  z while collecting plugin dataz# Data collected still available at r   r3  )r   r,  r!   r   r    r   ui_progressr;  r+  r  r  r   r   r   r   r  r   r  r  r  r  r   r  rL  r   r   r{  )	r   r  countrw  r  numplugsstatus_liner  r  s	            r*   r;  zSoSReport.collect_pluginK  s   	$OE8&&uQw/2D%%h/ t**+$waz%:2$>a~ N$$'HH,K8J8J,K$K#LAO%)	7!$$V,""))(3 FDMM"c$))*;*;&<<&&0S	 XX%D1C1C%DDEQH%%dmm7  ( a  		  !!'z 2" #  !!'z 2" #  	    	7ww/)!!!**%BCE!!9$++bIK!!(I66   	7!!(I6	7sy   5E4 G  "F >F1 BG  4	F ?F (F.+G  -F..G  1(GG  GG   	J$+J$3BJJ$#J$c                 >   | j                   j                  dk(  r+| j                   j                  sd|j                  d       }n| d}| j                   j                  s>t
        j                  j                  |       t
        j                  j                          y y )Nr   Z   r   )	r   rM  r  ljustquietr^  rl  writeflush)r   rQ  s     r*   rN  zSoSReport.ui_progress  st    99!#DIIOO{00456K(M,KyyJJ[)JJ r,   c           	      r   | j                   sy dj                  | j                   D cg c]C  }t        j                  j	                  |      "|t        j                  j	                  |       fE c}D cg c]  \  }}| d|  c}}      dz   }| j
                  j                  |d       y c c}w c c}}w )Nr   r  environment)r   r   r   environgetrU  r	  )r   r   ry  envs       r*   collect_env_varszSoSReport.collect_env_vars  s    }}ii;?== /4ZZ^^D!- rzz~~d+,. /
 +stfAcUO
  	
 	]3/
s   AB.5B3
c                    t               }| j                  D ]g  \  }}t        |      }|j                  D ]  }|j	                  t        |              |j                  r$|j	                  t        |j                               |j                  D ]'  }|j	                  t        |d   d|d   z                ) |j                  D ]U  }|j	                  t        |d   dt        j                  j                  d| j                         d   |d	         
             W |j                   D ]@  \  }}}|j	                  t#        |t        j                  j                  d|                   B |j	                  |       j t$        ddft&        ddft(        ddff}	|	D ]  \  }
}}	 | j+                         } |
|      j-                         }|j/                  dd      j1                         }|j3                  |       |j5                          | j6                  j9                  |t        j                  j                  d|              y # t:        $ r}|j<                  t>        v rs| j@                  jC                  d       | j@                  jC                  d|jD                   d| d       | j@                  jC                  d       | jG                  d       Y d }~Ad }~ww xY w)Nr  srcpathz..dstpath)r   hrefcmdr   rI  re  )r   return_coderb  zsos.txttextzsos.jsonJSONzsos.htmlHTMLutf-8r  r[  r  r   r   z while writing z reportr}   )$r   r   r   alertsaddr   custom_textr   copied_filesr   executed_commandsr   r   r   r   rO  copy_stringsr   r   r   r   rS  unicodeencodedecoderW  rX  rU  r  r  r  r  r  r   r  r   )r   rx   rw  r  r   alertrH  rc  r  
formatlistclass_filenametype_fdr  r  s                   r*   generate_reportszSoSReport.generate_reports  s    #11 	 NHd8,G *E%L)* D!1!123&& BJAiL,01Y<,?A BB -- (GU)+(,(,(8(8(:8(D(+F*&' (( ".. E	ArKQ-/WW\\$-BD EE JJw3	 : i&1j&1j&1


 (2 	"#FHe"'')//1w	:AAC 
%%brww||M<D0F% G	"  "77o-KK%%b)KK%%AJJ<ugWEGKK%%b)JJqM"s   &B"I	K$BKK$c                 <   | j                   D ]  \  }}	 |j                  d      rt        j                         }|j                  j                  d|       |j                          t        j                         }|j                  j                  d|       |j                  j                  d||z
         n| j                  j                  d|         y # t        $ r}|j                  t        v rp| j                  j                  d       | j                  j                  d|j                   d       | j                  j                  d       | j                  d	       | j!                  |d       Y d }~ld }~wt"        $ r | j!                  |d       Y w xY w)
Nr  postproc_startpostproc_endpostproc_timezSkipping postproc for plugin r   r   z" while post-processing plugin datar}   )r   
get_optionr   r  r   r  r  r   r   r  r  r  r  r   r  r   r{  r   r#  s         r*   r  zSoSReport.postproc  sF   "11 	<NHd<??:.$LLNEMM++,<eDMMO",,.CMM++NC@MM++OS5[IKK$$7zBD	<  <77o-KK%%b)KK%%AJJ<'IJLKK%%b)JJqM%%h
;; <%%h
;<s   B?C	FBE99FFc                 F   |sy	 d}t        j                  |      }t        |d      5 }	 |j                  |      }|sn|j	                  |       &	 d d d        |j                         S # 1 sw Y   xY w# t
        $ r" | j                          Y j                         S w xY w)NFi   rb)hashlibrR  openreadr  r   r{  	hexdigest)r   rU  	hash_name	hash_sizedigest
archive_fphashdatas          r*   _create_checksumzSoSReport._create_checksum  s    
	$I[[+Fgt$ ,
)y9H#MM(+	  	, !!, ,  	$!!#!!	$s(   #A5 (A)A5 )A2.A5 5B B c                     t        |dz   |z   dd      5 }|r|j                  |dz          d d d        y # 1 sw Y   y xY w)Nr  wrh  )encodingr   )r  rW  )r   rU  r  checksumfps        r*   _write_checksumzSoSReport._write_checksum  sA    'C-)+S7C 	*rD)	* 	* 	*s   5>c           
      h   d }d }d }| j                          d}| j                  j                  r	 | j                  | j                  | j
                  | j                  | j                  d}t        d|      }|j                  | j                  j                                |j                         \  }}d}| j                          | j                  /| j                  j!                  | j                  j"                         | j%                          |rt&        j(                  j+                  | j                  | j                  j,                        }	j/                  t&        j(                  j+                  |	dd      d       |j/                  t&        j(                  j+                  |	dd	      d	       |j/                  t&        j(                  j+                  |	d
d      d       | j                  j0                  r| j3                          | j                  j4                  raddlm ddlm}
  |
| j                        }t?        d |jA                  d      D              | jB                  d<    t?        | jB                  jE                                     }| jF                  jI                  d|        tK        | jB                  jM                         d d      d d }dj+                  fd|D              }| jF                  jI                  d|        | jF                  jI                  d       | jF                  jI                  d       | jF                  jI                  d       | jF                  jI                  d       | j                  jN                  st'        jP                  d      }| j                  j0                  st        t        d             	 |r| j                  jS                         | j                  jU                  | j                  j"                        }t'        jP                  |       n| j                  jb                  s| j                  jd                  r| jF                  jg                  d!       | j                  j                         }t&        j(                  ji                  |      }|rjk                  |      }	 t&        j(                  j+                  | j
                  |      }t'        jl                  ||       |}d }| j                  jN                  s2|st        d#       nB	 | j                  jo                         }| jq                  ||      }	 | js                  |||       t&        j(                  ji                  |      }|r!jk                  |ju                  d&d'            }t&        j(                  j+                  | j
                  |      }t'        jv                  |      }|d(z   |z   }|d(z   |z   }	 t'        jl                  ||       |}	 t'        jl                  ||       | j                  jy                  |||||+       n| j                  jy                  ||||+       | j                  jz                  s,| j                  j|                  s| j                  j~                  rt| j                  jN                  sA	 | j                  j                  |       | jF                  jI                  t        d,             nd.}| jF                  j                  |       t        j                          | j                  r| j                  j                          | j                  r>t&        j(                  j                  | j                        rt        | j                         y# t        $ r"}t        t        d|              Y d }~(d }~ww xY w# tV        $ r}t        d       t        t        d|jX                   d| j                  j                                       t        d       |jZ                  t\        v r| j_                  d        Y d }~Cd }~wt        $ r/ | j                  j`                  r Y t'        jP                  |       yw xY w# t'        jP                  |       w xY w# tV        $ r t        t        d"|              Y yw xY w# t        $ r t        t        d$             Y yw xY w# tV        $ r t        t        d%|              Y w xY w# tV        $ r t        t        d)|              Y yw xY w# tV        $ r t        t        d*|              Y >w xY w# t        $ r)}| jF                  j                  d-|        Y d }~yd }~ww xY w)/NF)r{   rL  sys_tmpr  r   T)in_placehook_commonsz#ERROR: Unable to obfuscate report: rZ  r~  )
short_namer  r[  zmanifest.jsonr   )get_human_readable)Pathc              3   P   K   | ]  }|j                         j                     y wrQ  )lstatst_size)r   rH  s     r*   r   z'SoSReport.final_work.<locals>.<genexpr>5  s#      ?I*+AGGI%%?Is   $&z**/*sos_logs_reportszNEstimated disk space requirement for whole uncompressed sos report directory: c                     | d   S )Nr}   r   )xs    r*   <lambda>z&SoSReport.final_work.<locals>.<lambda><  s
    ad r,   )keyreverse   z,  c              3   B   K   | ]  \  }}| d  |d         yw)z: r   )	precisionNr   )r   r   vr  s      r*   r   z'SoSReport.final_work.<locals>.<genexpr>=  s1       8$(Aq $%#R(:1(J'K L  8s   zFive biggest plugins:  r   z>Please note the estimation is relevant to the current options.zBe aware that the real disk space requirements might be different. A rule of thumb is to reserve at least double the estimation.?   zCreating compressed archive...r   z while finalizing archive r}   zQ
Unable to encrypt when using --build. Encryption is only available for archives.zError moving directory: z Creating archive tarball failed.z:Error generating archive checksum after archive creation.
z!Error writing checksum for file: z.tarz-obfuscated.tarr  zError moving archive file: zError moving checksum file: )rR   zUploaded archive successfullyzUpload attempt failed: zEUnable to upload archive when using --build as no archive is created.)Ggenerate_manifest_tag_summaryr   r;   r{   rL  r  r   r   set_target_pathrU  get_archive_pathexecuter   r   r   r  add_final_manifest_datacompression_type_obfuscate_upload_passwordsr   r   r   _nameobfuscate_filerV  add_ui_log_to_stdoutrC   sos.utilitiesr  pathlibr  sumr   r   r  r  r   sortedr#   r8   umaskrename_archive_rootfinalizer  r  r  r  r   r   encrypt_passencrypt_keyr   basenameobfuscate_stringrenameget_preferred_hash_namer  r  r  statdisplay_resultsrf   rg   rn   upload_archiver   r   r   r   r   r   )r   rU  	directoryrR   do_cleanr  cleaner_pathsr   _dirr  tmpdir_path_sum
bigpluginsbp_out	old_umaskr  dir_name	final_dirr  r  base_archive
final_namearchivestatarchive_hash
final_hashr   r  s                              @r*   
final_workzSoSReport.final_work  s   	**, 99??F"kk"kk#||#yy $  %dN''(E(E(GH#*??#4 & 	==$LL001K1KL((*77<<T\\-?-?@D""277<<j)#L.7 # 9""277<<j(#K.6 # 8""T=/B* #  99??%%' 99""8$ t{{+K;> ?I/:/?/?/G?I <ID$$%78 &c$*B*B*I*I*K&LMDKK CCG&J K 8 8 > > @$2DBBD1FJZZ  8,6 8 8FKK6vh?@KKR KK 0 1KK G H KKR  yyI99??a89:$LL44W=,,//II..0 #yy%%)>)>## %0 1 557Iww''	2H"33H=GGLLx@			)Y/%	
 yy 89! $ C C EI#44WiHH
L(()XF  "ww//8#*#;#;(009JK$L  WW\\$,,E
 ggg.&}y8'#-	9
!IIgz2(G"LIIlJ7 ++GY,7( , L KK''H19 ( ; II		 4 499//99??GKK..w7KK$$Q'F%GH-!!#& 	$$&;;277==54;;k  Fa=cUCDEEF@  "b	a!AJJ<'A<<88:;= > ?b	77o-JJqM 99??#
 #  a29+>?@  ! !! 2 3 4 !  L!?yIJKL*  !!9'CDE !$  L!:<.IJKL ! GKK%%(?u&EFFGs   B^8 A_& Ac <,c( )d d2 'e ?e? 8	_#__#&	b%/A5a*$b( *#b%b( $b%%b( (b? c%$c%(dd d/.d/2 ee e<;e<?	f1f,,f1c                 f    | j                   s%| j                  j                  t        d             yy)Nzno valid plugins were enabledFT)r   r   r   r   r   s    r*   verify_pluginszSoSReport.verify_plugins  s)    ""KKa ?@Ar,   c                    | j                   j                  d| j                         | j                   j                  d| j                  r| j                  j                  nd       | j                   j                  d| j                  j                         d}t        d      rMt        dt        j                                }|d   d	k(  r%|d
   j                         d	   j                  d      }| j                   j                  d       | j                   j                  j                  d|       | j                   j                  j                  dt        j                   d	             | j                   j                  d       | j"                  j%                         D ]+  \  }}| j                   j"                  j                  ||       - | j                   j                  d| j                  j&                         | j                   j                  d| j                  j(                         | j                   j                  d       y)zgAdd 'global' data to the manifest, that is any information that is
        not plugin-specific
        r   r^   unsetra   r@  ionicez
ionice -p r  r   r  r  priorityio_classnicenessr   enabled_pluginsdisabled_pluginsr  N)r   r  r   r^   r   add_listr   ra   r   r
   r   getpidr  rC  r   r  nicer   r#   rE   rV   )r   	_io_class_ior  r   s        r*   add_manifest_datazSoSReport.add_manifest_data  s    	  DLL9  t{{4;;+;+;!(	*
DII,>,>?	"(:biik])CDC8}!M//1!4::3?	"":.))*i@))*bggajA""9-,,,,. 	9JCNN"",,S%8	9 14993K3KL 2DII4J4JK""9-r,   c           	      \   dfd	}i | j                   j                  D ]N  }|j                  D ]
  } ||        |j                  D ]  } ||d        |j                  D ]
  } ||        P | j                   j                  dt        t        j                                            y)ac  Add 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]}`.
        c                     | d   D ]]  }| |   r|s	 |   }|j                  t        | |   t              r| |   n| |   g       t	        t        t        |                  |<   _ y # t         $ r g }Y ]w xY w)Ntags)r  r   r  r
  r  r   )entr  tagr   tag_summarys       r*   compile_tagsz=SoSReport.generate_manifest_tag_summary.<locals>.compile_tags  s    6{ 
;3xs&s+D  *3s8T :CHS
 $*$s4y/#:C 
;
   Ds   A((A65A6files_copiedr  N)filepath)	r   r  commandsfilescollectionsr  dictr  r#   )r   r  r  rc  _file
collectionr  s         @r*   r  z'SoSReport.generate_manifest_tag_summary  s    	; NN** 	)D}} "S!" 4UN34".. )
Z()	) 	  !%f[->->-@&A!B	Dr,   c           	         | j                   j                  dt         ddj                  | j                         d       | j
                  j                  j                         }dt         d| j
                  j                   ddj                  |       d}| j                   j                  |       | j                   j                  dt         ddj                  | j                  j                                       y )	N[z:setup] executing 'sos r   r   z:setup] using 'z' preset defaults (r|   z:setup] effective options now: )	r   r   __name__r   rz   r^   r   r  r   )r   preset_argsr   s      r*   _merge_preset_optionszSoSReport._merge_preset_options	  s    1XJ '!!$$,,!7 8; 	< kk&&..08*ODKK,<,<+= >HH[)*!- 	1XJ&EHHTYY%6%6%89:< 	=r,   c                 J   	 | j                   j                  | j                                | j                          | j	                          | j                          | j                          | j                          | j                          | j                  j                  r| j                          t        | j                  j                  r| j                          t        | j                  j                  r| j                          t        | j                  j                  r+| j                  | j                  j                         t        | j                  j                  r+| j                  | j                  j                         t        | j!                         st        | j#                          | j%                          | j'                          | j)                          | j+                          | j                  j,                  s| j/                          | j                  j0                  s| j3                          | j                  j4                  s| j7                          n| j8                  j;                  d       | j=                          | j?                         S # t@        $ rC | j                  jB                  r tE        jF                  dd       dk(  s| jI                          Y ntJ        $ r? | j8                  jM                  d       | jI                          | jO                  d       Y n]t        $ rR}tE        jF                  dd       dk(  s| jI                          tQ        jR                  |jT                         Y d }~nd }~ww xY w| jO                  d       y)Nz)Skipping postprocessing of collected dataSOS_TEST_LOGSkeepz
Exiting on user cancelr   r}   F)+r{   set_commonsrO  r  r  r  r  r  r  r   rL   
SystemExitrN   rM   rt   ru   r  r  r  r  r  r3  rY   r^  rX   rx  rZ   r  r  r   r)  r  r  r   r   getenvcleanupr  r   r   r^  exitcoder  s     r*   r  zSoSReport.execute  s}   8	KK##D$4$4$67!!#&&( ++-$$&yy%%!!#  yy&&""$  yy%%!!#  yy##		 4 45  yy##		 4 45  &&(  JJLLLN""$JJLLLN99((%%'99&&%%'99((  !LMLLN??$$ 	yy99_d3v=  	KK89LLNJJsO 	99_d3v=HHQVV	
 	

1s'   J"J% %A	N0AN6N>ANNrQ  )NN)r@  )r   r   )Jr  
__module____qualname____doc__r>   root_requiredr   arg_defaultsr   classmethodr   r   r   r   r   r   r   r   r   r   r  r  r  r  r   rO  rS  rW  r   r   staticmethodr]  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rL   rN   rM   rt   ru   r  rv  r  r  r)  r3  r.  r;  rN  r^  rx  r  r  r  r  r  r  r  r  r  __classcell__)r   s   @r*   r5   r5   K   sL    <DM>e>E> 	> 	2	>
 	&> 	> 	V> 	U> 	> 	2> 	2> 	r> 	5> 	> 	>  	"!>" 	#>$ 	B%>& 	'>( 	B)>* 	+>, 	->. 	/>0 	1>2 	B3>4 	5>6 	67>8 	9>: 	b;>< 	=>> 	d?>@ 	UA>B 	uC>D 	uE>F 	UG>H 	I>J 	K>L 	&M>N 	/O>P 	Q>R 	BS>T 	U>V 	%W>X 	Y>Z 	R[>\ 	%]>^ 	d_>` 	Da>b 	tc>d 	te>f 	g>h !&!"   $ $#'{>L@%%N KH KHZ 4 4lA	
>,.

>	(0
d, 
(2
$
'  
7
KK5;
;
;M^)9&v=
6G,R,,!0:(! A29>40/b5n45"n<0""*M^.2D@==r,   r5   )Fr   )3r^  rj  r   r  r   r  rm  r   r   concurrent.futuresr   r   r=  shutilr   sos.report.pluginsr  r  r   r   r	   r
   r   r   r   r   r   r   sos.componentr   sos.policiessos.report.reportingr   r   r   r   r   r   r   r   r   r   sos.cleanerr   ENOSPCEROFSr  r+   r0   r   r5   r   r,   r*   <module>r     s      	    
   1 B  * * *   & : : : # <<-$> +J Jr,   