
    -_g '                     :    d dl Z d dlmZmZmZ  G d deee      Zy)    N)PluginRedHatPluginUbuntuPluginc                   @    e Zd ZdZdZdZdZdZdZdZ	d Z
d	 Zd
 Zd Zy)CephMONan  
    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                    | j                  d      }| j                         | _        | j                  j                  j                  d      }|sb| j                  ddd       | j                  g d       |s| j                  dg       n| j                  dg       | j                  d	d
g       nM| j                  g d       |s| j                  dg       n| j                  dg       | j                  ddg       | j                  dd       | j                  g d       | j                  d      }|d   dk(  rQ|d   j                         D ];  }|j                  d      s|j                         d   }| j                  d|        = g d}| j                  ddd       | j                  ddd        | j                  | j                         D cg c]  }d!| d"
 c}d#       | j                  |D cg c]  }d$| 	 c}       | j                  |D cg c]  }d$| d%
 c}d#       y c c}w c c}w c c}w )&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_report)tags) 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)
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setupzCephMON.setup,   s   ??:. 11333??L +8F  
 ## %  ""5$  ""6$  (-   ## %  ""D$  ""E$  74  
 	M> $
 $	L ))/:8!"8,779 B##C(!--/!,C''*:3%(@AB

	4 	E#0!5 	 	7 	@#0!0 	 	2 	:>:K:K:MN3~cU+.N  	 	

 	i@suSE]@A 	;DECuSE./E  	 	
 O A Fs   H4;H9H>c                    | j                  d      }|d   dk(  r4	 |d   j                         d   }t        |j                  d      d         S | j                  d	       y# t        $ r}| j	                  d|        Y d}~4d}~ww xY w)
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)r.   ver_vererrs       r6   r    z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                    g }| j                   dv r| j                  d      }|d   dk(  ri|d   j                         D ]S  }|j                         }|s|d   j	                  d      s+	 |j                  d      }|j                  ||dz             U |S | j                   d
k\  rf| j                  d      }|d   dk(  rM	 t        j                  d|d         }|j                  |j                         d   j                  d             |S |S # t        t        f$ r | j                  d	       Y w xY w# t        $ r}| j                  d|        Y d}~|S d}~ww xY w)z! Get the IDs of the Ceph daemons )      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=   r>   )	r.   ceph_idsoutprocsprocid_indexstatsretrB   s	            r6   r-   zCephMON.get_ceph_ids   sg    (-- 45C8}! ]557 FE ;;=DQ 0 0 <F'+zz&'9H$OODA,>?F(  "$MM-0EX!#G))$H$)(O5COOCJJLO$9$9#$>? x !+J7 F NN+DEF ! GOO&?u$EFFGs+   )(D>A
D2  D/.D/2	E;EEc                     | j                   dk\  r%g d}|D ]  }d| d}| j                  d|d        n,g d}dd	j                  |       d
}| j                  d|d       | j                  d       y )NrG   )keyusernamepassword_secretrbd/mirror/peer/.*z(((.*)(z\\\": ))((\\\"(.*?)\\\")(.*)))r   z\2\"******\"\8)API_PASSWORDz
API_USER.*z
API_.*_KEYrZ   r]   r^   z((\".*(|z)\":) \")(.*)(\".*)z\1*******\5)r!   do_cmd_output_subjoindo_cmd_private_sub)r.   keysrZ   cregs       r6   postproczCephMON.postproc   s    "D  !#&DE&&.6GD chhtn--@AD""*D. 	 67    N)__name__
__module____qualname____doc__
short_descplugin_nameprofiles
containersfilesr!   r7   r    r-   rf    rg   r6   r   r      sB    " JK7H 'J6ELQ
fB!8rg   r   )rN   sos.report.pluginsr   r   r   r   rq   rg   r6   <module>rs      s"    
 A AB8flL B8rg   