3 ܓi@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZmZdd lmZdd lmZdd lmZdd lm Z dZ!GdddeZ"dS)N)datetime)ThreadPoolExecutor)getpass)Path)quote) SoSCleaner)SosNode) ClusterOption str_to_bool) SoSComponent)bold) __version__) SoSUploadz/etc/sos/groups.dcOseZdZdZdZdddddddgddgggddddddgdd gddddd dd dddgdddddgddgddddddddgggdd d d ddddgddddddddddddddddNZfddZddZeddZ eddZ eddZ ddZ eddZ edd Zdad!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@ZdAdBZdCdDZ dEdFZ!dGdHZ"dIdJZ#dKdLZ$dMdNZ%dOdPZ&dQdRZ'dSdTZ(dUdVZ)dWdXZ*dYdZZ+d[d\Z,d]d^Z-d_d`Z.Z/S)b SoSCollectora sos collect, or SoS Collector, is the formerly standalone sos-collector project, brought into sos natively in 4.0 and later. It is meant to collect sos reports from an arbitrary number of remote nodes, as well as the localhost, at the same time. These nodes may be either user defined, defined by some clustering software, or both. For cluster defined lists of nodes, cluster profiles exist that not only define how these node lists are generated but may also influence the sos report command run on nodes depending upon their role within the cluster. Nodes are connected to via a 'transport' which defaults to the use of OpenSSH's Control Persist feature. Other transport types are available, and may be specifically linked to use with a certain cluster profile (or, at minimum, a node within a certain cluster type even if that profile is not used). sos collect may be run from either a node within the cluster that is capable of enumerating/discovering the other cluster nodes, or may be run from a user's workstation and instructed to first connect to such a node via the --primary option. If run in the latter manner, users will likely want to use the --no-local option, as by default sos collect will also collect an sos report locally. Users should expect this command to result in a tarball containing one or more sos report archives on the system that sos collect was executed on. z8Collect an sos report from multiple nodes simultaneouslyFautoNTrz /etc/sos/cleaner/default_mappingrootsudoiX obfuscate)Nall_logs alloptionsZallow_system_changes become_rootcase_idchrootcleancluster_options cluster_typeZcontainer_runtimedomainsdisable_parsersZenable_pluginsZ encrypt_keyZ encrypt_passgroupZimageZinherit_config_fileZforce_pull_imageskip_cleaning_filesjobsZ journal_sizekeywords keyword_filekeep_binary_fileslabel list_optionslog_sizeZ low_prioritymap_fileprimaryZ namespacesZnode_config_filenodesZ no_env_varsno_local nopasswd_sudoZ no_pkg_check no_updateZ only_pluginspasswordpassword_per_nodeplugoptsZplugin_timeoutZ cmd_timeoutZpresetZ registry_userZregistry_passwordZregistry_authfile save_groupZsince skip_commands skip_filesZ skip_pluginsssh_keyZssh_portssh_userZ sudo_binaryZtimeout transporttreat_certificatesverify usernamesuploadZ 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_targetcsntj|||tjdg|_g|_d|_d|_d|_d|_ |j j j d|j j j |_|jjdd|jjdt|jddtj|_y$td d tjtjdD|_Wn&tk r|jd d g|_YnX|j|j|_|jjsjyT|j|j |j!d dj"ddt#j$D|j!d|jj%|j&Wn"t'k rh|j(ddYnXdS)N?rcollectrnone node_listsudo_pwrcSsh|]}|ddqS)rr).0irCrC/usr/lib/python3.6/__init__.py sz(SoSCollector.__init__..zkCould not get a list of IP addresses from this hostnamne. This may indicate a DNS issue in your environmentz 127.0.0.1z Executing  css|] }|VqdS)NrC)rDsrCrCrF sz(SoSCollector.__init__..zFound cluster profiles: zExiting on user cancel))super__init__osumask client_listrAr+ retrievedclusterrmanifestZ components add_sectionr? collect_md add_fieldadd_listsetattroptssocketZ gethostnamehostnamelistZ getaddrinfoip_addrs Exception log_error_parse_options load_clustersclustersr(parse_node_stringsparse_cluster_options log_debugjoinsysargvkeysverify_cluster_optionsKeyboardInterruptexit)selfparserZ parsed_argsZ cmdline_args) __class__rCrFrMsB      " zSoSCollector.__init__cCsHddl}|jj}i}|j|d}x"|D]}|d|j||d<q&W|S)zmLoads all cluster types supported by the local installation for future comparison and/or use rNrb)Zsos.collector.clustersZ collectorrb _load_modulescommons)rmsospackageZsupported_clustersrbrRrCrCrFras  zSoSCollector.load_clusterscCs6g}x,|jD]"}tjj|r |j|j||q W|S)z'Helper to import cluster and host types)__path__rNpathisdirextend_find_modules_in_path)clsrtZsubmodmodulesrvrCrCrFrqs   zSoSCollector._load_modulescCsrg}tjj|rnx\ttj|D]J}|jds0q d|kr:q tjj|\}}d|d|}|j|j|q W|S)aXGiven a path and a module name, find everything that can be imported and then import it path - the filesystem path of the package modulename - the name of the module in the package E.G. a path of 'clusters', and a modulename of 'ovirt' equates to importing sos.collector.clusters.ovirt z.py__zsos.collector..) rNrvexistssortedlistdirendswithsplitextrx_import_modules)rzrvZ modulenamer{Zpyfilefname_modnamerCrCrFrys   z"SoSCollector._find_modules_in_pathcCs|jdd}yt|tt|g}Wn>tk rd}z"td|d|jj|WYdd}~XnXtj |tj }x&|j D]}|dd kr~|j |q~W|S) z/Import and return all found classes in a moduler}z"Error while trying to load module z: NrSosHostCluster)rr) split __import__globalslocals ImportErrorprintro__name__inspectZ getmembersZisclasscopyremove)rzrZmod_short_namemoduleer{modrCrCrFrs zSoSCollector._import_modulesc Cs|jjs dSg}t|jjts,|jjg|j_x|jjD]}ddt|D}|jt|d}d}xp|D]h}yJ|}|||}tjtj |d|krd|krwh|j|j d|}Wqhtj k rwhYqhXqhW|t|kr6|j||ddq6W||j_dS) arParses the given --nodes option(s) to properly format the regex list that we use. We cannot blindly split on ',' chars since it is a valid regex character, so we need to scan along the given strings and check at each comma if we should use the preceeding string by itself or not, based on if there is a valid regex at that index. NcSsg|]\}}|dkr|qS),rC)rDrEmrCrCrF sz3SoSCollector.parse_node_strings..r[]rrp) rYr, isinstancer\ enumerateappendlenrecompileescapelstriperror)rmr,nodeZidxsstartposidxZregrCrCrFrcs0    zSoSCollector.parse_node_stringsc Cst|jdd}|jddddd|jddd d|jd dd d d |jdddddgdd|jdddd|jddddd|jdtddd|jd d!d"dd#d$d%|jd&dtd'd(|jd)dd d*d |jd+d,dd-d|jd.d/dgd0d |jd1dd2d|jd3dd d4d |jd5tdd6d|jd7tdd8d|jd9dd:d|jd;gdd|jd?gdd@dAd>|jdBddCd|jdDdE}|jdFdGddHdId%|jdJdKdL|jdMd ddNdO|jdPtddQd|jdRdSdL|jdTdUdVdWdXdY|jdZdd[d|jd\dd]d|jd^d_dL|jd`dadbdtdcdd|jdeddfd|jdgddhd|jdiddjd|jdkdldmdL|jdndodptdqd(|jdrdsddtd|jdudvdL|jdwdxdydzdd{d||jd}dd~d|jddWdd|jdddd|jdddd|jddtdd|jddd dd |jddd dd |jddd dd|jdddL|jddtdd(|jdtd dd|jddtdd(|jddd dd |jdddd|jdddd|jdddd|jdddd|jdddddgdd|jdd dddO|jdddd|jdddd|jdddd|jdddd|jdddd|jdddd|jdddddddgdd|jdd}|jddddd dddÍ|jdd dddd>|jddgdddÍ|jddgddd͍|jdddgddd͍|jddgddd͍|jddddd؍|jddd ddd͍|jddddd||jddgdddÍ|jdddddgddddS)NzReport Passthru Optionsz0These options control how report is run on nodesz-az --alloptions store_truezEnable all sos report options)actionhelpz --all-logszCollect logs regardless of sizez--allow-system-changesFz8z<40z<30F)newline)Z set_titleZadd_text__doc__itemsr )rzZsectionZ hsectionsZhsecvaluerCrCrF display_helps  zSoSCollector.display_helpc Csx|jr|jj|r|j|y |jWntk rH|jdYnX|dkrZ|j|sjtj|n tj |dS)aUsed to terminate and ensure all cleanup is done, setting the exit code as specified if required. :param msg: Log the provided message as an error :type msg: ``str`` :param error: The exit code to use when terminating :type error: ``int`` :param force: Use os.exit() to break out of nested threads if needed :type force: ``bool`` z/Warning: Failed to close all remote connectionsrKN) rRZcleanupr_close_all_connectionsr^log_warnrgrlrN_exit)rmmsgrforcerCrCrFrl)s     zSoSCollector.exitcCs8|j|jjdk|jtt|jjt|j|jd|_dS)zxFrom commandline options, defaults, etc... build a set of commons to hand to other collector mechanisms r)Z cmdlineopts need_sudotmpdirhostlenpolicyN) rYr7rmaxrr+r[rrr)rmrCrCrFr`Gs  zSoSCollector._parse_optionscCsg}t|jjts |jjg|j_|jjrx|jjD]t}|jdd}|jddjdd}y|jddjd}Wntk rd}YnX|jt|||j|q2W||j_dS)Nr}rrp=True) rrYrr\r IndexErrorrr ro)rmrYoptionrRnamerrCrCrFrdSs z"SoSCollector.parse_cluster_optionscCs|jjrxf|jjD]Z}d}xP|jjD]B\}}x8|jD].}|j|jkr6|j|kr6d}|j|||_Pq6Wq&WqW|s|j d|jd|jddS)z+Verify that requested cluster options existFTz!Unknown cluster option provided: r}rpN) rYrrbroptionsrrR_validate_optionrrl)rmoptmatchclustrrrCrCrFrjhs z#SoSCollector.verify_cluster_optionscCsl|jtks<|j|jks6d}|j||j|j|jfd|jS|jj}|d krdd }|j||jd|d kS) aCChecks to make sure that the option given on the CLI is valid. Valid in this sense means that the type of value given matches what a cluster profile expects (str for str, bool for bool, etc). For bool options, this will also convert the string equivalent to an actual boolean value z.Invalid option type for %s. Expected %s got %srptrueonyesfalseoffnozUInvalid value for %s. Accepted values are: 'true', 'false', 'on', 'off', 'yes', 'no'.)rrrrrr)rrr)opt_typeboolrlrrlower)rmrZclirvalrCrCrFrws   zSoSCollector._validate_optioncCs|jj|dS)z.Log info messages to both console and log fileN)sosloginfo)rmrrCrCrFlog_infoszSoSCollector.log_infocCs|jj|dS)z.Log warn messages to both console and log fileN)rZwarning)rmrrCrCrFrszSoSCollector.log_warncCs|jj|dS)z/Log error messages to both console and log fileN)rr)rmrrCrCrFr_szSoSCollector.log_errorcCs0tjdd}d|d|}|jj|dS)z.Log debug message to both console and log filerpz[sos_collector:z] N)rstackrdebug)rmrZcallerrCrCrFreszSoSCollector.log_debugc stjjdtjjdx8t|jD]*}tjjd|dd|j|jddq$Wixn|jjD]`\}}xV|jD]L}|jkr||j<qrx0|j D]&}||jj kr|jj j |qWqrWqbWtjjdtjjddd dd d dd d ddddddd xtfdddD]l}|}ddj ddt|j Dd d|jd d|j j d dt|jd d|jd d }tjj|qWtjjddS)z&Display options for available clustersz; The following clusters are supported by this installation z@Use the short name with --cluster-type or cluster options (-c) rHz<15Z30 z/ The following cluster options are available: rZ25z Option NameZ15ZTypez<10ZDefaultZ10Z Descriptionsz+SoSCollector.list_options..)keyz z, css|] }|VqdS)NrC)rDcrCrCrFrJsz,SoSCollector.list_options..zh Options take the form of cluster.name=value E.G. "ovirt.no-database=True" or "pacemaker.offline=False" N)rgstdoutwriterrbZ cluster_namerrrrRrrfrrrr description)rmrRrrrrZ_optZoptlnrC)rrFr(s*  $     0RzSoSCollector.list_optionscCstj|jdS)z8Removes the temp directory and all collected sos reportsN)shutilZrmtreer)rmrCrCrFdelete_tmp_dirszSoSCollector.delete_tmp_dircCsd}|jjr|d|jj7}|jjr8|d|jj7}tjtjd}y tjt_Wn2t k r}z|j d|WYdd}~XnXdj ddt d D}|d|d|S) z(Generates a name for the tarball archivez sos-collector-z%Y-%m-%dz#Could not cast to ascii_lowercase: Nrcss|]}tjtjVqdS)N)randomZchoicestring lowercase)rDrrCrCrFrJsz1SoSCollector._get_archive_name..) rYr'rrZstrftimeZnowrZascii_lowercaser NameErrorrerfrange)rmZnstrZdterrZrandrCrCrF_get_archive_names "zSoSCollector._get_archive_namecCs&|j|_d}|jd|jd|S)zvReturns the path, including filename, of the tarball we build that contains the collected sos reports Zgz/z.tar.)rarc_namer)rmZcomprrCrCrF_get_archive_paths zSoSCollector._get_archive_pathcCs|jj}|tjjtjd|tjjt|g}d}x|D]}tjj|r:|}Pq:W|dkrjt d||j d|t |ddd}t j |}xBdD]:}||r|j d |d ||d t|j|||qW|d r |j d|d d|jjj|d WdQRXdS)a Attempts to load the host group specified on the command line. Host groups are defined via JSON files, typically saved under /etc/sos/groups.d/, although users can specify a full filepath on the commandline to point to one existing anywhere on the system Host groups define a list of nodes and/or regexes and optionally the primary and cluster-type options. z.config/sos/groups.d/Nzno group definition for zLoading host group rzutf-8)encodingr+rzSetting option 'z' to 'z'per host groupr,zAdding z to node list)r+r)rYr!rNrvrfrhomeCOLLECTOR_CONFIG_DIRr~OSErrorreopenjsonloadrXr,rx)rmZgrppathsrrvhfZ_grouprrCrCrF_load_group_configs*      zSoSCollector._load_group_configc Cs|jj|jj|jjdt|jd}tjdkrRtj j t j d}tj |ddnt}tj j ||d}t|ddd }tj||Wd QRXtj|d |S) a Saves the results of this run of sos collect to a host group file on the system so it can be used later on. The host group will save the options primary, cluster_type, and nodes as determined by sos collect prior to execution of sos reports. r)rr+rr,z.config/sos/groups.dT)exist_okrwzutf-8)rNi)rYr3r+rRrr\rArNgetuidrvrfrrmakedirsrrrdumpchmod)rmZcfgZ group_pathrrrCrCrFwrite_host_group s    zSoSCollector.write_host_groupc=Cs |jj|j|jj rB|jj rB|jdd}|jj|j |y|jjs\|jjr|jj r|jj r|jdd|jj d}t |d|j_|jdo|jj o|jj r|jj r|jj r|jdd |jj d }t |d|j_n|jjs|jj|j_Wn"tk r&|jd d YnX|jjr|jj d ks|jj rZd}|j|d|jdd|jj d}t |d|j_d|jd<n|jdd|j_|jjry |jWnDtk r}z&d|jjd|}|j|dWYdd}~XnXy|jjWn"tk r,|jdd YnX|jj rJ|jd|j_nyd}d}d}|jj rtjdkr|jj r|jj sd}t |}|dkr|jj|d}d|j_d}n|jj|d}d|j_td|j||d|_ Wn@tk r*}z"|jd||jddWYdd}~XnX|jjd |j j |jj!d!|jj"j!|j j |j j#t$|jj"|j j |jj%r|jj%d"kr|j&d#|_'n|j&|jj%|_'|jj%|_%|j |j'_ n|j(|j'dkr|jj" rd$}|j|dn2|j'dkr&|jj"r&|jd%|j&d#|_'d"|_%|jjd&|j%|j'r|j'|j _'|jj)d'krd|j'j*|j_)|j'j+|j'j,r|jj-s|jd(|j'j,d)|j'j,|j_-|j.|jj/r|jj/}y"|j0}|jd*|d+|Wn:tk r}z|j1d,|d|WYdd}~XnXdS)-Nz)password not specified, assuming SSH keyszgsos collect ASSUMES that SSH keys are installed on all nodes unless the --password option is provided. z&password specified, not using SSH keysz"Provide the SSH password for user z: )promptrz3non-root user specified, will request sudo passwordz=A non-root user has been provided. Provide sudo password for z on remote nodes: z Exiting on user cancel rKrzkCannot become root without obtaining root password. Do not use --batch if you need to become root remotely.rpz,non-root user asking to become root remotelyzUser z5 will attempt to become root. Provide root password: FzSOption to become root but ssh user is root. Ignoring request to change user on nodezCould not load specified group zExiting on user cancel TzLocal sos report generation forcibly skipped due to lack of root privileges. Either use --nopasswd-sudo, run as root, or do not use --batch so that you will be prompted for a password rz8Enter local sudo password to generate local sos report: r localhost) local_sudoZ load_factsz(Unable to determine local installation: zsUnable to determine local installation. Use the --no-local option if localhost should not be included. Aborting... r+r,r@ZjbonzFCluster type could not be determined and no nodes provided Aborting...zCluster type could not be determined, but --nodes is provided. Attempting to continue using JBON cluster type and the node listrrzUpdating SSH key to z per clusterz Wrote group 'z' to zCould not save group )2rZ set_commonsrrrYr0r1reui_logr_fmt_msgr+batchr7rr.rBrkrlrZ root_passwordrr!rr^Zpre_workconnect_to_primaryr-rNrrrUrVaddressrTr,set_node_manifestgetattrrrbrRdetermine_clusterr8Zset_transport_typeZsetupZcluster_ssh_keyr6 get_nodesr3rr_)rmrrZ can_run_localr Zskip_local_msgZgnamerrCrCrFprep#s                                    zSoSCollector.prepcCsB|jjd|j r*|jj r*|jdd|jjd|jjr|jjdk r|jjrZ|jj p`|j j s|jjd|jjd|j dx2t |jD]$}|jjd|d|j dqW|jjd|jjs>ytd |jjdWnTtk r |jd d Yn4tk r<}z|jt|dWYdd}~XnXdS) zuPrints a list of nodes to collect from, if available. If no nodes are discovered or provided, abort. rzGNo nodes were detected, or nodes do not have sos installed. Aborting...rpz1The following is a list of nodes to collect from:N rrzC Press ENTER to continue with these nodes, or press CTRL-C to quit zExiting on user cancelrK)r rrAr+ connectedrlr[localrYr-rRstrict_node_listrrrrinputrkr^repr)rmrrrCrCrF display_nodess*  $  zSoSCollector.display_nodescCs"d}i}|jjr t|jj|d<|jjr0d|d<|jjr@d|d<|jjrPd|d<|jjrltt|jj|d<|jjrt|jj|d<|jj rt|jj |d <|jj d krt|jj |d <x*|j D]\}}|d |d |d 7}qW|j }|j d|d|jd<||jd<|jjd|dS)z:Configures the sos report command that is run on the nodeszsosreport --batch zcase-idrrzall-logsr:zlog-sizesysrootrrzcompression-typez--rHzInitial sos cmd set to sos_cmd sos_optionsZinitial_sos_cmdN)rYrrrrr:r)rrrcompression_typerrstriprerrrUrV)rmrrkvrCrCrFconfigure_sos_cmds2   zSoSCollector.configure_sos_cmdcCsry.t|jj|j|_|jjd|jjdWn>tk rl}z"|jd||jddWYdd}~XnXdS)zgIf run with --primary, we will run cluster checks again that instead of the localhost. z Connected to z, determining cluster type...z#Failed to connect to primary node: z.Could not connect to primary node. Aborting...rpN) rrYr+rrr rr^rerl)rmrrCrCrFrs zSoSCollector.connect_to_primarycCst|jj}x|jjD]}|j||j|_|jr|jj}|jd|dxb|D]Z}t |j|jrX|jj}|jd|d|j|_|jrX|jd|d|d|}PqXW||_ |j |_ |j |j d<|jjd |j PqWd S) a@This sets the cluster type and loads that cluster's cluster. If no cluster type is matched and no list of nodes is provided by the user, then we abort. If a list of nodes is given, this is not run, however the cluster can still be run if the user sets a --cluster-type manually zInstallation matches z, checking for layered profileszLayered profile z found. Checking installationz*Installation matches both layered profile z and base profile z), setting cluster type to layered profilerRzCluster type set to N)r\rbvaluesrr+Z check_enabledrorre issubclassrRrrrrr r)rmZchecksrRZcnameZ remainingZrnamerCrCrFrs,     zSoSCollector.determine_clustercCs(|jr$|jj}|jd||SgS)z>Collects the list of nodes from the determined cluster clusterz Node list: )rrRZ _get_nodesre)rmr,rCrCrFget_nodes_from_cluster(s  z#SoSCollector.get_nodes_from_clustercCs|j|jkr"|jjr"|jj|j|jjsPx$|jD]}||jkr2|jj|q2W|jdk r|jj rx.|jD]$}||jj|jjfkrl|jj|qlWt t dd|jD|_|j d|j|j j d|jdS)zSReduce duplicate entries of the localhost and/or primary node if applicableNcss|]}|r|VqdS)NrC)rDnrCrCrFrJ?sz0SoSCollector.reduce_node_list..zNode list reduced to rA)r[rArYr-rrRrr]r+r\setrerUrW)rmrEr(rCrCrFreduce_node_list0s   zSoSCollector.reduce_node_listcCsrxl|jjD]`}ytj|}tj||r*dSWq tjk rh}zd}|j||||fWYdd}~Xq Xq WdS)zCompares a discovered node name to a provided list of nodes from the user. If there is not a match, the node is removed from the listTz0Error comparing %s to provided node regex %s: %sNF)rYr,fnmatch translaterrrre)rmrZregexrrrCrCrFcompare_node_to_regexCs  *z"SoSCollector.compare_node_to_regexcs |j r |j r d}|j|dy@|j}|jjrXx*|D]|jr8|jjq8Wn||_Wnxt k r}z\|j d||j d|jj|_x0|jD]&t fdddDr|jj qWWYd d }~XnX|jjr8xR|jjD]Ft fdddDr q|jkr|j dd|jjqW|js|j jdd}x0|jD]&|jddkrX|jj qXW|jjs|jj|j |jy,tt|jtd}t||jd|jd<Wn8ttfk r}z|j d|WYd d }~XnXd S)z4 Sets the list of nodes to collect sos reports from zaCould not determine a cluster type and no list of nodes or primary node was provided. Aborting...rpzError parsing node list: z#Setting node list to --nodes optionc3s|]}|kVqdS)NrC)rDrE)rrCrFrJesz)SoSCollector.get_nodes..*\?()rNc3s|]}|kVqdS)NrC)rDrE)rrCrFrJksz*\?()/[]z Force adding z to node listr}r)rrzCould not set UI spacing: )r.r/r0r1r2r)r+rRrlr'rYr,r-rArr^reanyrr[rrr*rrrr TypeError ValueError)rmrr,rhostZ _node_maxrrC)rrFrPsJ       "    zSoSCollector.get_nodesc Csynt|d|j|dd}|j|j|jrd|jj||jjj |d|j t |jj|dn|j Wnt k rYnXdS)zTry to connect to the node, and if we can add to the client list to run sos report on Positional arguments node - a tuple specifying (address, password). If no password, set to None rrp)r0N)rrrZ set_clusterrRrrPrrUr,rTrr disconnectr^)rmrclientrCrCrF_connect_to_nodes    zSoSCollector._connect_to_nodecCsd}|jjdtd|j||j}|jj|d}|jjsyt||jjdWnLtk rx|j ddYn.t k r}z|j |dWYd d }~XnXd S) zmPrint the intro message and prompts for a case ID if one is not provided on the command line ahThis utility is used to collect sos reports from multiple nodes simultaneously. Remote connections are made and/or maintained to those nodes via well-known transport protocols such as SSH. An archive of sos report tarballs collected from the nodes will be generated in %s and may be provided to an appropriate support representative. The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party. No configuration changes will be made to the system running this utility or remote systems that it connects to. z sos collect (version z) z, Press ENTER to continue, or CTRL-C to quit rzExiting on user cancelrKrpN) r rr r rrYrrrkrlr^)rmZ disclaimerZ intro_msgr rrCrCrFintros zSoSCollector.introcCs|jjr|j|j|j|jjr<|jjr<|jdd|j|j|j|j |_ |j |j d|j j |_|j jdd|j|jdS)Nz sos-collector was called with incompatible options --batch and --password. If you need to use --password, please omit batch mode. rp)rsos_logsi)rYr(rlr:rr0r$rrr archive_nameZ setup_archivearchiveZget_archive_path archive_pathrr?)rmrCrCrFexecutes"  zSoSCollector.executec sVt|jj|jjg|jjrDjt|js6|jj rD|j j |j|j j dfdd|jD}|j jrg}x@|D]8}d|j jd|dd}t|}|j |d|fqvW|}yt|j j}|j|j|dd |jd d |j jo|j djd kr |j jdt|j |_|jdkr0|jd dn*|jdkrZ|j djd krZ|jdd|j j d|jd|j jdt|j j}|j|j|j dd |jd d t|j j}|j|j|j dd |jd d Wnbtk r|jddd dYn>tk r6}z d|}|j|dd dWYdd}~XnXt|jdrn|j j d|jj } | rn|jj!| d}|j"||j#|jf|j$|j#dkr|j%|_&nd}|j|d|j j's|j j(rRyN|j)|j*|j+|j |j,d} t-|j.|j/|j0d | |j&d} | j1|j j dWn6tk rP}z|j j2d|WYdd}~XnXdS)zY For each node, start a collection thread and then tar all collected sos reports z Connecting to nodes...csg|]}|kr|dfqS)NrC)rDr()filtersrCrFrsz(SoSCollector.collect..zPlease enter the password for @rz: rp)Z chunksizeT)waitr zNo nodes connected. Aborting...zCollection would only gather from localhost due to failure to either enumerate or connect to cluster nodes. Assuming single collection from localhost is not desired. Aborting...z* Beginning collection of sos reports from z nodes, collecting a maximum of z concurrently zExiting on user cancel rK)rzCould not connect to nodes: NZ run_extra_cmdz/Collecting additional data from primary node...z+ Successfully captured %s of %s sos reportsz4No sos reports were collected, nothing to archive...)rrsys_tmprrS)rnargscmdlinein_place hook_commonsr=zUploaded archive successfullyzUpload attempt failed: )3r)r+rr[r intersectionrArRrrPrr rrYr1r7rrr#mapr9Zshutdownr-poprZ report_numrl_finalize_sos_cmd_collectrkr^hasattrZ_run_extra_cmdZcollect_extra_cmdrrQrcreate_cluster_archiverr<r=rrrCrSrrnrDrEr?r) rmr,Z_nodesrrZnode_pwdZpoolZnpoolrfilesrGZuploaderrC)r@rFr?s              "          zSoSCollector.collectcCsLy |jWn:tk rF}z|jd|jd|WYdd}~XnXdS)zCalls finalize_sos_cmd() on each node so that we have the final command before we thread out the actual execution of sos z#Could not finalize sos command for z: N)Zfinalize_sos_cmdr^r_r)rmr8rrCrCrFrK7s zSoSCollector._finalize_sos_cmdcCspy8|js|jn|jjs"|j|jr6|jd7_Wn2tk rj}z|jd|WYdd}~XnXdS)zRuns sos report on each noderpzError running sos report: N)rZ sosreportrYr-rQr^r_)rmr8rrCrCrFrLAs zSoSCollector._collectcCs4x.|jD]$}|jr|jd|j|jqWdS)zClose all sessions for nodeszClosing connection to N)rPrrerr7)rmr8rCrCrFrNs z"SoSCollector.close_all_connectionscCsd}g}x(|jD]}x|jD]}|j|qWqWd}|jjr|j|j|j|j|jd}y8|j j dt d|d}|j |j|j \}}d}Wn4tk r}z|j jd|WYdd}~XnXy|jdx|D]}|jd d } |r|j| } tjj|j|} |jj| | d |r|j|} | rtjjd |jd d!} | d 7} |jj| | qW|jj|jtjjddd |jj|jtjjddd |jdk r|jj|jj|j|rtjj|j|jj} |j tjj| dd|j tjj| dd|j tjj| dd|jj!dd} tjj|jtjj"| }|rT|j|j#dd}tj$| ||r|jtjj|j|j%d}tj$|||j j d||j&j d||j j d|j j d|d|Stk r}z"d|d|j'}|j(|ddSd}~XnXdS)"zcCalls for creation of tar archive then cleans up the temporary files created by sos collectNF)rrrCrrSrT)rFrGz$ERROR: unable to obfuscate reports: z"Creating archive of sos reports...rrp)rZ checksumsz.sha256r;zsos.logzui.logZ sos_reportsz manifest.json)methodz.tarz-obfuscated.tarZ _private_mapz2A mapping of obfuscated elements is available at zArchive created as zP The following archive has been created. Please provide it to your support team.rrzCould not finalize archive: z. Data may still be available uncompressed at rz Archive errorrQ))rPZ file_listrrYrrrrCrSr rrZset_target_pathr?r^rrrZobfuscate_stringrNrvrfr=Zadd_fileZget_new_checksumZ add_stringZ sos_log_fileZsos_ui_log_fileZadd_final_manifest_datar Z_obfuscate_upload_passwords_nameZobfuscate_filefinalizebasenamereplacerenamer<rr>rl)rmr*Z arc_pathsr6rZdo_cleanrGZcleanerrrrZchecksumZ_dirrZ final_nameZmap_namerrCrCrFrNUs      $             z#SoSCollector.create_cluster_archive)NrF)0r __module__ __qualname__rZdescZ arg_defaultsrMra classmethodrqryrrcrrrlr`rdrjrrrr_rer(rrrrrrrr$rrr'r*r-rr9r:r?r?rKrLrrN __classcell__rCrC)rorFr(s 2  ! m   (&  % 0!e  r)#r+rrrNrrrrZrrgrconcurrent.futuresrrZpathlibrZshlexrZ sos.cleanerrZsos.collector.sosnoderZ sos.optionsr r Z sos.componentr Z sos.utilitiesr rsr Z sos.uploadrrrrCrCrCrF s.