
    ~ gG'                     :    S SK r S SKJrJrJr   " S S\\\5      rg)    N)PluginRedHatPluginUbuntuPluginc                   H    \ rS rSrSrSrSrSrSrSr	Sr
S	 rS
 rS rS rSrg)CephMON   a:  
This plugin serves to collect information on monitor nodes within a Ceph
or microceph cluster. It is designed to collect from several versions of
Ceph, including versions that serve as the basis for RHCS 4 and RHCS 5.

Older versions of Ceph will have collections from locations such as
/var/log/ceph, whereas newer versions (as of this plugin's latest update)
will have collections from /var/log/ceph/<fsid>/. This plugin attempts to
account for this where possible across the host's filesystem.

Users may expect to see several collections twice - once in standard output
from the `ceph` command, and again in JSON format. The latter of which will
be placed in the `json_output/` subdirectory within this plugin's directory
in the report archive. These JSON formatted collections are intended to
aid in automated analysis.
zCEPH monceph_mon)storagevirt	containerceph)zceph-(.*-)?mon.*)z/var/lib/ceph/mon/*z/var/lib/ceph/*/mon*%/var/snap/microceph/common/data/mon/*r   c                    U R                  S5      nU R                  5       U l        U R                  R                  R                  S5      nU(       dg  U R                  SSS.5        U R                  / SQ5        U(       d  U R                  S/5        OU R                  S/5        U R                  S	S
/5        ORU R                  / SQ5        U(       d  U R                  S/5        OU R                  S/5        U R                  SS/5        U R                  SSSS9  U R                  / SQ5        U R                  S5      nUS   S:X  aY  US   R                  5        HB  nUR                  S5      (       d  M  UR                  5       S   nU R                  SU 35        MD     / SQnU R                  SSSS9  U R                  S SS!S9  U R                  U R                  5        Vs/ s H	  nS"U S#3PM     snSS$9  U R                  U Vs/ s H  nS%U 3PM
     sn5        U R                  U Vs/ s H	  nS%U S&3PM     snSSS'9  g s  snf s  snf s  snf )(Nall_logs	microceph	ceph_confceph_mon_log)z.*/ceph.confz$/var/log/ceph/(.*/)?ceph-.*mon.*.log)z/etc/ceph/*keyring*z/var/lib/ceph/**/*keyring*z/var/lib/ceph/**/tmp/*mnt*z/etc/ceph/*bindpass*z/var/log/ceph/**/*ceph-mon*.logz /var/log/ceph/**/*ceph-mon*.log*z/run/ceph/**/ceph-mon*z/var/lib/ceph/**/kv_backend)z'/var/snap/microceph/common/**/*keyring*z(/var/snap/microceph/current/**/*keyring*z./var/snap/microceph/common/data/mon/*/store.dbz"/var/snap/microceph/common/state/*z./var/snap/microceph/common/logs/*ceph-mon*.logz//var/snap/microceph/common/logs/*ceph-mon*.log*r   z"/var/snap/microceph/current/conf/*zceph reportceph_reportF)tagsstderr) z!ceph config generate-minimal-confzceph config logceph config-key dumpceph crash lszceph crash statzceph featureszceph health detailzceph insightszceph log last 10000 debug auditz!ceph log last 10000 debug clusterzceph mgr dumpzceph mgr metadatazceph mgr module lszceph mgr serviceszceph mgr versionszceph mon statzceph mon features lszceph node lszceph osd crush class lszceph osd crush dumpzceph osd crush rule lszceph osd crush show-tunablesz!ceph osd crush tree --show-shadowz ceph osd erasure-code-profile lszceph osd metadatazceph osd utilizationzceph telemetry channel lszceph telemetry collection lszceph telemetry lszceph quorum_statuszceph versionszceph-disk listr   statusr   output*zceph crash info )zconfig dumpz	device lsz	df detaildfzfs dumpzfs lsz	fs statuszmds statzmon dumpzosd blocked-byzosd blocklist lszosd df treezosd dfzosd dumpzosd numa-statuszosd perfzosd pool autoscale-statuszosd pool ls detailzosd statzpg dumpzpg statr   ztime-sync-statusz'ceph health detail --format json-prettyjson_outputceph_health_detail)subdirr   z"ceph osd tree --format json-prettyceph_osd_treezceph tell mon.z mon_status)r   zceph z --format json-pretty)r   r   )
