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                   @   s4   e Zd ZdZdZdZdZdZdZdd„ Z	d	d
„ Z
dS )ÚCephMGRa?  
    This plugin is for capturing information from Ceph mgr nodes. While the
    majority of this plugin should be version-agnostic, several collections are
    dependent upon the version of Ceph installed. Versions that correlate to
    RHCS 4 or RHCS 5 are explicitly handled for differences such as those
    pertaining to log locations on the host filesystem.

    Note that while this plugin will activate based on the presence of Ceph
    containers, commands are run directly on the host as those containers are
    often not configured to successfully run the `ceph` commands collected by
    this plugin. These commands are majorily `ceph daemon` commands that will
    reference discovered admin sockets under /var/run/ceph.

    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 mgrÚceph_mgr)ÚstorageÚvirtÚ	containerÚceph)z/var/lib/ceph/mgr/*z/var/lib/ceph/*/mgr*z%/var/snap/microceph/common/data/mgr/*)zceph-(.*-)?mgr.*c                    s*  |   d¡}| jj d¡}g d¢}|  d¡}|d dkr!|g d¢7 }g d¢‰ d	}|sPd
}|  ddi¡ |  g d¢¡ |sB|  dg¡ n|  dg¡ |  g d¢¡ nd}|  ddi¡ |  dg¡ |sh|  dg¡ n|  dg¡ |  dd„ |D ƒ¡ | jdd„ |D ƒdd� |  ‡ fdd„|  	|¡D ƒ¡ d S )NÚall_logsÚ	microceph)zbalancer statuszhealthcheck history lszlog last cephadmzmgr dumpzmgr metadatazmgr module lszmgr statzmgr versionszceph orch statusÚstatusr   )zorch host lszorch device lszorch lszorch ls --exportzorch pszorch status --detailzorch upgrade status)zconfig diffzconfig showzcounter dumpzcounter schemaÚ
dump_cacheÚdump_mempoolsÚdump_osd_networkÚmds_requestsÚmds_sessionsÚobjecter_requestsz	perf dumpzperf histogram dumpzperf histogram schemazperf schemar   ÚversionÚ z/var/run/cephz"/var/log/ceph/(.*/)?ceph-mgr.*.logÚceph_mgr_log)z/etc/ceph/*keyring*z/var/lib/ceph/**/*keyring*z/var/lib/ceph/**/osd*z/var/lib/ceph/**/mon*z/var/lib/ceph/**/tmp/*mnt*z/etc/ceph/*bindpass*z/var/log/ceph/**/ceph-mgr*.logz/var/log/ceph/**/ceph-mgr*.log*)z/var/lib/ceph/**/mgr*z/var/lib/ceph/**/bootstrap-mgr/z/run/ceph/**/ceph-mgr*z/var/snap/microceph/current/runz./var/snap/microceph/common/logs/ceph-mgr.*.logz'/var/snap/microceph/common/**/*keyring*z-/var/snap/microceph/common/logs/ceph-mgr*.logz./var/snap/microceph/common/logs/ceph-mgr*.log*c                 S   s   g | ]}d |› �‘qS )úceph © ©Ú.0Úcmdr   r   ú=/usr/lib/python3/dist-packages/sos/report/plugins/ceph_mgr.pyÚ
<listcomp>’   s    z!CephMGR.setup.<locals>.<listcomp>c                 S   s   g | ]}d |› d�‘qS )r   z --format json-prettyr   r   r   r   r   r   –   s    Újson_output)Úsubdirc                    s&   g | ]}ˆ D ]
}d |› d|› �‘qqS )zceph daemon ú r   )r   Úmr   ©Úcmdsr   r   r   š   s    þÿÿ)
Ú
get_optionÚpolicyÚpackage_managerÚpkg_by_nameÚexec_cmdÚadd_file_tagsÚadd_forbidden_pathÚadd_copy_specÚadd_cmd_outputÚ	get_socks)Úselfr   Úmicroceph_pkgÚceph_mgr_cmdsÚorch_configuredÚ	directoryr   r"   r   Úsetup-   s^   


ÿÿÿþÿÿÿÿþÿzCephMGR.setupc                 C   sN   g }t  |¡D ]\}}}|D ]}| d¡r#| d¡r#| |  ||¡¡ qq|S )z¡
        Find any available admin sockets under /var/run/ceph (or subdirs for
        later versions of Ceph) which can be used for ceph daemon commands
        zceph-mgrz.asok)ÚosÚwalkÚ
startswithÚendswithÚappendÚ	path_join)r.   r2   Úceph_socketsÚrdirÚ_ÚfilesÚfiler   r   r   r-   Ÿ   s   €þzCephMGR.get_socksN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚprofilesr=   Ú
containersr3   r-   r   r   r   r   r      s    rr   )r4   Úsos.report.pluginsr   r   r   r   r   r   r   r   Ú<module>   s   
