3 ܓi@@s`ddlZddlZddlZddlZddlZddlZddlZddlmZddlZddl m Z ddl m Z ddl mZddlZddlmZmZmZmZmZmZmZmZddlmZddlmZdd lmZddlZdd l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd l+m,Z,dd l-m.Z.ej/ej0fZ1dddZ2ddZ3dddgZ4ddddddhZ5GdddeZ6dS)N)datetime)ThreadPoolExecutor) TimeoutError)rmtree)ImporterHelperSoSTimeoutErrorboldsos_get_command_outputTIMEOUT_DEFAULTlistdir is_executablescrub_url_credential)_sos) __version__) SoSComponent) ReportSectionCommand CopiedFile CreatedFileAlertNotePlainTextReport JSONReport HTMLReport) SoSCleaner) SoSUploadF, cCsg}|}|rt|d}nd}xB|D]:}t|t|t|dkrR|j||}|||}q$W|t| d|kr|dt| }|j||S)N H)lenappend)Z first_lineitemsindentseplineslinenewlineitemr*/usr/lib/python3.6/__init__.py _format_list.s   r,cCstj|ddS)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)rZstrptime)Zdater*r*r+ _format_since@sr-autoalwaysZneverZ http_proxyZ https_proxyZ HTTP_PROXYZ HTTPS_PROXYZNO_PROXYZ ALL_PROXYc@seZdZdZdZdZdddddddddgggdddgdgdgddddd dd gggddddddgdeegdddgdddddddddddddddddd d ?Zfd dZe ddZ e ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zdd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zed7d8Zdd9d:Z d;d<Z!d=d>Z"d?d@Z#dAdBZ$dCdDZ%dEdFZ&ddHdIZ'dJdKZ(dLdMZ)dNdOZ*dPdQZ+dRdSZ,dTdUZ-dVdWZ.dXdYZ/dZd[Z0d\d]Z1d^d_Z2dd`daZ3dbdcZ4dddeZ5dfdgZ6dhdiZ7djdkZ8dldmZ9dndoZ:dpdqZ;drdsZdxdyZ?dzd{Z@d|d}ZAd~dZBddZCddZDddZEddZFddZGddZHZIS) 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 archiveTFrr.dNz /etc/sos/cleaner/default_mapping obfuscate)? alloptionsall_logsbuildcase_idchrootcleancontainer_runtimekeep_binary_filesdescdomainsdisable_parsersskip_cleaning_filesZdry_run estimate_only experimentalenable_plugins journal_sizekeywords keyword_fileplugoptslabel list_plugins list_presets list_profileslog_sizeZ low_prioritymap_file skip_commands skip_files skip_plugins namespaces no_report no_env_vars no_postproc no_updatenote only_pluginspresetplugin_timeout cmd_timeoutprofilessinceverifyallow_system_changes usernamesupload upload_urlZupload_directoryZ upload_userZ upload_passZ upload_methodZupload_no_ssl_verifyZupload_protocolupload_s3_endpointZupload_s3_regionZupload_s3_bucketZupload_s3_access_keyZupload_s3_secret_keyZupload_s3_object_prefixZ upload_target add_preset del_presettreat_certificatescstj|||g|_g|_g|_t|_||_d|_i|_ |j |j |j j |_|jjjd|_|jd}|j j|_|jjrd}n|j jr|jtjkrd}|jjd|jd|d|jjtkr|jjd |jjtj|jj |j!d |j"|j#|j$dS) N/reportdefaultcmdlinepolicyzset sysroot to 'z' ()zinvalid chroot mode: )%super__init__loaded_pluginsskipped_plugins all_optionsdefault_env_varsenv_varsZ_argssysrootestimated_plugsizes print_header _set_debugriZis_rootZ_is_rootmanifestZ components add_section report_md_set_directoriesoptsZ in_containerosr%soslogdebugr8 chroot_modeserrorloggingshutdown tempfile_utilr9_exit_check_container_runtime_get_namespaces_get_hardware_devices)selfparserargsrhmsg) __class__r*r+rms8     zSoSReport.__init__c Cs|jdd}|jddddddd |jd dd dd d |jd dddtdd|jdddddd |jddddd|jddddddd |jdddd |jd!d"tdd#d$d%|jd&dd'd(|jd)dd*d(|jd+dd,dd-d |jd.d/d0d1td2gd3|jd4td5d6d7d8|jd9d:d;d0dd?dd@dAd|jdBdCddDddEd |jdFddGd(|jdHddIddJd |jdKddLtdMdNdO|jdPdddQdR|jdSddTd |jdUdVd0dWtdXgd3|jdYddZdd[d |jd\dd]dd^d |jd_dd`ddadb|jdctdd#ddd%|jdedfd0dgtdhgd3|jdidtdjddk|jdlddmd |jdnddod |jdpdqdrd0dstgdtdO|jdugd0dvdwdx|jdygd0dzd{dx|jd|dd}dd~d |jdddddd |jdddddR|jdddd |jdddd |jdddd |jdddd |jdddddgdd|jddddd|jdddd |jdddd |jdddd |jdddd |jdddd |jdddd |jdddddddgdd|j}|jdtddd|jdtddd|jdd}|jdddddddd|jddgd0dd|jdd0gddd|jddd0gddd|jdd0gddd|jdddddč|jdddddd|jddddd̍|jddddddx|jddgd0dd|jdddddgdddٍdS)NzReport Optionsz.These options control how report collects dataz-az --alloptions store_truer4Fz%enable all options for loaded plugins)actiondestrghelpz --all-logsr5z-collect all available logs regardless of sizez--sinceZstorer[zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])rrrgtyperz--buildr6z;preserve the temporary directory and do not package resultsz --case-idr7zspecify case identifier)rrrz-cz--chrootr8r.zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)rgrz--descz --descriptionrzDescription for a new preset)rrrgrz --dry-runz#Run plugins but do not collect data)rrz--estimate-onlyzzApproximate disk space requirements for a real sos run; disables --clean and --collect, sets --threads=1 and --no-postprocz--experimentalrAzenable experimental pluginsz-ez--enable-pluginsextendrBzenable these plugins)rrrrrgz--journal-sizer1rCz+limit the size of collected journals in MiB)rrgrrz-kz--plugin-optionz --plugoptsrFz7plugin options in plugname.option=value format (see -l)z--labelz--namerGz"specify an additional report labelz-lz--list-pluginsrHz)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrJzBdisplay a list of available profiles and plugins that they includez --log-sizerKr2z6limit the size of collected logs (not journals) in MiB)rrrrgrz--low-priorityz(generate report with low system priority)rrgrz --namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrOzdisable these pluginsz --no-reportrQz disable plaintext/HTML reportingz --no-env-varsrRz$Do not collect environment variablesz --no-postprocrSzDisable all post-processing)rgrrrz--notezBehaviour notes for new presetz-oz--only-pluginsrVzenable these plugins onlyz--presetzA preset identifier)rrrrgz--plugin-timeoutzset a timeout for all pluginsz --cmd-timeoutz%set a command timeout for all pluginsz-pz --profilez --profilesrZz)enable plugins used by the given profilesz--skip-commandsrMzdo not execute these commands)rgrrrz --skip-filesrNzdo 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)rgchoicesrz--upload-no-ssl-verifyz'Disable SSL verification for upload url)rgrrz--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-keyzAccess key for the S3 bucketz--upload-s3-secret-keyzSecret key for the S3 bucketz--upload-s3-object-prefixzPrefix for the S3 object/keyz--upload-protocolZhttpsZftpZsftpZs3z$Manually specify the upload protocolz --add-presetz#Add a new named command line preset)rrrz --del-presetz$Delete the named command line presetzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz --cleanerz--maskr9zObfuscate sensitive information)rrgrrz --domainsr=z$Additional domain names to obfuscatez--disable-parsersr>zCDisable specific parsers, so that those elements are not obfuscated)rrgrrz--skip-cleaning-filesz--skip-masking-filesr?zBList of files to skip/ignore during cleaning. Globs are supported.z --keywordsrDzList of keywords to obfuscatez--keyword-filerEz&Provide a file a keywords to obfuscate)rgrrz --no-updaterTz%Do not update the default cleaner mapz --map-filerLz /etc/sos/cleaner/default_mappingz;Provide a previously generated mapping file for obfuscation)rrgrz--keep-binary-filesr;zGKeep unprocessable binary files in the archive instead of removing themz --usernamesr^zList of usernames to obfuscatez--treat-certificatesr3keepremoverdzHow to treat the certificate files [.csr .crt .pem]. Defaults to "obfuscate" after convert the file to text. "Key" certificate files are always removed.)rgrrr)Zadd_argument_group add_argumentr-strintZadd_mutually_exclusive_group)clsrZ report_grpZ preset_grpZ cleaner_grpr*r*r+add_parser_optionssd                            zSoSReport.add_parser_optionscCs|jd|jd|jd|jd|jdd}|jd|jd|jd d}|jd td d td |jdtdddddd}d}x.|jD]"\}}|jd|d|ddqW|j|dS)NzSoS 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.zHow 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.aFPlugins 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.zSee Alsoz5For information on available options for report, see zsos report --helpz and zman sos-reportzThe following zsos 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)zreport.pluginszreport.plugins.$pluginZpoliciesr z<36F)r()Z set_titleZadd_textrxrr#)rsectionZpsecZssecZ help_linesZhelplnlnvaluer*r*r+ display_helps.   zSoSReport.display_helpcCs$|jjdtdtdddS)N zsos report (version rj)ui_loginfo_r)rr*r*r+ruszSoSReport.print_headercCs.|j|jd|j|j|jd|_dS)N)blockZfibre)ZstoragenetworkZnamespaced_networkZfstype)_get_block_devs_get_fibre_devs_get_network_devs_get_network_namespace_devices_get_devices_by_fstypedevices)rr*r*r+rs  zSoSReport._get_hardware_devicescCs|jjdkr|jjj}|dkr6i|j_|jjdn|jjsXd|d}|jj|nt||jjjkrdj d d |jjjD}t d |d |n2|jj||jjd <|jjd|jjd j ddS)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). r.noneoffdiabledz0Disabled all container runtimes per user option.zVWARNING: No container runtimes are active, ignoring option to set default runtime to 'z' z, css|]}|dkr|VqdS)rgNr*).0pr*r*r+ sz5SoSReport._check_container_runtime..zCannot use container runtime 'z1': no such runtime detected. Available runtimes: rgz"Set default container runtime to ''N)rrr) r{r:lowerriZruntimesr}rwarningkeysjoin Exceptionname)rZcrunrZvalidr*r*r+rs   z"SoSReport._check_container_runtimecCsyLg}ddddg}x6|D].}tjjd|r|jtjd|dqW|Stk r~}z|jjd|gSd}~XnXdS) 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. Zfc_hostZ fc_transportZfc_remote_portsZ fc_vportsz /sys/class/z/*z!Could not get fibre device list: N)r|pathisdirrglobrr}r)rZdevsZdevdirsZdevdirerrr*r*r+rs zSoSReport._get_fibre_devscsyddtjdD}td}g|ddkrbx2|djD]"}|jdjdd }j|qsz-SoSReport._get_block_devs..z /sys/blockzlosetup --all --noheadingsstatusroutput:rcs"g|]}|jdr|kr|qS)Zloop) startswith)rdev)real_loop_devicesr*r+r"s z!Could not get block device list: N) r|r r splitlinessplitreplacer"listsetrr}r)rZ device_listZ loop_devicesZloop_devZ loop_deviceZghost_loop_devsZdev_listrr*)rr+rs zSoSReport._get_block_devscCsd|ji|_dS)Nr)_get_network_namespacesrP)rr*r*r+r+szSoSReport._get_namespacescCsggggd}yPtd|jjdr.|j|j|ds\|jjd|j|j|j|d<Wn4t k r}z|jj d|WYdd}~XnX|S) aHelper to encapsulate network devices probed by sos. Rather than probing lists of distinct device types like we do for storage, we can do some introspection of device enumeration where a single interface may have multiple device types. E.G an 'ethernet' device could also be a bond, and that is pertinent information for device iteration. :returns: A collection of enumerated devices sorted by device type :rtype: ``dict`` with keys being device types )ethernetbridgeZteambondZnmcli)rsrzZNetwork devices not enumerated by nmcli. Will attempt to manually compile list of devices.rz%Could not enumerate network devices: N) r r{rsupdate_get_nmcli_devsr}r~ _get_eth_devs_get_bridge_devsrr)r_devsrr*r*r+r0s $zSoSReport._get_network_devscCs.i}x$|jdD]}d|j|i||<qW|S)zqEnumerate the network devices that exist within each network namespace that exists on the system rr)rPr)rZ_nmdevsZnmspr*r*r+rOsz(SoSReport._get_network_namespace_devicescCsi}ytd}|ddkrtxX|djddD]@}|j\}}||krT|g||<n||j||dj|q0Wtt|d|d<Wn4tk r}z|jjd|WYdd}~XnX|S) zUse nmcli, if available, to enumerate network devices. From this output, manually grok together lists of devices. znmcli --fields DEVICE,TYPE devrrrrkNrzCould not parse nmcli devices: ) r rrr"rrrr}r~)rrZ_ndevsrZdnameZdtyperr*r*r+rZs   $zSoSReport._get_nmcli_devscs dgg}|sbyfddtddD}Wqtk r^}z|jjd|WYdd}~XqXnyLd|d}t|}|d d krx&|d jD]}|kr|j|qWWn:tk r}z|jjd |d |WYdd}~XnX|dd|Ddd|DdS)a8Enumerate a list of ethernet network devices so that plugins can reliably iterate over the same set of devices without doing piecemeal discovery. These devices are used by `add_device_cmd()` when `devices` includes "ethernet" or "network". :param namespace: Inspect this existing network namespace, if provided :type namespace: ``str`` :returns: All valid ethernet devices found, potentially within a given namespace :rtype: ``list`` Zbonding_masterscsg|]}|kr|qSr*r*)rr) filt_devsr*r+rsz+SoSReport._get_eth_devs..z/sys/class/netNz.Failed to manually determine network devices: zip netns exec z ls /sys/class/netrrrz'Could not determine network namespace 'z ' devices: cSsg|]}|jdr|qS)r)r)rZbdr*r*r+rscSsg|]}|jdr|qS)tun)r)rZtdr*r*r+rs)rrr)r rr}rr rr")r namespaceZ _eth_devsrZ_nscmdZ_nsoutZ_nsethr*)rr+rns*   $ zSoSReport._get_eth_devsc Csg}ytddd}Wn4tk rH}z|jjd|WYdd}~XnX|ddkrxn|djd dD]V}y|j|jdWqltk r}z|jjd |d |WYdd}~XqlXqlW|S) 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: Nrrrrkz"Could not parse device from line 'z': )r rr}rrr"rr)rZ_bridgesZ_boutrZ_bliner*r*r+rs$ (zSoSReport._get_bridge_devscCs`g}td}|ddkr\xB|djD]2}|js&|ddjrDq&|j|jddq&W|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. zip netnsrrrNrkr)r risspacer" partition)rZout_nsZip_netnsr'r*r*r+rs z!SoSReport._get_network_namespacescCsi}td}|ddkr|Sxr|djD]b}|jj}t|dkrR|jddd|dkrfd|d<|j|dg||dj|dq*W|S) Nzlsblk -snrpo FSTYPE,NAMErrrrkunknownZextZext4)r rstriprr!insert setdefaultr")rZ _dev_fstypesrr'helperr*r*r+rs     z SoSReport._get_devices_by_fstypec Cs4|j|j|j|j|j|j|j|jj|j|j |j d S)N) cmddirlogdirrptdirtmpdirr}rirs verbosityZ cmdlineoptsrrP) rrrrr}rirsr{rrrP)rr*r*r+ get_commonsszSoSReport.get_commonscCs |jjS)N)rnew)rr*r*r+ get_temp_fileszSoSReport.get_temp_filecCs4|jj|jd|jj|jd|jj|jddS)Ni)archivemakedirsrrr)rr*r*r+_make_archive_pathsszSoSReport._make_archive_pathscCsd|_d|_d|_dS)NZ sos_commandssos_logs sos_reports)rrr)rr*r*r+rzszSoSReport._set_directoriescCs"|jjr|jt_d|_nd|_dS)NTF)r{r~ _exceptionsys excepthook raise_plugins)rr*r*r+rvszSoSReport._set_debugcCsNttdstjj r&tj|||n$tj|||dtjdtt j dS)z* Wrap exception in debugger if not in tty Zps1)limitfileN) hasattrrstderrisatty__excepthook__ tracebackprint_exceptionstdoutprintpdbZpm)etypeZeval_Zetracer*r*r+rs   zSoSReport._exceptioncCsV|js |jr>tj\}}}tj|||tjdttj ||rR|rR|j ||dS)N)r) rZ exit_processrexc_inforrrrrZ post_mortem_log_plugin_exception)rplugnamefuncrvaltbr*r*r+handle_exceptions  zSoSReport.handle_exceptioncCsTt|ddr(|jj|jtjjdddt|ddrP|jj|jtjjddddS)N sos_log_filerzsos.log)rsos_ui_log_filezui.log)getattrradd_filerr|rrr)rr*r*r+ _add_sos_logss     zSoSReport._add_sos_logscsRjj}jjsdSt|ds"dS|r:j|j r:dStfdd|jDS)NTrZFc3s|]}|jjkVqdS)N)r{rZ)rr)rr*r+r'sz+SoSReport._is_in_profile..)r{rVrZr_is_not_specifiedrany)r plugin_classrVr*)rr+_is_in_profiles zSoSReport._is_in_profilecCs ||jjkS)N)r{rO)r plugin_namer*r*r+ _is_skipped)szSoSReport._is_skippedcCs*||jj o(||jjko(||jjkS)N)rZ check_enabledr{rBrV)rr pluginClassr*r*r+ _is_inactive,s zSoSReport._is_inactivecCs*||jj o(||jjko(||jjkS)N)rZdefault_enabledr{rBrV)rrrr*r*r+_is_not_default1s zSoSReport._is_not_defaultcCs|jjo||jjkS)N)r{rV)rrr*r*r+r 6szSoSReport._is_not_specifiedrcCs"|jj|j||j|fdS)N)ror"rr)rr reasonr*r*r+_skip:s zSoSReport._skipcCs |jj|j||jfdS)N)rnr"rr)rr r*r*r+_loadAszSoSReport._loadcCstjjj}ttjj}|j}g|_t|_t |j j}|j j }g}|j j r\|jtjjjt||}|j j}t|j j} x|D]} tjj| \} } yp|| |} | sw|j j| }|||j j ds|jjtd| d|j jdkr|j|tdw|jj| |j|}|s2|j|tdw|j| rP|j|tdw|j| |rp|j|tdw|j| |r|j|td wt |d r|jj!|j| o|}|j"| r|r|j|td wx$|jD]}|| kr| j#|qW|j$|Wqt%k rT}z*|jjtd| d ||j&WYdd}~XqXqWt | dkr|jj'td dj(| |j)|j*ddS)N)rAzplugin z does not validate, skippingrzdoes not validateZexcludedZskippedZinactiveZoptionalrZz not specifiedz does not install, skipping: z)Unknown or inactive profile(s) provided: z, rk)+sosrfplugins import_pluginrZ get_modules plugin_namesrrZr!r{riZvalid_subclassesrAr"ZExperimentalPlugintuplevalidate_pluginrr|rsplitextZ match_pluginr}rrrrr rrrrrr rrrrrrrJr)rrrrZusing_profilesZpolicy_classesZ extra_classesZvalid_plugin_classesrZremaining_profilesplugZplugbase__Zplugin_classesr Z in_profileZdefault_profileier*r*r+ load_pluginsGst              zSoSReport.load_pluginscCsD|jjr@x6|jD],\}}x"|jjD]}t|jkr$d|_q$WqWdS)NT)r{r4rnoptionsvaluesboolZval_typer)rrroptr*r*r+_set_all_optionss  zSoSReport._set_all_optionsc$Cs$|jjr i}x|jjD]}y|jd\}}Wntk rHd}YnXt|tr|j}|dkrjd}n0|dkrxd }n"y t|}Wntk rYnXy|jd\}}Wntk r|}d}YnXy ||Wntk ri||<YnX||||<qWx|j D]\}}||krx||D]}||j kr^|j j d|d|d|j dy:|j |j||||j jd|d|j |Wn:tk r}z|j j ||j dWYdd}~XnXq*W||=qWx"|D]}|j j d|dqW|jr |j j ddS)N=TonenableenabledtrueyesrdisabledisabledfalsenoF.zno such option "z" for plugin (rjrkzSet z plugin option to zCWARNING: unable to set option for disabled or non-existing plugin (z).r)r(r)r*r+r,)rr-r.r/r0)r{rFr ValueError isinstancerrrKeyErrorrnr"r}rrZ set_valuer~rr)rr{r%rargrrrr*r*r+ _set_tunablessZ          "   zSoSReport._set_tunablescCsddl}xR|j|jj|jjD]:}|jdd}||jkr|jjd|d|j dqWx.|jj D]"}||jkrf|jj d|dqfWdS)Nrr1za non-existing plugin (z$) was specified in the command line.rkz'Requested to skip non-existing plugin 'z'.) itertoolschainr{rVrBrrr}fatalrrOr)rr7pluginrr*r*r+_check_for_unknown_pluginss   z$SoSReport._check_for_unknown_pluginscCs:x4|jD]*\}}x |jD]}|jj|j|qWqWdS)N)rnr"rpr")rrr:r%r*r*r+_set_plugin_optionss zSoSReport._set_plugin_optionscCsd}g}|jjdkr2|d|jjdg7}d|j_|jjsL|dg7}d|j_|jjsf|dg7}d|j_|jjr|dg7}d |j_|jjr|d g7}d |j_|r|d d j|7}n|d 7}|d7}|S)Nz Estimate-only mode enabledrkz --threads=z overriden to 1z--build enabledTz--no-postproc enabledz--clean disabledFz--upload* options disabledz", which overrides some options: z r1z )r{threadsr6rSr9r_r)rrZext_msgr*r*r+_set_estimate_onlys,     zSoSReport._set_estimate_onlycCsd|jjd|jr:|jjdt|jdt|jdn|jjdt|jd|jjddS)Nrrz profiles, z pluginsz profiles)rrrnr!rZ)rr*r*r+_report_profiles_and_pluginss  (z&SoSReport._report_profiles_and_pluginsc Cs|j r$|j r$|jjtddS|jrz|jjtd|jjdxB|jD]&\}}|jjd|dd|jqNWn|jjtd|jjd|jr|jjtd|jjdx:|jD]0\}}}|jjd|dd|dd|jqW|jjd|jr|jjtd |jd d j }x|D]}||}|j }|j dkr|d krh|j j pdt }n|d kr|j jp~t }nt }|jdkr|j j }|jjd|jdd|dd|jq0W|jjd|jjtdx|jD]}|jdkr|j |jkrqt|j tr4|j dkr.d} nd} n|j } | dkrHd } |jjd|jd|jdd| dd|jqWn|jjtd|jjdt|j} | jtd| dd} x | D]} |jjd| qW|jdS)Nzno valid plugins foundz,The following plugins are currently enabled:rrz<30zNo plugin enabled.z-The following plugins are currently disabled:z<14z4The following options are available for ALL plugins:rrkr cmd-timeoutpostprocz<25z<15z+The following plugin options are available:Tr(rr1z<40zNo plugin options available.z Profiles: )r$)rrAr@)rnror}r9rrrZget_descriptionrpZget_default_plugin_optsrr{rXr rYrrSr<rgr3r$r:rrZsortr,r?) rrrZ plugclassrZ _defaultsZ_optr%rZtmpoptrZr&r'r*r*r+rHsj $  *       ,     :   zSoSReport.list_pluginsc Cs|js|jjtddS|jjtd|jjddd}t|j}|jxr|D]j}g}x.|jD]$\}}||rf||jkrf|j |qfWt |d|dd}x|D]}|jjd |qWqVW|j dS) Nzno valid profiles foundz%The following profiles are available:rcSs t|dS)NrZ)r)cr*r*r+ _has_profasz*SoSReport.list_profiles.._has_profz<15T)r$r) rZr}r9rrrrrCrnr"r,r?) rrErZZprofilerrr:r&r'r*r*r+rJZs"    zSoSReport.list_profilescCs|jjs|jjtddS|jjtd|jjdx|jjjD]}|sPqF|jj|}|jjddd|j |jjddd|j |j r|jjddd|j |j j d kr|j j}d dd}t||d dd }x|D]}|jj|qW|jjdqFWdS) Nzno valid presets foundz$The following presets are available:rzname:z>14rz description:znote:rzoptions:T)r$r%)riZpresetsr}r9rrrr find_presetrr<rUr{rto_argsr,)rrWrZ options_strr&r'r*r*r+rIps(     zSoSReport.list_presetscCs|j}|j|r(|jjd|ddS|p2|jj}|p>|jj}y|j||||jdWn2tk r}z|jjd|dSd}~XnX|j j d}|j d||j |d d}|jj d |d d j |d dS)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 zA preset named 'z' already existsF)rr<rUr{zCould not add preset: Nz --add-presetrrzAdded preset 'z' with options rrT) rirFrrr{r<rUrbrrhindexrr)rrr<rUrir Z arg_indexrr*r*r+rbs      zSoSReport.add_presetcCs|j}|j|s(|jjd|ddSy|j|dWn6tk rn}z|jjt|ddSd}~XnX|jjd|dd S) zDelete a named command line preset. :param name: the name of the preset to delete :returns: True on success or False otherwise zPreset 'z ' not foundF)rrNzDeleted preset 'z' T)rirFrrrcrrr)rrrir r*r*r+rcs zSoSReport.del_presetcCs|jj}|jjr||j7}|jjr4|jj|np|td7}y t |WnVt k rv|jj d|j dYn.t k r}z|j d|WYdd}~XnXdS)Nz,Press ENTER to continue, or CTRL-C to quit. zExiting on user cancelrk)riZget_msgr{r@r>batchrrrinputKeyboardInterruptrrr)rrr r*r*r+rJs     zSoSReport.batchcCsrtj}d}|d}tjj|j|}|jj|d|d|d|jjd||jj |d|dd dS) Nz!caught exception in plugin methodz-plugin-errors.txtz "r1z()"zwriting traceback to ra)mode) r format_excr|rrrr}rr add_string)rr:methodZtracerZplugin_err_logZlogpathr*r*r+rs zSoSReport._log_plugin_exceptioncCs|jjy$|jjtd|j|jdStk r}zD|jt krnt dt d|j dt dnt d|WYdd}~XnNt k r}z2|jj d|jj dtj|jj |WYdd}~XnX|jddS)Nz Setting up archive ...rrz while setting up archivezError setting up archive: z) Unexpected exception setting up archive:rk)riZpre_workrrrZ setup_archiverOSErrorerrnofatal_fs_errorsrstrerrorrrr print_excr)rr r*r*r+preworks&     zSoSReport.preworkcCsr|jjtdxZ|jD]N\}}y|jjj||jt|jj|t j }|j j d||j |_ |j|j|jj|j|jjr|jt j }|j j d||j j d||Wqtk rtYqtk rH}zV|jtkr,|jjd|jjd|jd|jjd|jd|j|d WYdd}~Xqtk rh|j|d YqXqWdS) Nz Setting up plugins ...Z setup_startZ setup_endZ setup_timerrz while setting up pluginsrksetup)rrrrnryrrxZset_plugin_manifestrrnowrw add_fieldrZadd_default_collectionsrXrrrZ _env_varsr{r\Z setup_verifyrLrRrSrTrrUrrr)rrrstartendr r*r*r+rXs:     zSoSReport.setupcCs.g}|jdt|jjdj|dddS)zWFetch version information from all plugins and store in the report version filez sos report: rz version.txt)ZcontentrN)r"rrrPr)rZversionsr*r*r+version szSoSReport.versioncCs|jjtd|jjdd}g|_g|_x*|jD] }|d7}|jj||dfq4Wydg}t|jj }|j |j t |j}WdQRXx"|D]}|s|j jd|qW|jjdWn*tk r|jjdtjdYnXdS)Nz! Running plugins. Please wait ...rrrkzUnexpected plugin task result: z Exiting on user cancel )rrrpluglist running_plugsrnr"rr{r=map_collect_pluginrr}r~rLrr|r)rZ plugruncountrresultsexecutorresr*r*r+collects(    zSoSReport.collectc Cstd }y||j|ddd}|j|j|}|jp:d}tj}|jjd||j |dtj}|jjd||jjd||Wnt k rd|dd }|j j d |d |j j||jj|d|j|dddj|jd d |jjYnXWdQRX|jjr|jj} y0td| } t| djd|j|d<Wn$tk rd|j|d<YnXxTtj| D]F} tj j!| | } tj j"| rtj j#|  rt$| n tj%| qWd S)zaWraps the collect_plugin() method so we can apply a timeout against the plugin as a wholerkrNZ start_time)rZend_timeZrun_timezPlugin z timed outz rT)waitzdu -sB1 r)&rrnZsubmitcollect_pluginrrrYrwrZresultFuturesTimeoutErrorrrr}rr_rZset_timeout_hitrZ_threadsclearr{r@rZ get_tmp_dirr rrrtrr|r rrrislinkrunlink) rr:ZpoolZ_plugtrr[r\rrZdufr*r*r+ra,s@       " zSoSReport._collect_pluginc $Cs,y*|\}}|j|dd}|jj|Wntk r>dSXt|j}d|d|dd|dddjd d |jDd }|j|y|jy|jj |Wn(t k r|j j d |d YnXy|jj |Wn*t k r |j j d |dYnXd}t|jt |jjkrV|jrVdddddjdd |jDd }|j rn|j rnd}|r~|j|Wntk rYntk r}zT|jtkr|jjd|jd|jjd|jdtjd|j|dWYdd}~Xn"tk r&|j|dYnXdS)NrkFz Starting rez<5rz<15z [Running: css|] }|VqdS)Nr*)rrr*r*r+resz+SoSReport.collect_plugin..]zCould not remove z from plugin list, ignoring...z& from running plugin list, ignoring...rz Finishing plugins z<12css|] }|VqdS)Nr*)rrr*r*r+r~sz Finished running pluginsz z while collecting plugin dataz# Data collected still available at rre)rnr_r"rr!r ui_progressrgr^rr2r}r~rr{r=rrRrSrTrrrUrr|rr) rr:countrrZnumplugs status_linerr r*r*r+rg]sT 8 &  zSoSReport.collect_plugincCsT|jjdkr(|jj r(d|jd}n |d}|jjsPtjj|tjjdS)Nr Zr) r{rrJljustquietrrwriteflush)rrrr*r*r+rps   zSoSReport.ui_progresscCs@|js dSdjdddd|jDDd}|jj|ddS)NrcSs"g|]\}}|dt|qS)r')r )rrrr*r*r+rsz.SoSReport.collect_env_vars..cSs.g|]&}tjj|dk r|tjj|fqS)N)r|environget)rrr*r*r+rsZ environment)rrrrrP)renvr*r*r+collect_env_varsszSoSReport.collect_env_varscCst}x|jD]\}}t|d}x|jD]}|jt|q(W|jrT|jt|jx,|jD]"}|jt |dd|ddq\Wx>|j D]4}|jt |ddt j jd|jd|d d qWx0|jD]&\}}}|jt|t j jd|dqW|j|qWtd d ftd dftddff} x| D]\} } } yT|j} | |j}|jddj}| j|| j|jj| t j jd| dWnntk r}zP|jtkr|j j!d|j j!d|j"d| d|j j!d|j#dWYdd}~XnXq$WdS)N)rZsrcpathz..Zdstpath)rhrefcmdrrr)rZ return_coder}zsos.txttextzsos.jsonZJSONzsos.htmlZHTMLzutf-8rr)rrrz while writing z reportrk)$rrnrZalertsaddrZ custom_textrZ copied_filesrZexecuted_commandsrr|rrrZ copy_stringsrrrrrZunicodeencodedecoderwrxrrrRrSrTrrrUr)rrfrrrZalertrnr~rZ formatlistZclass_filenameZtype_fdrr r*r*r+generate_reportssN            zSoSReport.generate_reportscCsx|jD]\}}yh|jdrhtj}|jjd||jtj}|jjd||jjd||n|jjd|Wq t k r}zT|j t kr|j j d|j j d|jd|j j d|jd |j|dWYdd}~Xq tk r |j|dYq Xq WdS) NrAZpostproc_startZ postproc_endZ postproc_timezSkipping postproc for plugin rrz" while post-processing plugin datark)rnZ get_optionrrYrwrZrAr}rrRrSrTrrrUrrr)rrrr[r\r r*r*r+rAs*     zSoSReport.postproccCsv|sdSyHd}tj|}t|d&}x|j|}|s6P|j|q&WWdQRXWntk rl|jYnX|jS)NFirrbi)hashlibropenreadrrrZ hexdigest)rr hash_nameZ hash_sizeZdigestZ archive_fpZhashdatar*r*r+_create_checksums   zSoSReport._create_checksumc Cs8t|d|ddd}|r*|j|dWdQRXdS)Nr1wzutf-8)encodingr)rrw)rrrchecksumfpr*r*r+_write_checksumszSoSReport._write_checksumcRs:d}d}d}|jd}|jjryJ|j|j|j|j|jd}td|d}|j|j j |j \}}d}Wn4t k r}zt td|WYdd}~XnX|j|jdk r|j j|jj|j|r&tjj|j|j j} |jtjj| dd|jtjj| dd|jtjj| d d |jjr8|j|jjr d d lmd d lm} | |j} tdd| j dD|j!d<t|j!j"} |j#j$d| t%|j!j&dddddd} djfdd| D}|j#j$d||j#j$d|j#j$d|j#j$d|j#j$d|jj'stj(d}|jjsJt tdzy&|r`|j j)||j j*|jj}Wnt+k r}zLt dt td|j,d |j j t d|j-t.kr|j/d!WYdd}~Xn"t k r|jj0rdSXWdtj(|Xn|jj1s$|jj2r0|j#j3d"|j j }tjj4|}|rV|j5|}y$tjj|j|}tj6|||}Wn(t+k rt td#|dSXd}|jj's$|st d$q8y|jj7}|j8||}Wn"t k rt td%dSXy|j9|||Wn(t+k r<t td&|YnXtjj4|}|rb|j5|j:d'd(}tjj|j|}tj;|}|d)|}|d)|}ytj6|||}Wn(t+k rt td*|dSXytj6||Wn(t+k r t td+|YnX|jj<|||||d,n|jj<||||d,|jj=sV|jj>sV|jj?r|jj'syP|j|j|j|j|jd}t@|jA|jB|jCd||d-}|j |j#j$td.Wn6t k r}z|j#jDd/|WYdd}~XnXnd0}|j#jD|tEjF|jGr|jGj|jr6tjjH|jr6tI|jdS)1NF)rirsys_tmpr"rwT)in_place hook_commonsz#ERROR: Unable to obfuscate report: rzsos.logzui.logrz manifest.jsonr)get_human_readable)Pathcss|]}|jjVqdS)N)lstatst_size)rrnr*r*r+rEsz'SoSReport.final_work..z**/*Zsos_logs_reportszNEstimated disk space requirement for whole uncompressed sos report directory: cSs|dS)Nrkr*)xr*r*r+Ksz&SoSReport.final_work..)keyreversez, c3s(|] \}}|d|ddVqdS)z: r)Z precisionNr*)rrv)rr*r+rLszFive biggest plugins: rz>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.?zCreating compressed archive...rz while finalizing archive rkzQ Unable to encrypt when using --build. Encryption is only available for archives.zError moving directory: z Creating archive tarball failed.z:Error generating archive checksum after archive creation. z!Error writing checksum for file: z.tarz-obfuscated.tarr1zError moving archive file: zError moving checksum file: )rL)rrrhrrrzUploaded archive successfullyzUpload attempt failed: zEUnable to upload archive when using --build as no archive is created.)Jgenerate_manifest_tag_summaryr{r9rirrrwrZset_target_pathrZget_archive_pathexecuterrrr Zadd_final_manifest_dataZcompression_typeZ_obfuscate_upload_passwordsr|rr_nameZobfuscate_filervZadd_ui_log_to_stdoutr@ sos.utilitiesrZpathlibrsumrrtr#rrsortedr#r6umaskZrename_archive_rootfinalizerRrUrSrTrr~Z encrypt_passZ encrypt_keyrbasenameZobfuscate_stringrenameZget_preferred_hash_namerrrstatZdisplay_resultsr_r`rarrrrhrrrrrr)rrZ directoryrLZdo_cleanrZcleanerZ_pathsrZ_dirrZ tmpdir_pathZ_sumZ bigpluginsZbp_outZ old_umaskr Zdir_nameZ final_dirrrZ base_archiveZ final_nameZ archivestatZ archive_hashZ final_hashZuploaderrr*)rr+ final_work s   $                                         &   zSoSReport.final_workcCs|js|jjtddSdS)Nzno valid plugins were enabledFT)rnr}rr)rr*r*r+verify_pluginsszSoSReport.verify_pluginscCs|jjd|j|jjd|jr&|jjnd|jjd|jjd}tdr~t dt j }|dd kr~|d j d j d }|jjd |jjjd ||jjjdt jd |jjdx&|jjD]\}}|jjj||qW|jjd|jj|jjd|jj|jjddS)zgAdd 'global' data to the manifest, that is any information that is not plugin-specific rsrWZunsetrZrZionicez ionice -p rrrrpriorityZio_classZnicenessrZenabled_pluginsZdisabled_pluginsrN)ryrZrsrWrZadd_listr{rZr r r|getpidrrrxrnicerr#rBrO)rZ _io_class_iorrr*r*r+add_manifest_datas$   zSoSReport.add_manifest_datacsdfdd }ixZ|jjD]N}x|jD] }||q(Wx|jD]}||dq@Wx|jD] }||qZWqW|jjdttjdS)acAdd a section to the manifest that contains a dict summarizing the tags that were created and assigned during this report's creation. This summary dict can be used for easier inspection of tagged items by inspection/analyzer projects such as Red Hat Insights. The format of this dict is `{tag_name: [file_list]}`. filepathc sx|dD]v}|| s | r q y |}Wntk rDg}YnX|jt||tr`||n||gttt||<q WdS)NZtags)r4rr3rrr)Zentrtagr) tag_summaryr*r+ compile_tags s  "z=SoSReport.generate_manifest_tag_summary..compile_tagsZ files_copiedrN)r) ryrZcommandsfiles collectionsrZdictrr#)rrrr~Z_fileZ collectionr*)rr+rs     z'SoSReport.generate_manifest_tag_summarycCs|jjdtddj|jd|jjj}dtd|jjddj|d}|jj||jjdtddj|jjdS) N[z:setup] executing 'sos rrz:setup] using 'z' preset defaults (rjz:setup] effective options now: ) r}r__name__rrhrWr{rGr)rZ preset_argsrr*r*r+_merge_preset_options%s " " zSoSReport._merge_preset_optionscCs yB|jj|j|j|j|j|j|j|j|j j rX|j t |j j rl|j t |j j r|j t |j jr|j|j jt |j jr|j|j jt |jst |j|j|j|j|j|j js|j|j js |j|j js*|jjd|jn |jjd|j|jSt k r|j j!rbt"j#dddks||j$Yn|t%k r|jj&d|j$|j'dYnJt k r}z,t"j#dddks|j$t(j)|j*WYdd}~XnX|j'ddS) Nz*Starting post-processing of collected dataz*Skipping post-processing of collected dataZ SOS_TEST_LOGSrz Exiting on user cancelrIrkF)+riZ set_commonsrr!r&rr6r;r<r{rH SystemExitrJrIrbrcrrJrWrrXrerRr|rQrrSrrrAr]rrRr~r|getenvZcleanuprLrrrexitcode)rr r*r*r+r4sn         zSoSReport.execute)N)NN)r)rr)Jr __module__ __qualname____doc__r<Z root_requiredr Z arg_defaultsrm classmethodrrrurrrrrrrrrrrrrrrrzrv staticmethodrrr r rrrr rrr!r&r6r;r<r>r?rHrJrIrbrcrJrrWrXr]rerargrpr|rrArrrrrrrr __classcell__r*r*)rr+r0Rs ' X 7   2     O; I   17  7Z r0)Fr)7rrr|rSrrrrrconcurrent.futuresrrriZshutilrZsos.report.pluginsrrrrrr r r r r rrrZ sos.componentrZ sos.policiesZsos.report.reportingrrrrrrrrrrZ sos.cleanerrZ sos.uploadrZENOSPCZEROFSrTr,r-rrqr0r*r*r*r+ s6    (   0