o
    O6uf¨%  ã                   @   s4   d dl Z d dlmZmZmZ G dd„ deeeƒZdS )é    N)ÚPluginÚRedHatPluginÚUbuntuPluginc                   @   sH   e Zd ZdZdZdZdZdZdZdZ	dd	„ Z
d
d„ Zdd„ Zdd„ ZdS )Ú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                 C   sŠ  |   d¡}|  ¡ | _| jj d¡}|s9|  dddœ¡ |  g d¢¡ |s+|  dg¡ n|  dg¡ |  d	d
g¡ n|  g d¢¡ |sI|  dg¡ n|  dg¡ |  ddg¡ | j	ddd� |  	g d¢¡ |  
d¡}|d dkr‹|d  ¡ D ]}| d¡rŠ| ¡ d }|  	d|› �¡ qug d¢}| j	dddd� | j	ddd d� | j	d!d"„ |  ¡ D ƒdd#� |  	d$d"„ |D ƒ¡ | j	d%d"„ |D ƒdd#� d S )&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 dumpz!ceph config generate-minimal-confzceph config logúceph config-key dumpz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 osd crush dumpzceph osd crush show-tunablesz!ceph osd crush tree --show-shadowz ceph osd erasure-code-profile lszceph osd metadatazceph quorum_statuszceph versionszceph-disk listzceph crash lsÚstatusr   ÚoutputÚ*zceph crash info )z	device lsz	df detailÚdfzfs dumpzfs lszmds statzmon dumpzosd blocked-byz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_treec                 S   ó   g | ]}d |› d�‘qS )zceph tell mon.z mon_status© )Ú.0Úmidr   r   ú=/usr/lib/python3/dist-packages/sos/report/plugins/ceph_mon.pyÚ
<listcomp>¨   ó    z!CephMON.setup.<locals>.<listcomp>)r   c                 S   s   g | ]}d |› �‘qS )úceph r   ©r   Úcmdr   r   r   r    ¬   s    c                 S   r   )r"   z --format json-prettyr   r#   r   r   r   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_cmdsr   r   r   Úsetup,   sv   

þ	ÿÿþÿÿþ

€þþþ
þzCephMON.setupc              
   C   s~   |   d¡}|d dkr8z|d  ¡ d }t| d¡d ƒW S  ty7 } z|  d|› �¡ W Y d}~nd}~ww |  d	¡ dS )
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_cmdr2   ÚintÚ	ExceptionÚ
_log_debugÚ
_log_error)r4   ÚverÚ_verÚerrr   r   r   r&   ´   s   
€ÿÿzCephMON.get_ceph_versionc           	   
   C   s   g }| j dv rK|  d¡}|d dkrI|d  ¡ D ]0}| ¡ }|rH|d  d¡rHz| d¡}| ||d  ¡ W q ttfyG   |  	d	¡ Y qw q|S | j d
krŽ|  d¡}|d dkrŽzt
 d|d ¡}| | ¡ d  d¡¡ W |S  ty� } z|  d|› �¡ W Y d}~|S d}~ww |S )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=   r0   r2   r1   ÚindexÚappendÚ
IndexErrorÚ
ValueErrorÚ	_log_warnÚreÚsearchÚextendÚgroupsr?   r@   )	r4   Úceph_idsÚoutÚprocsÚprocÚid_indexÚstatsÚretrD   r   r   r   r3   Ã   s<   


ÿ€
÷
ÿþ€þzCephMON.get_ceph_idsc                 C   sn   | j dkrg d¢}|D ]}d|› d�}|  d|d¡ qng d¢}dd	 |¡› d
�}|  d|d¡ |  d¡ d S )NrH   )Ú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)r4   ÚkeysrZ   Úcregr   r   r   Úpostprocä   s   

ÿþ	ÿzCephMON.postprocN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚprofilesÚ
containersÚfilesr'   r:   r&   r3   rf   r   r   r   r   r      s     	!r   )rO   Úsos.report.pluginsr   r   r   r   r   r   r   r   Ú<module>   s   