관리-도구
편집 파일: client.cpython-311.pyc
� IMg�% � � � d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlm Z m Z d dlmZm Z mZmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ d d lmZ d d lmZm Z m!Z! d dl"m#Z# ej$ e%� � Z& G d� d e� � Z'dS )� N)� Generator�List)�APIError�APIErrorTooManyRequests� APITokenError�send_message)�license)�Core)�Message�MessageType)�MessageSink�expect)�PersistentMessagesQueue)�db)�RecurringCheckStop�recurring_check�Scope)�ServerJSONEncoderc � � e Zd ZdZ eej � dd� � � � ZdZ dZ ej Z dej fd�Zdd �Zd� Zej deej d d f fd�� � Z eej � � d edd fd�� � Z ee � � d� � � Z ed� � d� � � Z dede!fd�Z"d e!defd�Z#dd�Z$d S )�SendToServera Send messages to server. * process Reportable messages; * add them to a pending messages list; * send all pending messages to server when list is full (contains _PENDING_MESSAGES_LIMIT items or more); * send all pending messages on plugin shutdown.� IMUNIFYAV_MESSAGES_COUNT_TO_SEND� i, �2 �loopc � �N K � || _ t � � | _ t j � � | _ t j � � | _ |� | � � � � � | _ |� | � � � � � | _ d S �N) �_loopr �_pending�asyncio�Event� _try_send�Lock�_lock�create_task�_send�_sender_task�_invoke_send_message�_invoke_send_message_task)�selfr s �S/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/client.py�create_sinkzSendToServer.create_sink1 s � � � ��� �/�1�1�� � �������\�^�^�� � �,�,�T�Z�Z�\�\�:�:���)-�)9�)9��%�%�'�'�* � * ��&�&�&� �returnNc � �� K � t j | � � � | j � � � d{V �� n�# t j $ r� t � d| j � � | j � � � s\| j � � � t j t j � � 5 | j � d{V �� ddd� � n# 1 swxY w Y Y nw xY w| j j dk rrt � d| j j � � | j � � � t � d| j � � � � � dS dS )a When shutdown begins it gives 50 seconds to send _pending messages to the server (after 60 seconds process will bi killed by systemd) If stop() isn't done in 50 second it terminates process of sending messages and logs error Nz5Timeout (%ds) sending messages to server on shutdown.r z&Save %s messages to persistent storagezStored queue %r)r �wait_for�stop�_SHUTDOWN_SEND_TIMEOUT�TimeoutError�logger�errorr&