File: //usr/local/lib/python3.9/site-packages/agent360/plugins/__pycache__/ping.cpython-39.pyc
a
q�dg] � @ sn d dl Z d dlmZmZmZ d dlZd dlZdd� Zd
dd�Zdd � Z G d
d� dej
�Zedkrje� �
� dS )� N)�Popen�PIPE�CalledProcessErrorc C s |� | �}|sdS |�� S d S )NF)�search�groups)Zping_output�regex�match� r �?/usr/local/lib/python3.9/site-packages/agent360/plugins/ping.py�_get_match_groups s
r Tc C sz d}d}z t | �� td�}|�� d }W n ty: Y n0 |rZ|du rT|�d�}q^|}ng }|rn|�d�}ng }||fS )N� )�stdoutr Tz\n�
)r �splitr �communicate� Exception)�Command�newlinesZOutput�Error�procZStdoutZStderrr r r
�system_command s r c C s� t j�d�st j�d�rnttd| d�d �}z$t�d�}t||�\}}}}|}W n tyh d}Y n0 �nt jdkr�ttd | d�d �}t�d�}t||�}|du r�d}n|\}}}}|}n�t jd
k�r�d}z`t ddd
| gt
t
d�}|�� \} }
| �r,ztt�
d| �d �}W n t�y( Y n0 nd}W n t�yF Y n0 |dk�r�zt�
d| �}|d �� }W n t�y� Y n0 nd}|| d�S )N�linuxZfreebsdzping -W 5 -c 1 Fr z'(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)����darwinz
ping -c 1 �win32�pingz-nz1 )r
�stderrzAverage = (\d+)s: + .+ = [0-9]{1,9}ms, .+ = [0-9]{1,9}ms, .+ = (\d+){1,9}ms)�avgping�host)�sys�platform�
startswith�strr �re�compiler r r r r �int�findallr �decode)�hostname�responseZmatcherZminpingr ZmaxpingZjitter�matchedr �out�errorZ
rxresponser r r
�collect_ping) sJ
r- c @ s e Zd ZdZ dd� ZdS )�Pluginr c C sB i }|� dd��d�}g |d<