U
    id	                     @   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}zt |}|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   s   |  d}| | | dr*| d n
| 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 '%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curl -X GET '%s/_cat/indices'zcurl -X GET '%s/_cat/shards'zcurl -X GET '%s/_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   )Zsos.report.pluginsr   r   r
   r   r   r   r   r   <module>   s   