a G%@iQ@@sVddlZddlZddlZddlZddlZddlZddlZddlmZddlZddl 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/ej0fZ1dddZ2ddZ3gdZ4hdZ5GdddeZ6dS)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}|D]:}t|t|t|dkrP|||}|||}q"|t| d|kr|dt| }|||S)N H)lenappend)Z first_lineitemsindentseplineslinenewlineitemr*7/usr/lib/python3.9/site-packages/sos/report/__init__.py _format_list.s  r,cCst|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)rstrptime)dater*r*r+ _format_since@sr/)autoalwaysnever>Z HTTP_PROXYZ HTTPS_PROXYZNO_PROXYZ https_proxyZ http_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 archiveTFrr0dN /etc/sos/cleaner/default_mapping obfuscate)? alloptionsall_logsbuildcase_idchrootcleancontainer_runtimekeep_binary_filesdescdomainsdisable_parsersskip_cleaning_filesdry_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_certificatescst|||g|_g|_g|_t|_||_d|_i|_ | | |j |_|jjd|_|d}|j j|_|jjrd}n|j r|jtjkrd}|jd|jd|d|jjtvr|jd |jjt|j |!d |"|#|$dS) N/reportdefaultcmdlinepolicyzset sysroot to 'z' ()zinvalid chroot mode: )%super__init__loaded_pluginsskipped_plugins all_optionsdefault_env_varsenv_vars_argssysrootestimated_plugsizes print_header _set_debugrnZis_rootZ_is_rootmanifest components add_section report_md_set_directoriesoptsZ in_containerosr%soslogdebugr< chroot_modeserrorloggingshutdown tempfile_utilr=_exit_check_container_runtime_get_namespaces_get_hardware_devices)selfparserargsrmmsg __class__r*r+rrs8     zSoSReport.__init__c Cs|dd}|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 |jddgddd|jddddd|jdddd |jdddd |jdddd |jdddd |jdddd |jdddd |jddgddd|}|jdtddd|jdtddd|dd}|jdddddddd|jddgd0dd|jdd0gddd|jddd0gddd|jdd0gddd|jddddd|jdddddd|jdddddȍ|jddddddx|jddgd0dd|jddgdѢdddԍdS)NzReport Optionsz.These options control how report collects dataz-az --alloptions store_truer8Fz%enable all options for loaded plugins)actiondestrlhelpz --all-logsr9z-collect all available logs regardless of sizez--sincestorer`zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])rrrltyperz--buildr:z;preserve the temporary directory and do not package resultsz --case-idr;zspecify case identifier)rrrz-cz--chrootr<r0zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)rlrz--descz --descriptionrzDescription for a new preset)rrrlrz --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--experimentalrFzenable experimental pluginsz-ez--enable-pluginsextendrGzenable these plugins)rrrrrlz--journal-sizer4rHz+limit the size of collected journals in MiB)rrlrrz-kz--plugin-optionz --plugoptsrKz7plugin options in plugname.option=value format (see -l)z--labelz--namerLz"specify an additional report labelz-lz--list-pluginsrMz)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrOzBdisplay a list of available profiles and plugins that they includez --log-sizerPr5z6limit the size of collected logs (not journals) in MiB)rrrrlrz--low-priorityz(generate report with low system priority)rrlrz --namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrTzdisable these pluginsz --no-reportrVz disable plaintext/HTML reportingz --no-env-varsrWz$Do not collect environment variablesz --no-postprocrXzDisable all post-processing)rlrrrz--notezBehaviour notes for new presetz-oz--only-pluginsr[zenable these plugins onlyz--presetzA preset identifier)rrrrlz--plugin-timeoutzset a timeout for all pluginsz --cmd-timeoutz%set a command timeout for all pluginsz-pz --profilez --profilesr_z)enable plugins used by the given profilesz--skip-commandsrRzdo not execute these commands)rlrrrz --skip-filesrSzdo not collect these filesz--verifyraz+perform data verification during collectionz--allow-system-changesrbzJRun 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)r0ZputZpostz HTTP method to use for uploading)rlchoicesrz--upload-no-ssl-verifyz'Disable SSL verification for upload url)rlrrz--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-protocol)r0httpsftpsftpZs3z$Manually specify the upload protocol --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--maskr=zObfuscate sensitive information)rrlrrz --domainsrAz$Additional domain names to obfuscatez--disable-parsersrBzCDisable specific parsers, so that those elements are not obfuscated)rrlrrz--skip-cleaning-filesz--skip-masking-filesrCzBList of files to skip/ignore during cleaning. Globs are supported.z --keywordsrIzList of keywords to obfuscatez--keyword-filerJz&Provide a file a keywords to obfuscate)rlrrz --no-updaterYz%Do not update the default cleaner mapz --map-filerQr6z;Provide a previously generated mapping file for obfuscation)rrlrz--keep-binary-filesr?zGKeep unprocessable binary files in the archive instead of removing themz --usernamesrczList of usernames to obfuscatez--treat-certificatesr7)r7keepremoverizHow to treat the certificate files [.csr .crt .pem]. Defaults to "obfuscate" after convert the file to text. "Key" certificate files are always removed.)rlrrr)add_argument_group add_argumentr/strintadd_mutually_exclusive_group)clsrZ report_grpZ preset_grpZ cleaner_grpr*r*r+add_parser_optionss                        zSoSReport.add_parser_optionscCs|d|d|d|d|jdd}|d|d|jd d}|d td d td |dtdddddd}d}|D]"\}}|jd|d|ddq||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_titleadd_textrrr#)rsectionZpsecZssec help_linesZhelplnZlnvaluer*r*r+ display_helpsD   zSoSReport.display_helpcCs$|jdtdtdddS)N zsos report (version ro)ui_loginfo_rrr*r*r+r{szSoSReport.print_headercCs.||d|||d|_dS)N)blockZfibre)ZstoragenetworkZnamespaced_networkZfstype)_get_block_devs_get_fibre_devs_get_network_devs_get_network_namespace_devices_get_devices_by_fstypedevicesrr*r*r+rszSoSReport._get_hardware_devicescCs|jjdkr|jj}|dvr6i|j_|jdn|jjsXd|d}|j|nt||jjvrd dd|jjD}t d |d |n2|jj||jjd <|jd |jjd j d dS)a[Check the loaded container runtimes, and the policy default runtime (if set), against any requested --container-runtime value. This can be useful for systems that have multiple runtimes, such as RHCOS, but do not have a clearly defined 'default' (or one that is determined based entirely on configuration). r0)ZnoneoffZdiabledz0Disabled all container runtimes per user option.zVWARNING: No container runtimes are active, ignoring option to set default runtime to '' rcss|]}|dkr|VqdS)rlNr*.0pr*r*r+ sz5SoSReport._check_container_runtime..zCannot use container runtime 'z1': no such runtime detected. Available runtimes: rlz"Set default container runtime to ''N) rr>lowerrnZruntimesrrwarningkeysjoin Exceptionname)rZcrunrZvalidr*r*r+rs.     z"SoSReport._check_container_runtimec CszFg}gd}|D].}tjd|r|td|dq|WSty}z"|jd|gWYd}~Sd}~00dS)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)rpathisdirrglobrrr)rZdevsZdevdirsZdevdirerrr*r*r+rszSoSReport._get_fibre_devsc szddtdD}td}g|ddkr^|dD]"}|ddd }|q:fd d|D}tt|t|}|WSt y}z"|j d |gWYd }~Sd }~00d S) 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. cSsg|]}d|qS)z/dev/r*)rdr*r*r+ z-SoSReport._get_block_devs..z /sys/blockzlosetup --all --noheadingsstatusroutput:rcs"g|]}|dr|vr|qS)Zloop startswithrdevZreal_loop_devicesr*r+r"s z!Could not get block device list: N) rr r splitlinessplitreplacer"listsetrrr)rZ device_listZ loop_devicesZloop_devZ loop_deviceZghost_loop_devsZdev_listrr*rr+rs  zSoSReport._get_block_devscCsd|i|_dS)Nr)_get_network_namespacesrUrr*r*r+r+szSoSReport._get_namespacesc Csggggd}zPtd|jjdr.|||ds\|jd||||d<Wn6t y}z|j d|WYd}~n d}~00|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)ryrzZNetwork devices not enumerated by nmcli. Will attempt to manually compile list of devices.rz%Could not enumerate network devices: N) r rryupdate_get_nmcli_devsrr _get_eth_devs_get_bridge_devsrr)r_devsrr*r*r+r0s" (zSoSReport._get_network_devscCs*i}|jdD]}d||i||<q|S)zqEnumerate the network devices that exist within each network namespace that exists on the system rr)rUr)rZ_nmdevsZnmspr*r*r+rOs  z(SoSReport._get_network_namespace_devicesc Csi}ztd}|ddkrp|dddD]@}|\}}||vrR|g||<n||||d|q.tt|d|d<Wn6ty}z|jd|WYd}~n d}~00|S) zUse nmcli, if available, to enumerate network devices. From this output, manually grok together lists of devices. znmcli --fields DEVICE,TYPE devrrrrpNrzCould not parse nmcli devices: ) r rrr"rrrrr)rrZ_ndevsrZdnameZdtyperr*r*r+rZs   (zSoSReport._get_nmcli_devsc s dgg}|sdzfddtddD}Wqty`}z|jd|WYd}~qd}~00nzHd|d}t|}|d d kr|d D]}|vr||qWn<ty}z$|jd |d |WYd}~n d}~00|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|]}|vr|qSr*r*rZ 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|]}|dr|qS)rr)rZbdr*r*r+rrcSsg|]}|dr|qS)tunr)rZtdr*r*r+rr)rrr)r rrrr rr")r namespaceZ _eth_devsrZ_nscmdZ_nsoutZ_nsethr*rr+rns8      zSoSReport._get_eth_devsc Csg}ztddd}Wn6tyJ}z|jd|WYd}~n d}~00|ddkr|dd dD]X}z||dWqlty}z$|jd |d |WYd}~qld}~00ql|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 showtimeoutz$Unable to enumerate bridge devices: Nrrrrpz"Could not parse device from line 'z': )r rrrrr"rr)rZ_bridgesZ_boutrZ_bliner*r*r+rs( zSoSReport._get_bridge_devscCs\g}td}|ddkrX|dD]2}|s$|ddrBq$||ddq$|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 netnsrrrNrpr)r risspacer" partition)rZout_nsZip_netnsr'r*r*r+rs z!SoSReport._get_network_namespacescCsi}td}|ddkr|S|dD]b}|}t|dkrP|ddd|dvrdd|d<||dg||d|dq(|S) Nzlsblk -snrpo FSTYPE,NAMErrrrpunknownextZext4)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) cmddirlogdirrptdirtmpdirrrnry verbosityZ cmdlineoptsrrU) rrrrrrnryrrrrUrr*r*r+ get_commonsszSoSReport.get_commonscCs |jSN)rnewrr*r*r+ get_temp_fileszSoSReport.get_temp_filecCs4|j|jd|j|jd|j|jddS)Ni)archivemakedirsrrrrr*r*r+_make_archive_pathsszSoSReport._make_archive_pathscCsd|_d|_d|_dS)NZ sos_commandssos_logs sos_reports)rrrrr*r*r+rszSoSReport._set_directoriescCs"|jjr|jt_d|_nd|_dS)NTF)rr _exceptionsys excepthook raise_pluginsrr*r*r+r|szSoSReport._set_debugcCsLttdstjs$t|||n$tj|||dtjdtt 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>t\}}}tj|||tjdtt ||rR|rR| ||dS)N)r ) rZ exit_processrexc_inforrrrrZ post_mortem_log_plugin_exception)rplugnamefuncrvaltbr*r*r+handle_exceptions  zSoSReport.handle_exceptioncCsTt|ddr(|jj|jtjdddt|ddrP|jj|jtjddddS)N sos_log_filersos.logrsos_ui_log_fileui.log)getattrradd_filerrrrrrr*r*r+ _add_sos_logss      zSoSReport._add_sos_logscsPjj}jjsdSt|ds"dS|r8|s8dStfdd|jDS)NTr_Fc3s|]}|jjvVqdSr)rr_rrr*r+r'rz+SoSReport._is_in_profile..)rr[r_r _is_not_specifiedrany)r plugin_classr[r*rr+_is_in_profiles zSoSReport._is_in_profilecCs ||jjvSr)rrTr plugin_namer*r*r+ _is_skipped)szSoSReport._is_skippedcCs*|| o(||jjvo(||jjvSr)rZ check_enabledrrGr[rr)Z pluginClassr*r*r+ _is_inactive,s   zSoSReport._is_inactivecCs*|| o(||jjvo(||jjvSr)rZdefault_enabledrrGr[r+r*r*r+_is_not_default1s   zSoSReport._is_not_defaultcCs|jjo||jjvSr)rr[r(r*r*r+r$6s zSoSReport._is_not_specifiedrcCs"|j||||fdSr)rtr"rr)rr&reasonr*r*r+_skip:s  zSoSReport._skipcCs |j|||fdSr)rsr"rr)rr&r*r*r+_loadAs zSoSReport._loadc Cstjjj}ttjj}|}g|_t|_t |j j}|j j }g}|j j r\|tjjjt||}|j j}t|j j} |D]} tj| \} } zz|| |} | sWq|j | }|||j j ds|jtd| d|j jdkr||tdWq|j| ||}|s4||tdWq|| rT||tdWq|| |rv||tdWq|| |r||td Wqt |d r|j!|j| o|}|"| r|r||td Wq|jD]}|| vr| #|q|$|Wqt%y\}z0|jtd| d ||&WYd}~qd}~00qt | dkr|j'td d(| |)|*ddS)N)rFzplugin z does not validate, skippingrzdoes not validateZexcludedZskippedZinactiveZoptionalr_z not specifiedz does not install, skipping: z)Unknown or inactive profile(s) provided: rrp)+sosrkplugins import_pluginrZ get_modules plugin_namesrr_r!rrnZvalid_subclassesrFr"ZExperimentalPlugintuplevalidate_pluginrrrsplitextZ match_pluginrrrrr/r'r*r,r-r rr$rr0rrrrrOr)rr3rr2Zusing_profilesZpolicy_classesZ extra_classesZvalid_plugin_classesr6Zremaining_profilesplugZplugbase__Zplugin_classesr&Z in_profileZdefault_profileier*r*r+ load_pluginsGs                   zSoSReport.load_pluginscCs<|jjr8|jD](\}}|jD]}t|jvr d|_q qdS)NT)rr8rsoptionsvaluesboolZval_typer)rr9r8optr*r*r+_set_all_optionss  zSoSReport._set_all_optionsc Cs|jjri}|jjD]}z|d\}}WntyBd}Yn0t|tr|}|dvrdd}n.|dvrrd}n z t|}WntyYn0z|d\}}Wnty|}d}Yn0z ||Wntyi||<Yn0||||<q|j D]\}}||vr||D]}||j vrH|j d|d|d | d z:|j |||||j d |d |j |Wn<ty}z"|j || d WYd}~n d}~00q||=q|D]}|j d |dq|r|j ddS)N=T)onenableZenabledtrueZyes)rdisableZdisabledZfalsenoF.zno such option "z" for plugin (rorpzSet z plugin option to zCWARNING: unable to set option for disabled or non-existing plugin (z).r)rrKr ValueError isinstancerrrKeyErrorrsr=rrrZ set_valuerrr)rrr@rargr8rrr*r*r+ _set_tunablessh                $ zSoSReport._set_tunablescCsddl}||jj|jjD]:}|dd}||jvr|jd|d| dq|jj D]"}||jvr`|j d|dq`dS)NrrHza non-existing plugin (z$) was specified in the command line.rpz'Requested to skip non-existing plugin 'z'.) itertoolschainrr[rGrr4rfatalrrTr)rrNpluginr)r*r*r+_check_for_unknown_pluginss      z$SoSReport._check_for_unknown_pluginscCs2|jD]&\}}|jD]}|j|j|qqdSr)rsr=rur")rr9rQr@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 |7}n|d 7}|d7}|S)Nz Estimate-only mode enabledrpz --threads=z overriden to 1z--build enabledTz--no-postproc enabledz--clean disabledFz--upload* options disabledz", which overrides some options: z rHz )rthreadsr:rXr=rdr)rrZext_msgr*r*r+_set_estimate_onlys,     zSoSReport._set_estimate_onlycCsd|jd|jr:|jdt|jdt|jdn|jdt|jd|jddS)Nrrz profiles, z pluginsz profiles)rrrsr!r_rr*r*r+_report_profiles_and_pluginss  z&SoSReport._report_profiles_and_pluginsc Cs|js |js |jtddS|jrr|jtd|jd|jD]&\}}|jd|dd|qHn|jtd|jd|jr|jtd|jd|jD]0\}}}|jd|dd|d d|q|jd|jrn|jtd |jd d  }|D]}||}|j }|j d krx|dkrZ|j j pVt }n|dkrt|j jppt }nt }|jdkr|j j }|jd|jdd|dd|jq"|jd|jtd|jD]}|jdvr|j |jkrqt|j tr"|j durd} nd} n|j } | dur6d } |jd|jd|jdd| dd|jqn|jtd|jdt|j} | td| dd} | D]} |jd| q|dS)Nzno valid plugins foundz,The following plugins are currently enabled:rrz<20zNo plugin enabled.z-The following plugins are currently disabled:z<30z<14z4The following options are available for ALL plugins:rrpr cmd-timeoutpostprocz<25<15z+The following plugin options are available:)rrYrXTrCrrHz<35zNo plugin options available.z Profiles: r$)rsrtrrPrrrZget_descriptionruZget_default_plugin_optsrrr]r r^rrXr@rlrJr?rQrr_sortr,rV) rrr8Z plugclassr. _defaultsZ_optr@rZtmpoptr_r&r'r*r*r+rMsv  "         *       zSoSReport.list_pluginsc Cs|js|jtddS|jtd|jddd}t|j}||D]b}g}|jD]$\}}||rb||jvrb| |qbt |d|dd}|D]}|jd |qqT| dS) Nzno valid profiles foundz%The following profiles are available:rcSs t|dS)Nr_)r )cr*r*r+ _has_profasz*SoSReport.list_profiles.._has_profrZTr[r) r_rrPrrrrr\rsr"r,rV) rr_r_Zprofiler2rrQr&r'r*r*r+rOZs"   zSoSReport.list_profilescCs|jjs|jtddS|jtd|jd|jjD]}|sNqD|j|}|jddd|j |jddd|j |j r|jddd|j |j j d kr|j }d dd}t||d dd }|D]}|j|q|jdqDdS) Nzno valid presets foundz$The following presets are available:rzname:z>14rz description:znote:rzoptions:T)r$r%)rnZpresetsrrPrrrr find_presetrr@rZrrto_argsr,)rr\rZ options_strr&r'r*r*r+rNps(     zSoSReport.list_presetsc Cs|j}||r(|jd|ddS|p2|jj}|p>|jj}z|j||||jdWn8ty}z |jd|WYd}~dSd}~00|j d}|j d||j |d d}|j d |d d |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@rZrzCould not add preset: NrrrzAdded preset 'z' with options rrT) rnr`rrrr@rZrgrrmindexrr)rrr@rZrnr;Z arg_indexrr*r*r+rgs"     zSoSReport.add_presetc Cs|j}||s(|jd|ddSz|j|dWn<tyt}z$|jt|dWYd}~dSd}~00|jd|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 foundFrrNzDeleted preset 'rT)rnr`rrrhrrr)rrrnr;r*r*r+rhs zSoSReport.del_presetc Cs|j}|jjr||7}|jjr4|j|np|td7}z t |WnVt yt|j d| dYn0t y}z| d|WYd}~n d}~00dS)Nz,Press ENTER to continue, or CTRL-C to quit. zExiting on user cancelrp)rnZget_msgrrErUbatchrrrinputKeyboardInterruptrrr)rrr;r*r*r+res      zSoSReport.batchcCsrt}d}|d}tj|j|}|j|d|d|d|jd||jj |d|dd dS) Nz!caught exception in plugin methodz-plugin-errors.txtz "rHz()"zwriting traceback to ra)mode) r format_excrrrrrrr add_string)rrQmethodZtracerZplugin_err_logZlogpathr*r*r+rs zSoSReport._log_plugin_exceptionc Cs|jz&|jtd||WdSty}zJ|jt vrnt dt d|j dt dnt d|WYd}~nXd}~0t y}z8|j d|j dt|j |WYd}~n d}~00|ddS)Nz Setting up archive ...rrz while setting up archivezError setting up archive: z) Unexpected exception setting up archive:rp)rnZpre_workrrrZ setup_archiverOSErrorerrnofatal_fs_errorsrstrerrorrrr print_excrrr;r*r*r+preworks&     "zSoSReport.preworkc Csj|jtd|jD]L\}}z|jj||t|jj|t }|j d||j |_ |||j|j|jjr|t }|j d||j d||WqtytYqtyD}z\|jtvr$|jd|jd|jd|jd|d||d WYd}~qd}~0tyb||d Yq0qdS) Nz Setting up plugins ...Z setup_startZ setup_endZ setup_timerrz while setting up pluginsrpsetup)rrrrsrr2rZset_plugin_manifestr!rnowr} add_fieldrZadd_default_collectionsrtrwrZ _env_varsrraZ setup_verifyrgrmrnrorrprrrrrr8startendr;r*r*r+rts>        zSoSReport.setupcCs.g}|dt|jjd|dddS)zWFetch version information from all plugins and store in the report version filez sos report: rz version.txt)ZcontentrN)r"rrrkr)rZversionsr*r*r+version s zSoSReport.versioncCs|jtd|jdd}g|_g|_|jD] }|d7}|j||dfq2ztg}t|jj $}| |j t |j}Wdn1s0Y|D]}|s|j d|q|jdWn(ty|jdtdYn0dS)Nz! Running plugins. Please wait ...rrrpzUnexpected plugin task result: z Exiting on user cancel )rrrpluglist running_plugsrsr"rrrTmap_collect_pluginrrrrgrrr)rZ plugruncountr:resultsexecutorresr*r*r+collects*  "  zSoSReport.collectc Cstd}z||j|ddd}||j|}|jp:d}t}|jd||j |dt}|jd||jd||Wnt y d|dd }|j d |d |j ||j|d|j|ddd|jd d |jYn0Wdn1s$0Y|jjr|j} z0td| } t| dd|j|d<Wn"tyd|j|d<Yn0t| D]D} tj !| | } tj "| rtj #| st$| n t%| qd S)zaWraps the collect_plugin() method so we can apply a timeout against the plugin as a wholerprNZ start_timerZend_timeZrun_timezPlugin z timed out rT)waitzdu -sB1 r)&rrsZsubmitcollect_pluginrrrur}rvresultFuturesTimeoutErrorrrrrr|rZset_timeout_hitrZ_threadsclearrrErZ get_tmp_dirr rrrzrrr rrrislinkrunlink) rrQZpoolZ_plugtrrxryrrZdufr*r*r+r~,sB     0   zSoSReport._collect_pluginc Cs"z*|\}}|j|dd}|j|Wnty>YdS0t|j}d|d|dd|dddd d |jDd }||z|z|j |Wn&t y|j d |d Yn0z|j |Wn(t y|j d |dYn0d}t|jt |jjkrR|jrRddddddd |jDd }|jsf|jsfd}|rv||WntyYnty}zZ|jtvr|jd|jd|jd|jdtd||dWYd}~n(d}~0ty||dYn0dS)NrpFz Starting rjz<5rrZz [Running: css|] }|VqdSrr*rr*r*r+rfrz+SoSReport.collect_plugin..]zCould not remove z from plugin list, ignoring...z& from running plugin list, ignoring...rz Finishing plugins z<12css|] }|VqdSrr*rr*r*r+rrz Finished running pluginsrz while collecting plugin dataz# Data collected still available at rr)rsr|r"rr!r ui_progressrr{rrIrrrrrTrrmrnrorrrprrrr) rrQcountrr8Znumplugs status_linerr;r*r*r+r]sf            zSoSReport.collect_plugincCsR|jjdkr&|jjs&d|d}n |d}|jjsNtj|tjdS)Nr Zr) rrreljustquietrrwriteflush)rrr*r*r+rs   zSoSReport.ui_progresscCs@|js dSddddd|jDDd}|j|ddS)NrcSs"g|]\}}|dt|qS)rB)r )rrrr*r*r+rsz.SoSReport.collect_env_vars..cSs.g|]&}tj|dur|tj|fqSr)renvironget)rrr*r*r+rsZ environment)rwrrrk)renvr*r*r+collect_env_varss zSoSReport.collect_env_varsc Cst}|jD]\}}t|d}|jD]}|t|q$|jrN|t|j|jD]"}|t |dd|ddqT|j D]4}|t |ddt j d|d|d d q~|jD]&\}}}|t|t j d|dq||q td d ftd dftddff} | D]\} } } zT|} | |}|dd}| || |jj| t j d| dWnpty}zV|jtvr|j !d|j !d|j"d| d|j !d|#dWYd}~n d}~00qdS)NrcZsrcpathz..Zdstpath)rhrefcmdrrr )rZ return_coderzsos.txttextzsos.jsonZJSONzsos.htmlZHTMLutf-8rrrrrz while writing z reportrp)$rrsrZalertsaddrZ custom_textrZ copied_filesrZexecuted_commandsrrrrrZ copy_stringsrrrrrZunicodeencodedecoderrrr"rmrnrorrrpr)rrkrr8rZalertrrr9Z formatlistclass_filenametype_fdrr;r*r*r+generate_reportss\                zSoSReport.generate_reportsc Cs|jD]\}}zh|drdt}|jd||t}|jd||jd||n|jd|Wqt y}zZ|j t vr|j d|j d|jd|j d|d ||dWYd}~qd}~0ty||dYq0qdS) NrYZpostproc_startZ postproc_endZ postproc_timezSkipping postproc for plugin rrz" while post-processing plugin datarp)rsZ get_optionrrur}rvrYrrrmrnrorrrprrrrwr*r*r+rYs.       zSoSReport.postproccCs|sdSzXd}t|}t|d,}||}|s4q@||q$Wdn1sT0YWntyz|Yn0|S)NFirb)hashlibropenreadrrrZ hexdigest)rr hash_nameZ hash_sizeZdigestZ archive_fpZhashdatar*r*r+_create_checksums   . zSoSReport._create_checksumcCsLt|d|ddd"}|r*||dWdn1s>0YdS)NrHwr)encodingr)rr)rrrchecksumfpr*r*r+_write_checksumszSoSReport._write_checksumc sRd}d}d}|d}|jjrzJ|j|j|j|j|jd}td|d}||j | \}}d}Wn6t y}zt td|WYd}~n d}~00||jdur|j |jj||r(tj|j|j j} |tj| dd|tj| dd|tj| d d |jjr:||jjr"d d lmd d lm} | |j} tdd| dD|j!d<t|j!"} |j#$d| t%|j!&dddddd} dfdd| D}|j#$d||j#$d|j#$d|j#$d|j#$d|jj's*t(d}|jjsLt tdzz&|rb|j )||j *|jj}Wnt+y}zRt dt td|j,d |j t d|j-t.vr|/d!WYd}~n6d}~0t y |jj0rYWt(|dS0Wt(|n t(|0n|jj1s>|jj2rJ|j#3d"|j }tj4|}|rp|5|}z$tj|j|}t6|||}Wn(t+yt td#|YdS0d}|jj's:|st d$qNz|j7}|8||}Wn"t yt td%YdS0z|9|||Wn&t+yTt td&|Yn0tj4|}|rz|5|:d'd(}tj|j|}t;|}|d)|}|d)|}zt6|||}Wn(t+yt td*|YdS0zt6||Wn&t+y t td+|Yn0|jj<|||||d,n|jj<||||d,|jj=sl|jj>sl|jj?r|jj'szP|j|j|j|j|jd}t@|jA|jB|jCd||d-}| |j#$td.Wn8t y}z|j#Dd/|WYd}~n d}~00nd0}|j#D|tEF|jGr,|jG|jrNtjH|jrNtI|jdS)1NF)rnrsys_tmpr=r}T)in_place hook_commonsz#ERROR: Unable to obfuscate report: rrr rz manifest.jsonrget_human_readable)Pathcss|]}|jVqdSr)lstatst_size)rrr*r*r+rDsz'SoSReport.final_work..z**/*Zsos_logs_reportszNEstimated disk space requirement for whole uncompressed sos report directory: cSs|dS)Nrpr*)xr*r*r+Krz&SoSReport.final_work..)keyreversez, c3s(|] \}}|d|ddVqdS)z: r)Z precisionNr*)rrvrr*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 rpzQ 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.tarrHzError moving archive file: zError moving checksum file: )rQ)rrrmrrrzUploaded archive successfullyzUpload attempt failed: zEUnable to upload archive when using --build as no archive is created.)Jgenerate_manifest_tag_summaryrr=rnrrr}rZset_target_pathrZget_archive_pathexecuterrrr#Zadd_final_manifest_dataZcompression_typeZ_obfuscate_upload_passwordsrrr_nameZobfuscate_filerZadd_ui_log_to_stdoutrE sos.utilitiesrpathlibrsumrrzr>rrsortedr#r:umaskZrename_archive_rootfinalizermrprnrorrZ encrypt_passZ encrypt_keyrbasenameZobfuscate_stringrenameZget_preferred_hash_namerrrstatZdisplay_resultsrdrerfrrrrmrrrrrr)rrZ directoryrQZdo_cleanrZcleanerZ_pathsrZ_dirrZ tmpdir_pathZ_sumZ bigpluginsZbp_outZ old_umaskr;Zdir_nameZ final_dirrrZ base_archive final_nameZ archivestatZ archive_hashZ final_hashZuploaderrr*rr+ final_work sF  (                                      *   zSoSReport.final_workcCs|js|jtddSdS)Nzno valid plugins were enabledFT)rsrrrrr*r*r+verify_pluginsszSoSReport.verify_pluginscCs|jd|j|jd|jr&|jjnd|jd|jjd}tdr~t dt }|dd kr~|d  d  d }|jd |jjd ||jjdt d |jd|jD]\}}|jj||q|jd|jj|jd|jj|jddS)zgAdd 'global' data to the manifest, that is any information that is not plugin-specific ryr\Zunsetr_rZionicez ionice -p rrrrpriorityZio_classZnicenessrZenabled_pluginsZdisabled_pluginsr2N)rrvryr\rZadd_listrr_r r rgetpidrrrrnicerr#rGrT)rZ _io_class_iorrr*r*r+add_manifest_datas&   zSoSReport.add_manifest_datacs|dfdd }i|jjD]B}|jD] }||q$|jD]}||dq8|jD] }||qNq|jdttdS)acAdd a section to the manifest that contains a dict summarizing the tags that were created and assigned during this report's creation. This summary dict can be used for easier inspection of tagged items by inspection/analyzer projects such as Red Hat Insights. The format of this dict is `{tag_name: [file_list]}`. filepathc s~|dD]p}||r|sqz |}Wnty<g}Yn0|t||trX||n||gttt||<qdS)Ntags)rKrrJrrr)Zentrtagr tag_summaryr*r+ compile_tags s     z=SoSReport.generate_manifest_tag_summary..compile_tagsZ files_copiedrN)r) rr2Zcommandsfiles collectionsrvdictrr#)rrr8rZ_fileZ collectionr*rr+rs        z'SoSReport.generate_manifest_tag_summaryc Cs|jdtdd|jd|jj}dtd|jjdd|d}|j||jdtdd|jdS) N[z:setup] executing 'sos rrz:setup] using 'z' preset defaults (roz:setup] effective options now: ) rr__name__rrmr\rrar)rZ preset_argsrr*r*r+_merge_preset_options%s   zSoSReport._merge_preset_optionsc Csz8|j||||||||j j rX| t |j j rl| t |j j r| t |j jr||j jt |j jr||j jt |st ||||||j js||j js ||j js|n |jd||WSt yt|j j!rVt"#dddksp|$Yn|t%y|j&d|$|'dYnLt y}z2t"#dddks|$t()|j*WYd}~n d}~00|'ddS)Nz)Skipping postprocessing of collected dataZ SOS_TEST_LOGSrz Exiting on user cancelrdrpF)+rnZ set_commonsrr<rArrMrRrSrrM SystemExitrOrNrgrhrrersrrtrrWrrVrrXrYrrrzrrmrrgetenvZcleanuprgrrrexitcoderrr*r*r+r4sl        " zSoSReport.execute)N)NN)r)rr)Jr __module__ __qualname____doc__r@Z root_requiredr Z arg_defaultsrr classmethodrrr{rrrrrrrrrrrrrrrrr| staticmethodrrr#r'r*r,r-r$r/r0r<rArMrRrSrUrVrMrOrNrgrhrerrsrtrzrr~rrrrrYrrrrrrrr __classcell__r*r*rr+r3RsB ' W 6   2     O; I   17  7Z r3)Fr)7rrrrnrrrrrconcurrent.futuresrrrshutilrZsos.report.pluginsr1rrrrr r r r r rrrZ sos.componentrZ sos.policiesZsos.report.reportingrrrrrrrrrrZ sos.cleanerrZ sos.uploadrENOSPCZEROFSror,r/rrvr3r*r*r*r+ s4    (   0