U
    -Ø_g '  ã                   @   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 monZceph_mon)ZstorageZvirtZ	containerZ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¡}|sv|  dddœ¡ |  dddd	g¡ |sZ|  d
g¡ n|  dg¡ |  ddg¡ n>|  ddddg¡ |sš|  dg¡ n|  dg¡ |  ddg¡ | j	ddd |  	dddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8g ¡ |  
d¡}|d9 d:kr`|d;  ¡ D ].}| d<¡r0| ¡ d: }|  	d=|› ¡ q0d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRd9dSg}| j	dTdUdVdW | j	dXdUdYdW | j	dZd[„ |  ¡ D ƒdUd\ |  	d]d[„ |D ƒ¡ | j	d^d[„ |D ƒdUd\ d S )_NÚall_logsZ	microcephZ	ceph_confZceph_mon_log)z.*/ceph.confz$/var/log/ceph/(.*/)?ceph-.*mon.*.logz/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_backendz'/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 reportZceph_report)Útagsz!ceph config generate-minimal-confzceph config logúceph config-key dumpz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 listÚstatusr   ÚoutputÚ*zceph crash info zconfig dumpz	device lsz	df detailZ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 statztime-sync-statusz'ceph health detail --format json-prettyZjson_outputZceph_health_detail)Úsubdirr   z"ceph osd tree --format json-prettyZceph_osd_treec                 S   s   g | ]}d |› d‘qS )zceph tell mon.z mon_status© )Ú.0Zmidr   r   ú=/usr/lib/python3/dist-packages/sos/report/plugins/ceph_mon.pyÚ
<listcomp>³   s     z!CephMON.setup.<locals>.<listcomp>)r   c                 S   s   g | ]}d |› ‘qS )úceph r   ©r   Úcmdr   r   r   r   ·   s     c                 S   s   g | ]}d |› d‘qS )r   z --format json-prettyr   r   r   r   r   r   »   s     )Z
get_optionÚget_ceph_versionÚceph_versionZpolicyZpackage_managerZpkg_by_nameZadd_file_tagsZadd_forbidden_pathZadd_copy_specZadd_cmd_outputZcollect_cmd_outputÚ
splitlinesÚendswithÚsplitÚget_ceph_ids)Úselfr   Zmicroceph_pkgZcrashesZcrashlnZcidZ	ceph_cmdsr   r   r   Úsetup,   sø    

þú	ÿÿþüÿÿþÝ&
éþþþþzCephMON.setupc              
   C   s|   |   d¡}|d dkrnz$|d  ¡ d }t| d¡d ƒW S  tk
rl } z|  d|› ¡ W 5 d}~X Y nX |  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_cmdr   ÚintÚ	ExceptionÚ
_log_debugZ
_log_error)r   ZverZ_verÚerrr   r   r   r   ¿   s    
"ÿzCephMON.get_ceph_versionc           	   
   C   s   g }| j dkr–|  d¡}|d dkr”|d  ¡ D ]b}| ¡ }|r0|d  d¡r0z | d¡}| ||d  ¡ W q0 ttfk
r   |  	d	¡ Y q0X q0n†| j d
kr|  d¡}|d dkrz,t
 d|d ¡}| | ¡ d  d¡¡ W n4 tk
r } z|  d|› ¡ W 5 d}~X Y nX |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   r   r   r   ÚindexÚappendÚ
IndexErrorÚ
ValueErrorZ	_log_warnÚreÚsearchÚextendÚgroupsr!   r"   )	r   Zceph_idsÚoutZprocsÚprocZid_indexZstatsZretr#   r   r   r   r   Î   s.    



ÿ"zCephMON.get_ceph_idsc                 C   s|   | j dkr>dddddg}|D ]}d|› d}|  d	|d
¡ qn0ddddddg}dd |¡› d}|  d	|d¡ |  d	¡ d S )Nr'   ÚkeyZusernameZpasswordZ_secretzrbd/mirror/peer/.*z(((.*)(z\\\": ))((\\\"(.*?)\\\")(.*)))r	   z\2\"******\"\8ZAPI_PASSWORDz
API_USER.*z
API_.*_KEYz((\".*(ú|z)\":) \")(.*)(\".*)z\1*******\5)r   Zdo_cmd_output_subÚjoinZdo_cmd_private_sub)r   Úkeysr3   Zcregr   r   r   Úpostprocï   s8    
û
  ÿú	  ÿzCephMON.postprocN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z
short_descZplugin_nameZprofilesZ
containersÚfilesr   r   r   r   r7   r   r   r   r   r      s    !r   )r-   Zsos.report.pluginsr   r   r   r   r   r   r   r   Ú<module>	   s   