o
    *b
	                     @   s.   d dl mZmZ d dlZG dd deeZdS )    )PluginIndependentPluginNc                   @   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}z[t |E}|D ]:}td|}td|}|r4t| dkr4| d  }tdd|}q|rFt| dkrF| d  }qW d    n1 sQw   Y  W ||fS W ||fS  ty} } z| d	||f  W Y d }~||fS d }~ww )
NZ	localhostZ9200z(^network.host):(.*)z(^http.port):(.*)   z"|\' zFailed to parse %s: %s)	openresearchlengroupsstripsub	ExceptionZ	_log_info)	selfels_config_fileZhostnameportZfreadlineZnetwork_hostZnetwork_porte r   </usr/lib/python3/dist-packages/sos/report/plugins/elastic.pyget_hostname_port   s0   
zElastic.get_hostname_portc                 C   st   |  d}| | | dr| d n| d | |\}}|d | }| d| d| d| d	| g d S )
Nz$/etc/elasticsearch/elasticsearch.ymlZall_logsz/var/log/elasticsearch/*z(/var/log/elasticsearch/elasticsearch.log:z)curl -X GET '%s/_cluster/settings?pretty'z'curl -X GET '%s/_cluster/health?pretty'z&curl -X GET '%s/_cluster/stats?pretty'zcurl -X GET '%s/_cat/nodes?v')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   )Zsos.report.pluginsr   r   r
   r   r   r   r   r   <module>   s   
