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                   @   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 mgrZceph_mgr)ZstorageZvirtZ	containerZceph)z/var/lib/ceph/mgr/*z/var/lib/ceph/*/mgr*z%/var/snap/microceph/common/data/mgr/*)zceph-(.*-)?mgr.*c                    sn  |  d}| jjd}ddddddd	d
dddg}| d}|d dkr^|dddddddg7 }ddddddddd d!d"d#d$d%dd&g d'}|sd(}| d)d*i | d+d,d-d.d/d0g |s| d1g n| d2g | d3d4d5g n>d6}| d7d*i | d8g |s| d9g n| d:g | d;d< |D  | jd=d< |D d>d? |  fd@d<| 	|D  d S )ANall_logsZ	microcephzbalancer evalzbalancer statuszbalancer status detailzhealthcheck history lszlog last cephadmzmgr dumpzmgr metadatazmgr module lszmgr serviceszmgr statzmgr versionszceph orch statusZstatusr   zorch host lszorch device lszorch lszorch ls --exportzorch pszorch status --detailzorch upgrade statuszconfig diffzconfig showzcounter dumpzcounter schemaZ
dump_cacheZdump_mempoolsZdump_osd_networkZmds_requestsZmds_sessionsZobjecter_requestsz	perf dumpzperf histogram dumpzperf histogram schemazperf schemaversion z/var/run/cephz"/var/log/ceph/(.*/)?ceph-mgr.*.logZceph_mgr_logz/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     Zjson_output)Zsubdirc                    s&   g | ]} D ]}d | d| qqS )zceph daemon  r
   )r   mr   Zcmdsr
   r   r      s    )
Z
get_optionZpolicyZpackage_managerZpkg_by_nameZexec_cmdZadd_file_tagsZadd_forbidden_pathZadd_copy_specZadd_cmd_output	get_socks)selfr   Zmicroceph_pkgZceph_mgr_cmdsZ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appendZ	path_join)r   r   Zceph_socketsZrdir_filesfiler
   r
   r   r      s    zCephMGR.get_socksN)__name__
__module____qualname____doc__Z
short_descZplugin_nameZprofilesr   Z
containersr   r   r
   r
   r
   r   r      s   ur   )r   Zsos.report.pluginsr   r   r   r   r
   r
   r
   r   <module>   s   