????

Your IP : 3.145.105.194


Current Path : /usr/lib/python3.6/site-packages/glances/exports/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/glances/exports/__pycache__/glances_export.cpython-36.opt-1.pyc

3

Eo�cd�@sHdZddlmZddlmZmZmZmZddlm	Z	Gdd�de
�ZdS)z5
I am your father...

...for all Glances exports IF.
�)�
json_dumps)�
NoOptionError�NoSectionError�	iteritems�iterkeys)�loggerc	@s�eZdZdZdddddddd	d
g	Zd"dd
�Zdd�Zddgdfdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
d d!�ZdS)#�
GlancesExportz!Main class for Glances export IF.ZalertZamps�helpZnow�pluginZportsZprocesslistZ
psutilversionZ	quicklookNcCsN|jjtd�d�|_tjd|j�||_||_d|_d|_	d|_
d|_dS)zInit the export class.Zglances_NzInit export module %sF)�	__class__�
__module__�len�export_namer�debug�config�args�
export_enable�host�port�_last_exported_list)�selfrr�r�$/usr/lib/python3.6/glances_export.py�__init__)szGlancesExport.__init__cCstjd|j�dS)zClose the export module.zFinalise export interface %sN)rrr)rrrr�exit>szGlancesExport.exitrrcs
|pg}�jdkrdSy(x"|D]}t�|�jj||��qWWnTtk
rbtjdj|��dStk
r�}ztjdj||��dSd}~XnXx<|D]4}yt�|�jj||��Wq�tk
r�Yq�Xq�Wtjdj|��tjdj|�fdd�||D���d	S)
aGLoad the export <section> configuration in the Glances configuration file.

        :param section: name of the export section to load
        :param mandatories: a list of mandatory parameters to load
        :param options: a list of optional parameters to load

        :returns: Boolean -- True if section is found
        NFzNo {} configuration foundz"Error in the {} configuration ({})z+Load {} from the Glances configuration filez{} parameters: {}csi|]}t�|�|�qSr)�getattr)�.0�opt)rrr�
<dictcomp>csz+GlancesExport.load_conf.<locals>.<dictcomp>T)	r�setattrZ	get_valuerr�error�formatrr)rZsectionZmandatoriesZoptionsr�er)rr�	load_confBs(	



$zGlancesExport.load_confcCsPy||d}Wn$tk
r4tjdj|��YnXt|t�rH|dS|SdS)z#Return the value of the item 'key'.�keyzNo 'key' available in {}rN)�KeyErrorrr r!�
isinstance�list)r�item�retrrr�get_item_keygs
zGlancesExport.get_item_keycCsNi}|rJytdd�|jd�D��}Wn$tk
rHtjd|�i}YnX|S)z�Parse tags into a dict.

        :param tags: a comma separated list of 'key:value' pairs. Example: foo:bar,spam:eggs
        :return: a dict of tags. Example: {'foo': 'bar', 'spam': 'eggs'}
        cSsg|]}|jd��qS)�:)�split)r�xrrr�
<listcomp>{sz,GlancesExport.parse_tags.<locals>.<listcomp>�,zInvalid tags passed: %s)�dictr,�
ValueErrorr�info)rZtagsZd_tagsrrr�
parse_tagsrs
zGlancesExport.parse_tagscs�fdd�|j�D�S)z�Return the list of plugins to export.

        :param stats: the stats object
        :return: a list of plugins to export
        csg|]}|�jkr|�qSr)�non_exportable_plugins)r�p)rrrr.�sz3GlancesExport.plugins_to_export.<locals>.<listcomp>)ZgetPluginsList)r�statsr)rr�plugins_to_export�szGlancesExport.plugins_to_exportcCs|jS)z)Return the list of plugins last exported.)r)rrrr�last_exported_list�sz GlancesExport.last_exported_listcCs�|js
dS|j|�|_|j|j�d�}|j|j�d�}x�|j�D]x}t||t�rf||j||�n2t||t	�r@x"||D]}|j||�q~Wnq@|j
||�\}}|j|||�q@WdS)z�Update stats to a server.

        The method builds two lists: names and values and calls the export method to export the stats.

        Note: this class can be overwritten (for example in CSV and Graph).
        F)Zplugin_listT)rr7rZgetAllExportsAsDictr8ZgetAllLimitsAsDictr&r0�updater'�_GlancesExport__build_export�export)rr6Z	all_statsZ
all_limitsr
�i�export_names�
export_valuesrrrr9�szGlancesExport.updatecs<g}g}t|t�r�dt|�krB|dt|�krBdj||d��nd�x�t|�D]�\�}t|t�rjt|�}t|t�r�y|d}Wntk
r�d}YnXt|t�r�|j	|�\}}��fdd�|D�}||7}||7}qP|j
��j��|j
|�qPWn:t|t��r4x,|D]$}|j	|�\}}||7}||7}�qW||fS)zBuild the export lists.r$z{}.�rcs g|]}��j�t|��qSr)�lower�str)rr<)r$�pre_keyrrr.�sz0GlancesExport.__build_export.<locals>.<listcomp>)r&r0rr!r�boolrr'�
IndexErrorr:�appendr@)rr6r=r>�valueZ
item_namesZitem_valuesr(r)r$rBrZ__build_export�s6






zGlancesExport.__build_exportcCsdS)Nr)r�name�columnsZpointsrrrr;�szGlancesExport.export)NN)�__name__r�__qualname__�__doc__r4rrr#r*r3r7r8r9r:r;rrrrrs(
%&rN)rKZglances.globalsrZglances.compatrrrrZglances.loggerr�objectrrrrr�<module>s