get_optionget_ceph_versionceph_versionpolicypackage_managerpkg_by_nameadd_file_tagsadd_forbidden_pathadd_copy_specadd_cmd_outputcollect_cmd_output
splitlinesendswithsplitget_ceph_ids)	selfr   microceph_pkgcrashescrashlncid	ceph_cmdsmidcmds	            =/usr/lib/python3/dist-packages/sos/report/plugins/ceph_mon.pysetupCephMON.setup,   s   ??:. 11333??L +8F  
 ## %  ""5$  ""6$  (-   ## %  ""D$  ""E$  74  
 	MeL $
 $	L ))/:8!"8,779##C((!--/!,C''*:3%(@A :

	4 	E#0!5 	 	7 	@#0!0 	 	2 	:>:K:K:MN:M3~cU+.:MN  	 	

 	i@isuSE]i@A 	;DE9CuSE./9E  	 	
 O A Fs   &II0Ic                    U R                  S5      nUS   S:X  a4   US   R                  5       S   n[        UR                  S5      S   5      $ U R                  S	5        g! [         a  nU R	                  SU 35         SnAN5SnAff = f)
z$Get the versions of running daemons zceph --versionr   r   r      .z"Could not determine ceph version: Nz?Failed to find ceph version, command collection will be limited)exec_cmdr.   int	Exception
_log_debug
_log_error)r0   ver_vererrs       r8   r"   CephMON.get_ceph_version   s     mm,-x=AL8}**,Q/4::c?1-.. 	M	
   L"DSE JKKLs   2A! !
B	+BB	c                    / nU R                   S;   a  U R                  S5      nUS   S:X  av  US   R                  5        H_  nUR                  5       nU(       d  M  US   R	                  S5      (       d  M7   UR                  S5      nUR                  XES-      5        Ma     U$ U R                   S
:  ah  U R                  S5      nUS   S:X  aN   [        R                  " SUS   5      nUR                  UR                  5       S   R                  S5      5        U$ U$ ! [        [        4 a    U R                  S	5         GM  f = f! [         a  nU R                  SU 35         SnAU$ SnAff = f)z Get the IDs of the Ceph daemons )r      zps -u ceph -o argsr   r   r   zceph-monz--id   zUnable to find ceph IDs   zceph statusz!(\s*mon: .* quorum) (.*) (\(.*\)),zid determination failed: N)r#   r>   r,   r.   r-   indexappend
IndexError
ValueError	_log_warnresearchextendgroupsr@   rA   )	r0   ceph_idsoutprocsprocid_indexstatsretrE   s	            r8   r/   CephMON.get_ceph_ids   sf    (-- 45C8}! ]557E ;;=DtQ 0 0 < <F'+zz&'9H$OODA,>? 8(  "$MM-0EX!#G))$H$)(O5COOCJJLO$9$9#$>? x !+J7 F NN+DEEF ! GOO&?u$EFFGs+   8'DAE !EE
E1E,,E1c                     U R                   S:  a'  / SQnU H  nSU S3nU R                  SUS5        M     O,/ SQnSS	R                  U5       S
3nU R                  SUS5        U R                  S5        g )NrJ   )keyusernamepassword_secretrbd/mirror/peer/.*z(((.*)(z\\\": ))((\\\"(.*?)\\\")(.*)))r   z\2\"******\"\8)API_PASSWORDz
API_USER.*z
API_.*_KEYr^   ra   rb   z((\".*(|z)\":) \")(.*)(\".*)z\1*******\5)r#   do_cmd_output_subjoindo_cmd_private_sub)r0   keysr^   cregs       r8   postprocCephMON.postproc   s    "D !#&DE&&.6G D chhtn--@AD""*D. 	 67    )r#   N)__name__
__module____qualname____firstlineno____doc__
short_descplugin_nameprofiles
containersfilesr#   r9   r"   r/   rj   __static_attributes__ rl   r8   r   r      sB    " JK7H 'J6ELR
hB!8rl   r   )rQ   sos.report.pluginsr   r   r   r   rx   rl   r8   <module>rz      s"    
 A AC8flL C8rl   