%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/wmt/common/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/wmt/common/__pycache__/config.cpython-37.pyc

B

��wa��@s�ddlZddlZddlZddlmZmZmZddlmZddl	m
Z
ddlmZddl
mZddlmZddlmZeGd	d
�d
��ZGdd�d�ZdS)
�N)�	dataclass�asdict�field)�CONFIG_PATH)�WmtConfigException)�parse)�get_admin_email)�gethostname)�Listc@sdeZdZUdZdZeed<dZeed<dZe	ed<e
ed�Ze
e	ed	<d
Zeed<d
Zeed<dS)
�CfgzC
    Default values, in case config has not been specified yet
    ��
ping_interval�
�ping_timeoutN�report_email)�default_factory�ignore_listT�summary_notification_enabled�alert_notifications_enabled)�__name__�
__module__�__qualname__�__doc__r
�int�__annotations__rr�strr�listrr
r�boolr�rr�B/opt/alt/python37/lib/python3.7/site-packages/wmt/common/config.pyrs
rc@s|eZdZdd�Zdd�Zdd�Zed�dd	�Zed
d��Z	e
d�d
d�Zedd��Zdd�Z
ed�dd�Zed�dd�ZdS)�
ConfigManagercCsDtj��|_dt���|_t�|_|��|_	|�
�|_|��|_
dS)Nzweb-monitoring-tool@)rZ__dataclass_fields__�keys�allowed_paramsr	Z
from_emailr�default_report_email�	_init_cfg�cfg�generate_ignored_domains�_ignored_domains�_get_target_emailZtarget_email)�selfrrr�__init__s

zConfigManager.__init__cCs|jjr|jjS|jS)a
        This function checks to see which email address to use for TO: field of smtp.
        If report_email has been defined by user then report_email will be used.
        By default (in case not defined by user) default_report_email will be used
        )r%rr#)r)rrrr('szConfigManager._get_target_emailcCs
t|j�S)N)rr%)r)rrr�to_dict/szConfigManager.to_dict)�returncCsj|��st�S|��}t�}xH|��D]<\}}||jkrVt�d|�dt|j����q&t|||�q&W|S)Nzunsupported parameter "z:", please ensure config contains only allowed parameters: )	�
is_presentr�read�itemsr"�loggingZwarningr�setattr)r)�datar%�key�valuerrrr$2s
zConfigManager._init_cfgcCstj�t�S)N)�os�path�isfilerrrrrr-EszConfigManager.is_present)�new_jsonc
Cs�yt�|�}Wn0tjk
r>}ztt|���Wdd}~XYnXt|����|j�shtdt	|j�����|�
�|�}|�d�r�t|�d�t�r�|d�
d�|d<ttd��}tj||dd�WdQRXtf|�|_|�
�S)z�
        Changes configuration of wmt

        Returns:
            self.to_dict()

        Raises:
            WmtConfigException

        Example:
            wmt-api-solo --config-change {'key': 'val'}
        Nz@some of passed params are unsupported, only allowed parameters: r�,�w�)�indent)�json�loads�JSONDecodeErrorrr�setr!�issubsetr"rr+�get�
isinstance�split�openr�dumprr%)r)r8Z
new_config�eZconfig�frrr�modifyIs
zConfigManager.modifyc
CsXy"tt��}t�|�}WdQRXWn0tjk
rR}ztt|���Wdd}~XYnX|S)N)rErr=�loadr?rr)rHr2rGrrrr.ms
zConfigManager.readcCs|��|_dS)N)r$r%)r)rrr�reloadvszConfigManager.reloadcCs
||jkS)z5
        Check if domain is in ignored list.
        )r')r)Zdomainrrr�is_domain_ignoredyszConfigManager.is_domain_ignoredcCsBt�}x6|jjD]*}t|�}d|kr0|�dd�}|�|�qW|S)al
        Generates ignored domains from self.ignore_list and
        returns it for using as cache in self.ignored_domains set().

        Purpose of this function is to generate formatted url as "http://www.test.com"
        from user entered urls in self.ignore_list.
        It makes sense to check domains names with this cache before pings or reports
        ZhttpsZhttp)r@r%rr�replace�add)r)Zdomains�dZdomain_from_ignore_listrrrr&s	z&ConfigManager.generate_ignored_domainsN)rrrr*r(r+rr$�staticmethodr-rrIr.rKrrLr@r&rrrrr s$	r )r0r5r=ZdataclassesrrrZwmt.common.constrZwmt.common.exceptionsrZwmt.common.url_parserrZclcommon.cpapirZsocketr	�typingr
rr rrrr�<module>s

Zerion Mini Shell 1.0