U
    -_g	                     @   s.   d dl Z d dlmZmZ G dd deeZdS )    N)PluginIndependentPluginc                   @   s,   e Zd ZdZdZdZdZdd Zdd Zd	S )
ElasticzElasticSearch serviceZelastic)services)Zelasticsearchc           	   
   C   s   d}d}zt |dd}|D ]t}td|}td|}|rlt| dkrl| d  }td	d
|}q|rt| dkr| d  }qW 5 Q R X W n8 tk
r } z| d| d|  W 5 d}~X Y nX ||fS )z Get hostname and port number Z	localhostZ9200zUTF-8)encodingz(^network.host):(.*)z(^http.port):(.*)   z"|\' zFailed to parse z: N)	openresearchlengroupsstripsub	ExceptionZ	_log_info)	selfels_config_fileZhostnameportZfreadlineZnetwork_hostZnetwork_porterr r   </usr/lib/python3/dist-packages/sos/report/plugins/elastic.pyget_hostname_port   s      (zElastic.get_hostname_portc                 C   s   |  d}| | | dr*| d n
| d | |\}}|d | }| d| dd| dd| d	d| d
d| dd| dd| dg d S )Nz$/etc/elasticsearch/elasticsearch.ymlZall_logsz/var/log/elasticsearch/*z/var/log/elasticsearch/*.log:zcurl -X GET 'z/_cluster/settings?pretty'z/_cluster/health?pretty'z/_cluster/stats?pretty'z/_cat/nodes?v'z/_cat/indices'z/_cat/shards'z/_cat/aliases')Z	path_joinZadd_copy_specZ
get_optionr   Zadd_cmd_output)r   r   Zhostr   Zendpointr   r   r   setup*   s$    









zElastic.setupN)	__name__
__module____qualname__Z
short_descZplugin_nameZprofilesZpackagesr   r   r   r   r   r   r      s   r   )r   Zsos.report.pluginsr   r   r   r   r   r   r   <module>   s   