HEX
Server: LiteSpeed
System: Linux baran.dnsprotection.me 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: ddir12 (3618)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/glances/plugins/__pycache__/glances_connections.cpython-36.pyc
3

Eo�c��@sPdZddlmZddlmZddlmZddlmZddl	Z	Gdd�de�Z
dS)	zConnections plugin.�)�unicode_literals)�logger)�
GlancesPlugin)�	nativestrNcs�eZdZdZejejgZejej	gZ
ejejej
ejejejgZddd�Zd�fdd�	Zejejdd	���Z�fd
d�Zddd
�Z�ZS)�Pluginz5Glances connections plugin.

    stats is a dict
    z*/proc/sys/net/netfilter/nf_conntrack_countz(/proc/sys/net/netfilter/nf_conntrack_max)�nf_conntrack_count�nf_conntrack_maxNcs,tt|�j||id�d|_d|_d|_dS)zInit the plugin.)�args�configZstats_init_valueTN)�superr�__init__Z
display_curse�net_connections_enabled�nf_conntrack_enabled)�selfr	r
)�	__class__��)/usr/lib/python3.6/glances_connections.pyr1s
zPlugin.__init__cs�|j�}|jdk�r�|j�rytjdd�}Wn>tk
rj}z"tjdj|��d|_||_	|j	Sd}~XnXx(|j
D]�t�fdd�|D��|�<qtWd	}x4|jD]*�t�fd
d�|D��|�<||�7}q�W||d<d	}x4|jD]*�t�fdd�|D��|�<||�7}q�W||d
<|j
�r�x�|jD]~}y6t|j|d��}t|j�jd��||<WdQRXWn@tk
�r�}z"tjdj|��d|_
||_	|j	Sd}~XnX�q*W|dd|d|d<n|jdk�r�||_	|j	S)zRUpdate connections stats using the input method.

        Stats is a dict
        ZlocalZtcp)Zkindz*Can not get network connections stats ({})FNcsg|]}|j�kr|�qSr)�status)�.0�c)�srr�
<listcomp>Zsz!Plugin.update.<locals>.<listcomp>rcsg|]}|j�kr|�qSr)r)rr)rrrr]s�	initiatedcsg|]}|j�kr|�qSr)r)rr)rrrrbs�
terminated�r�
z*Can not get network connections track ({})r�dr�nf_conntrack_percentZsnmp)Zget_init_valueZinput_methodr
�psutil�net_connections�	Exceptionr�debug�format�stats�status_list�len�initiated_statesr�	conntrack�open�float�readline�rstrip�IOError)rr#r�err�i�fr)rr�updateBsH$z
Plugin.updatecsHtt|�j�y |jr,|jdd�|jdd<Wntk
rBYnXdS)zUpdate stats views.r)�header�
decorationN)rr�update_viewsrZ	get_alertZviews�KeyError)r)rrrr3{szPlugin.update_viewscCsZg}|js|j�r|S|js$|jr@djd�}|j|j|d��|jr�x�tjdtj	dgD]l}|j|j
��djt|�j�t
|�d�}|j|j|��dj|j||t
|�d	d�}|j|j|��qXW|j�rVd
}|j|j
��djt|�j�t
|�d�}|j|j|��djdj|jd|jd
�|t
|�d	d�}|j|j||jddd���|S)z2Return the dict to display in the curse interface.z{}zTCP CONNECTIONSZTITLErrz
{:{width}})�widthz{:>{width}}�ZTrackedz{:0.0f}/{:0.0f}rrrr2)�keyZoption)r#Zis_disabledr
rr"�appendZcurse_add_liner�CONN_LISTEN�CONN_ESTABLISHEDZcurse_new_liner�
capitalizer%Z	get_views)rr	Z	max_width�ret�msgrrrr�	msg_curse�s.
 zPlugin.msg_curse)NN)NN)�__name__�
__module__�__qualname__�__doc__rr9r:r$Z
CONN_SYN_SENTZ
CONN_SYN_RECVr&ZCONN_FIN_WAIT1ZCONN_FIN_WAIT2ZCONN_TIME_WAITZ
CONN_CLOSEZCONN_CLOSE_WAITZ
CONN_LAST_ACKZterminated_statesr'rrZ_check_decoratorZ_log_result_decoratorr0r3r>�
__classcell__rr)rrrs 8r)rBZ
__future__rZglances.loggerrZglances.plugins.glances_pluginrZglances.compatrrrrrrr�<module>
s