K<]c @s8dZddklZddklZlZlZlZlZddk Z ddk Z ddk Z ddk Z ddk l Z ddkZddkZdZdZdZd Zd efd YZd efd YZdefdYZdefdYZdefdYZedZdS(s; This exports methods available for use by plugins for sos i(twith_statement(tsos_get_command_outputt import_moduletgreptfileobjttailN(ttimec CsdyIt|ii}z)|~}ti||itiSWdQXWntj ogSXdS(s=Return a list of all non overlapping matches in the string(s)N(Rt__exit__t __enter__tretfindalltreadt MULTILINEtAttributeError(tregextfnamet_[1]tf((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt regex_findall s #&cCsYtidd|}tidd|}tidd|id}|d|!}|S( Ns^/(usr/|)(bin|sbin)/ts [^\w\-\.\/]+t_t/t.s ._-i(R tsubtstrip(tcommandtname_maxt mangledname((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_mangle_command)s  cstfd|DS(Nc3sx|]}|jVqWdS(N((t.0tp(tpath(s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pys 2s (tany(Rt path_list((Rs8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_path_in_path_list1scCshtidftidftidftidfg}x+|D]#}|d|io |dSq=WdS(s return a string indicating the type of special node represented by the stat buffer st (block, character, fifo, socket). s block devicescharacter devices named pipetsocketiiN(tstattS_ISBLKtS_ISCHRtS_ISFIFOtS_ISSOCKtst_mode(tstt_typestt((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _node_type5s   tPlugincBs<eZdZd7ZeZdZd8Zd9Z d7Z d:Z dZ e dZdZdZdZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZd7dZdZ dZ!dZ"ddZ#dd7dZ$d7edZ%dZ&dd7dZ'dd7d Z(d!Z)d7d7dd7d"Z*d7ed#Z+d$Z,d%Z-d&Z.d'Z/d7e0dd7d(Z1d)Z2d*Z3d+Z4d,Z5d-Z6d.Z7d/Z8d0Z9d1Z:d2Z;d3Z<d4Z=d5Z>d6Z?RS(;s@ This is the base class for sosreport plugins. Plugins should subclass this and set the class variables where applicable. plugin_name is a string returned by plugin.name(). If this is set to None (the default) class_.__name__.tolower() will be returned. Be sure to set this if you are defining multiple plugins that do the same thing on different platforms. requires_root is a boolean that specifies whether or not sosreport should execute this plugin as a super user. version is a string representing the version of the plugin. This can be useful for post-collection tooling. packages (files) is an iterable of the names of packages (the paths of files) to check for before running this plugin. If any of these packages or files is found on the system, the default implementation of check_enabled will return True. profiles is an iterable of profile names that this plugin belongs to. Whenever any of the profiles is selected on the command line the plugin will be enabled (subject to normal check_enabled tests). t unversionedcCst|dtp g|_ng|_g|_g|_d|_g|_g|_||_ g|_ t |_ g|_ g|_d|i jo|i dn tid|_xV|iD]K}|ii|d|iih|dd6|dd 6|d d 6qWdS( Nt option_listRtsoslogtsosiitdescitspeeditenabled(tgetattrtFalseR0t copied_filestexecuted_commandstalertst custom_textt opt_namest opt_parmstcommonstforbidden_pathstsett copy_pathst copy_stringst collect_cmdstloggingt getLoggerR1tappend(tselfR>topt((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt__init__es(             "cCs|io|iS|iiS(s^Returns the plugin's name as a string. This should return a lowercase string. (t plugin_namet__name__tlower(tclass_((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytname~s cCsd|i|fS(Ns[plugin:%s] %s(RN(RGtmsg((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _format_msgscCs|ii|i|dS(N(R1terrorRP(RGRO((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _log_errorscCs|ii|i|dS(N(R1twarningRP(RGRO((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _log_warnscCs|ii|i|dS(N(R1tinfoRP(RGRO((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _log_infoscCs|ii|i|dS(N(R1tdebugRP(RGRO((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _log_debugscCs |idS(Ntpolicy(R>(RG((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyRYscCs|ii|dj S(s'Is the package $package_name installed?N(RYt pkg_by_nametNone(RGt package_name((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt is_installedsc CsMd|d}|id|||f|ipdSd }yx|iD]}|dd joqJnti|d|otii|id|d}|id||ii |}t i |||i \} }|o|ii | |qqJqJWWn<tj o0} d} |i| |d| fd }nX|S( s_Apply a regexp substitution to command output archived by sosreport. cmd is the command name from which output is collected (i.e. excluding parameters). The regexp can be a string or a compiled re object. The substitution string, subst, is a string that replaces each occurrence of regexp in each file collected from cmd. Internally 'cmd' is treated as a glob with a leading and trailing '*' and each matching file from the current module's command list is subjected to the replacement. This function returns the number of replacements made. t*s4substituting '%s' for '%s' in commands matching '%s'itfiletexetcmddirsapplying substitution to '%s's-regex substitution failed for '%s' with: '%s'N(RXR9R[tfnmatchtosRtjoinR>tarchivet open_fileR tsubnR t add_stringt ExceptionRR( RGtcmdtregexptsubsttglobstrt replacementstcalledRtreadabletresultteRO((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytdo_cmd_output_subs0     # c Csy|i|}|id|||f|pdS|ii|}ti|||i\}}|o|ii||nd}Wn8tj o,}d} |i | ||fd}nX|S(sgApply a regexp substitution to a file archived by sosreport. srcpath is the path in the archive where the file can be found. regexp can be a regexp string or a compiled re object. subst is a string to replace each occurance of regexp in the content of srcpath. This function returns the number of replacements made. s"substituting '%s' for '%s' in '%s'is-regex substitution failed for '%s' with: '%s'( t_get_dest_for_srcpathRXReRfR RgR RhRiRR( RGtsrcpathRkRlRRpRqRnRrRO((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt do_file_subs  !  c Cst|dpti|}n|i}g}|iD]"}||do ||q:q:~}x%|D]}|i|d||qlWdS(szApply a regexp substituation to a set of files archived by sos. The set of files to be substituted is generated by matching collected file pathnames against pathexp which may be a regular expression string or compiled re object. The portion of the file to be replaced is specified via regexp and the replacement string is passed in subst.tmatchRuN(thasattrR tcompileRwR8Rv( RGtpathexpRkRlRwRRt file_listR_((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytdo_path_regex_subs 9cCs t||S(N(R(RGRR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytdo_regex_find_allscCsoti|}tiitii||}tii|}tii|o<tii|tii|}|id||fn|}|id||tii |f|i i ||tii |o|id|dS|id||f||jo|i |n|id||i ih|d6|d6dd 6|d 6dS( Ns&made link target '%s' relative as '%s's0copying link '%s' pointing to '%s' with isdir=%ss%link '%s' is a directory, skipping...s#normalized link target '%s' as '%s's.link '%s' points to itself, skipping target...Rutdstpathtyestsymlinktpointsto(RctreadlinkRRdtdirnametnormpathtisabstrelpathRXtisdirRetadd_linkt _do_copy_pathR8RF(RGRutlinkdesttdesttabsdesttreldest((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _copy_symlinks0!!     cCsWxPti|D]?}|id||f|itii||ddqWdS(Ns!recursively adding '%s' from '%s'R(RctlistdirRXRRRdR[(RGRutafile((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _copy_dirs  cCs2x+|iD] }||djo |dSq WdS(NRuR~(R8R[(RGRutcopied((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyRts   cCst||iS(N(R"R?(RGR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_is_forbidden_path$scCsSti|i}ti|i}|i}|ii||ti||dS(N(Rctmajortst_rdevtminorR)Retadd_nodetmakedev(RGRR*tdev_majtdev_mintmode((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt _copy_node's cCs|i|o|id|dS|p |}nyti|}Wn+ttfj o|id|dSXti|i o|i |dSti |i o|i |dSti |i pti |i p8t|}|id||f|i||dS|id||f|i d@p|iid|n|ii|||iih|d6|d 6d d 6dS( sCopy file or directory to the destination tree. If a directory, then everything below it is recursively copied. A list of copied files are saved for use later in preparing a report. sskipping forbidden path '%s'Rsfailed to stat '%s'Ns creating %s node at archive:'%s's!copying path '%s' to archive:'%s'i$RuR~tnoR(RRXRctlstattOSErrortIOErrorRVR$tS_ISLNKR)RtS_ISDIRRtS_ISREGR-RReRhtadd_fileR8RF(RGRuRR*tntype((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR.s:   &  cCs.x'ti|D]}|ii|qWdS(sWSpecify a path to not copy, even if it's part of a copy_specs[] entry. N(tglobR?RF(RGt forbiddenPathtfilespec((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytadd_forbidden_path^scCs|i|ifS(s%return a list of all options selected(R<R=(RG((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytget_all_optionsfscCsJxCt|i|iD](\}}||jo||dRR<R=R[tgett iteritems( RGRtdefaulttglobal_optionsRRNRtvaltitemsRR((Rs8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt get_optionss          t,c Csq|i|}yGg}|i|D]}||iq&~}ttd|SWntj o|SXdS(sTWill try to return the option as a list separated by the delimiter. N(RtsplitRtlisttfilterR[Ri(RGRt delimiterRtoptionRRHtopt_list((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytget_option_as_lists 0c Cs|o t|ptSti|}|it|djodSd}t}|d9}d}xT|D]L}|ti|ti7}|o||jo t}Pn|i |qmW|o|o|}|dti jo|i ti }n|i ti i dd} |it||| ti idti i|} ti i| d|i| } |ii| |ndS( sAdd a file or glob but limit it to sizelimit megabytes. If fname is a single file the file will be tailed to meet sizelimit. If the first file in a glob is too large it will be tailed to meet the sizelimit. iNiRs.tailedRt sos_stringsi(tlenR7RtsortR[RcR$tST_SIZERt add_copy_spectseptlstriptreplaceRtadd_string_as_fileRRRRdRNReR( RGtcopyspect sizelimitttailittfilest current_sizet limit_reachedt_filet file_nametstrfiletrel_patht link_path((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytadd_copy_spec_limits6  !cCst|to |g}nxd|D]\}|o t|p|idtS|i|}|ii||id|q$WdS(szAdd a file specification (can be file, dir,or shell glob) to be copied into the sosreport by this module. sadded null or empty copy specsadded copyspec '%s'N( t isinstancet basestringRRTR7t_expand_copy_specRAtupdateRV(RGt copyspecsRRA((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyRs  i,cCst|d|d|}|ddjo|id||fn|ddjp|ddjo|id|n|S( Nttimeouttrunattstatusi|s command '%s' timed out after %dsi~is%could not run '%s': command not found(RRTRX(RGtprogRRRq((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytget_command_outputs "cCs|i|d|d|S(s[Execute a command independantly of the output gathering part of sosreport. RR(R(RGRRR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt call_ext_progscCs|i|ddjS(sExecute a command independently of the output gathering part of sosreport and check the return code. Return True for a return code of 0 and False otherwise. Ri(R(RGR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytcheck_ext_progsc Cst|to |g}nt|djo|p|o|idnx[|D]S}|||||f}d}|i|||ii||id|qVWdS(s:Run a program or a list of programs and collect the outputis.ambiguous filename or symlink for command lists2packed command tuple: ('%s', '%s', '%s', %s, '%s')sadded cmd output '%s'N(RRRRTRXRCRFRV( RGtcmdstsuggest_filenamet root_symlinkRRRjtcmdtt_logstr((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytadd_cmd_outputs !cCsctii|iid|i}|otii||}n|oti|n|S(s[Return a path into which this module should store collected command output t sos_commands(RcRRdRet get_tmp_dirRNtmakedirs(RGRNtmaketcmd_output_path((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytget_cmd_output_pathscGs t||S(sReturns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by line. (R(RGRktfnames((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt file_grepscCs|ii}t||S(N(ReRR(RGR`R((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR scCstii|id|i|i|}tii|oQd}xHto<d||f}tii|p |}Pn|d7}qJWn|S(s@The internal function to build up a filename based on a command.Rais%s_%di(RcRRdR>RNRtexistsR(RGR`toutfntinctnewfn((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_make_command_filenamescCsQ|ii||fd|ididd}|id||fdS(s6Add a string to the archive as a file named `filename`s...itutf8tignoresadded string '%s' as '%s'N(RBRFt splitlinestdecodeRX(RGtcontenttfilename((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR s c CsMt}|i|d|d|}|ddjp|ddjodS|id|idt|f|o|i|}n|i|}|t|idd } |ii |d ||o|ii ||n|i i h|d 6| d 6|id i d|d|dd| tii|ii|S(s]Execute a command and save the output to a file for inclusion in the report. RRRi~iscollected output of '%s' in %siRaitoutputR`R_t xmlreporttcmdlinetexitcodetf_stdoutN(RRR[RXRRRR>ReRhRR9RFt add_commandRcRRdtget_archive_path( RGR`RRRRtstartRqRt outfn_strip((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytget_cmd_output_now&s$ "  cCs1ttd|dddjodStSdS(s?Return whether specified moudle as module_name is loaded or nott^t s /proc/modulesiN(RRR[R(RGt module_name((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytis_module_loadedGs$cCs|ii|dS(spAdd an alert to the collection of alerts for this plugin. These will be displayed in the report N(R:RF(RGt alertstring((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt add_alertOscCs|i|7_dS(svAppend text to the custom text that is included in the report. This is freeform and can include html. N(R;(RGttext((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytadd_custom_textUscCs ti|S(N(R(RGR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR[scCs6x/|iD]$}|id||i|q WdS(Nscollecting path '%s'(RARVR(RGR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_collect_copy_specs^s c Csxt|iD]n}|d\}}}}}|idd|d|id||i|d|d|d|d|qWdS( Nisunpacked command tuple: s('%s', '%s', '%s', %s, '%s')scollecting output of '%s'RRRR(RRCRXRVR (RGtprogsRRRRR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_collect_cmd_outputcs c Csx|iD]\}}d}||ididd7}|id||fy/|ii|tiid|i |Wq t j o }|i d||fq Xq WdS(Ns...iRRscollecting string '%s' as '%s'Rscould not add string '%s': %s( RBRRRVReRhRcRRdRNRiRX(RGtstringRRRr((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt_collect_stringsms       cCsUt}|i|i|i|it|f}|id|dS(sCollect the data for a plugin.scollected plugin '%s' in %sN(RRRRRNRX(RGR tfields((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytcollect|s     cCsTyEt|do|io|iiSt|i|iiSWndSXdS(s9 This function will return the description for the plugint__doc__sN(RxRRtsupert __class__(RG((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytget_descriptions csip iotitoig_ntitoig_ntdiDptfdiDStS(sThis method will be used to verify that a plugin should execute given the condition of the underlying environment. The default implementation will return True if neither class.files or class.packages is specified. If either are specified the plugin will check for the existence of any of the supplied files or packages and return True if any exist. It is encouraged to override this method if this behavior isn't applicable. css%x|]}tii|VqWdS(N(RcRR(RR((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pys s c3s"x|]}i|VqWdS(N(R](Rtpkg(RG(s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pys s (RtpackagesRRR R(RG((RGs8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt check_enableds cCstS(swThis decides whether a plugin should be automatically loaded or only if manually specified in the command line.(R(RG((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytdefault_enabledscCs|it|idS(sCollect the list of files declared by the plugin. This method may be overridden to add further copy_specs, forbidden_paths, and external programs if required. N(RRR(RG((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytsetupscCsdS(sLPerform any postprocessing. To be replaced by a plugin if required. N((RG((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytpostprocscCsd|i}|d|id}t|io}|d}xb|iD]W}|dd|d|df}|d d jo|d |d }n|d }qLW|d}nt|io|d}xx|iD]m}|doJt|do9d|idd|d}|d||df}q|d|d}qW|d}nt|io:|d}x|iD]}|d|}q|W|d}n|idjo|d}||id}n|S(sm Present all information that was gathered in an html file that allows browsing the results. s
s

Plugin s

s

Files copied:

    s
  • %ss..R~RuRRs (symlink to %s)Rs
  • s

s

Commands Executed:

    R_s../RaRs
  • %s
  • R`s
  • %s
  • s

    Alerts:

      Rs

      Additional Information:
      s

      (RNRR8R9R>R:R;(RGthtmlRRjt cmd_rel_pathtalert((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pytreports@       N((((@RKt __module__RR[RJRt requires_roottversionR RRetprofilesRIt classmethodRNRPRRRTRVRXRYR]RsRvR|R}RRRtRRRRRRRRRRRRRRRRRRRR7R RRRRRRRRRR!R"R#R$R((((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR.Dsz         '    )     0   ! $                   t RedHatPlugincBseZdZRS(sBTagging class to indicate that this plugin works with CentOS Linux(RKR)R(((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR.st UbuntuPlugincBseZdZRS(sBTagging class to indicate that this plugin works with Ubuntu Linux(RKR)R(((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR/st DebianPlugincBseZdZRS(sBTagging class to indicate that this plugin works with Debian Linux(RKR)R(((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR0stIndependentPlugincBseZdZRS(s@Tagging class that indicates this plugin can run on any platform(RKR)R(((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyR1scCs+d|}|p tf}nt||S(sImport name as a module and return a list of all classes defined in that module. superclasses should be a tuple of valid superclasses to import, this defaults to (Plugin,). ssos.plugins.%s(R.R(RNt superclassest plugin_fqname((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyt import_plugins  (Rt __future__Rt sos.utilitiesRRRRRRcRR R$RRDRbRRR"R-tobjectR.R.R/R0R1R[R4(((s8/usr/lib/python2.6/site-packages/sos/plugins/__init__.pyts*(