U
    *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 |ƒ€}|D ]t}t d|¡}t d|¡}|rht| ¡ ƒdkrh| ¡ d  ¡ }t dd|¡}q|rt| ¡ ƒdkr| ¡ d  ¡ }qW 5 Q R X W n4 tk
rÎ } z|  d	||f ¡ W 5 d }~X Y nX ||fS )
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   s     
 $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   