관리-도구
편집 파일: stat_sender.cpython-37.pyc
B � d� � @ sd d Z dZddlZddlZddlZddlmZ ddlmZ ddl m Z mZ ddlm Z ddlmZ dd lmZmZ dd lmZ ddlmZ ddlmZ d dlmZ d dlmZ ddlmZ ddlm Z ddl!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( G dd� de�Z)e*dk�r`e&� ej+dej,d� ye)� �-� W n4 e k �r^ Z. ze/e.� e0d ��W ddZ.[.X Y nX dS )zd This module contains SSA classes for sending e-mails with report and sending reports to ClickHouse zssa.modules� N)�EmailMessage)�partial)�Optional�Any)�get_admin_email)�is_cl_solo_edition)�Session�Response)�HTTPAdapter)�RequestException)�Retry� )�Common)� DecisionMaker� )�stat_server)�SSAError)�Mailer�render_report_table)�read_sys_id�sentry_init� duration_cast�format_datec s� e Zd ZdZ� fdd�Zdedd�dd�Zeee d�d d �Z ee d�dd �Zee d�dd�Zee d�dd�Zeeed�dd��Zeed�dd�Zee d�dd�Z� ZS )�StatisticsSenderz4 Send report to ClickHouse and over e-mails c s� t � �� t�d�| _| j�dt� t� | _dt � d�| _ t� | _t dtdg�tddd g�dd �}t|d�}t� | _| j�d|� t| jjdd �| j_d S )N�stat_senderzStatisticsSender enabled: %szhttps://z /api/clos-ssa� �POSTi� i� i� )�total�method_whitelist�status_forcelist�backoff_factor)Zmax_retries� )�timeout)�super�__init__�logging� getLogger�logger�info�__package__r �sys_idr �ch_endpointr �mail_senderr � frozensetr r �sessionZmountr �request)�selfZ retry_conf�adapter)� __class__� �H/opt/alt/python37/lib/python3.7/site-packages/ssa/modules/stat_sender.pyr$ * s zStatisticsSender.__init__N)�report�returnc C s0 |dkrt � �� }| jr"| �|� | �|� dS )zi Send given report over e-mail If no report given, get it from DecisionMaker API N)r �get_json_report�summary_notification_enabled�email_report�clickhouse_report)r0 r5 r3 r3 r4 �send; s zStatisticsSender.send)�report_viewr6 c C s� | � � }|r�|�d�r�t|�\}}| jj|dt|d �|d�}|jt�|�dd|d � d�d� |j|d d|d � d �d� | j� |� |S dS )z4 Create and send e-mail with report �domainsZ ssa_report�date)Z recipient�templater>