관리-도구
편집 파일: manager.cpython-37.pyc
B � d�- � @ s� d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl mZmZ ddl mZ ddlmZ dd lmZ dd lmZ ddlmZ G dd � d �Zdd�dd�ZdS )zA This module contains classes implementing SSA Manager behaviour � N)�iglob)�is_cl_solo_edition� )�load_validated_parser�load_configuration)� flag_file)�SSAManagerError)�ssa_version)� AutoTracer)� DecisionMakerc @ s� e Zd ZdZdd� Zedd�dd��Zeed�dd ��Z ee d�d d��Zee d�dd ��Ze e d�dd�Zd?eejd�dd�Ze dd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�d d!�Zeed"�d#d$�Zed�d%d&�Zed'd(�d)d*�Zd'd�d+d,�Zed�d-d.�Zd'd�d/d0�Zd'd�d1d2�Z d'd�d3d4�Z!ed�d5d6�Z"d'd�d7d8�Z#d'd�d9d:�Z$dd�d;d<�Z%d'd�d=d>�Z&d'S )@�Managerz SSA Manager class. c C s0 t �d�| _d| _d| _d| _tttj f| _ d S )NZmanagerzclos_ssa.ini)Zphp44Zphp51Zphp52Zphp53zphp\d+-imunifyzphp-internal)z /opt/alt/php[0-9][0-9]/link/confz./var/cagefs/*/*/etc/cl.php.d/alt-php[0-9][0-9]z+/opt/cpanel/ea-php[0-9][0-9]/root/etc/php.dz$/opt/plesk/php/[0-9].[0-9]/etc/php.dz'/usr/local/php[0-9][0-9]/lib/php.conf.dzM/usr/share/cagefs/.cpanel.multiphp/opt/cpanel/ea-php[0-9][0-9]/root/etc/php.dzA/usr/share/cagefs-skeleton/usr/local/php[0-9][0-9]/lib/php.conf.d)�loggingZ getLogger�logger� ini_file_name�substrings_to_exclude_dir_paths�wildcard_ini_locations�OSError� ValueError� subprocessZSubprocessError�subprocess_errors)�self� r �</opt/alt/python37/lib/python3.7/site-packages/ssa/manager.py�__init__! s zManager.__init__zjson str)�returnc O s* ddi}|� dd� |�� D �� t�|�S )z@ Form a success json response with given kwargs �result�successc S s i | ]\}}||�qS r r )�.0�k�vr r r � <dictcomp>: s z$Manager.response.<locals>.<dictcomp>)�update�items�json�dumps)�args�kwargsZraw_responser r r �response4 s zManager.responsec C s t j�t�S )z Is SSA enabled )�os�path�isfiler )r r r r �_enabled= s zManager._enabledc C s ddhS )zK Configuration settings required Request Processor restart Zrequests_durationZignore_listr )r r r r �_restart_required_settingsD s z"Manager._restart_required_settingsc C s dddddhS )NZcorrelationZcorrelation_coefficientZrequest_numberZtimeZdomains_numberr )r r r r �solo_filtered_settingsK s zManager.solo_filtered_settings)�settingsr c C s | j �|�S )z� SSA Agent requires restart in case of changing these configuration: - requests_duration - ignore_list )r, �intersection)r r. r r r �_restart_requiredP s zManager._restart_requiredF)�commandr c C s y0t jdd|gdd|d�}| j�d|� d�� W n� t jk r� } zj| jjd|j� d|j� d |jpf|j � �|j|j|j|j d �d� t d|j� d|j� d |jp�|j � ���W dd}~X Y nZ | jk �r } z8| jjd |� d�dt|�id� t d |� d|� ���W dd}~X Y nX |S )z� Run /sbin/service utility to make given operation with SSA Agent service :command: command to invoke :check_retcode: whether to run with check or not :return: subprocess info about completed process z /sbin/servicez ssa-agentT)Zcapture_output�textZcheckz ssa-agent z succeededz SSA Agent z failed with code z: )�cmdZretcode�stdout�stderr)�extraNzFailed to run z command for SSA Agent�errz for SSA Agent: ) r �runr �infoZCalledProcessError�errorr3 � returncoder4 r5 r r �str)r r1 � check_retcoder �er r r �run_service_utilityX s( 4$zManager.run_service_utility)r% r c C s� t � }|�|� y|�� W nH tk rd } z*| jjddt|�id� td|� ���W dd}~X Y nX | �|�r~| j ddd� | � � S ) z� Change SSA config and restart it. :args: dict to override current option values :return: JSON encoded result of the action z Failed to update SSA config filer7 )r6 z"Failed to update SSA config file: N�restartT)r= )r �overrideZwrite_ssa_confr r r: r<