관리-도구
편집 파일: mod_lsapi_stat.cpython-39.pyc
a �����q?h�:����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlmZ�d�dlm Z �d�dlm Z �d�dlmZ�d�dlm Z mZmZmZmZ�d�dlmZmZmZmZmZmZmZ�d�dlZG�dd ��d e�Zddd�Zddd�Zddd�Zddd�Zdd��Z dd��Z!dd��Z"dS�)�����N)�get_cp)�criu_settings_malfunctions)�lsapi_settings_malfunctions)�liblsapi_malfunctions)� cpanel_whmapi�plesk_bin_php_handler�dump_loaded_modules� dump_lsapi� query_strings)�get_da_domains�get_da_php_options�read_da_config� liblsapi_path�pretty_version_keys� count_domains�StatUtilsExceptionc�������������������@���s���e�Zd�ZdS�)�ModLsapiStatExceptionN)�__name__� __module__�__qualname__��r���r����//usr/share/lve/modlscapi/user/mod_lsapi_stat.pyr������s���r���Fc�������������� ���C���s��d}i�}t���}zd|jdkr8tj�d�r2t��|d<�qpd}n8|jdkrNt��|d<�n"|jdkrdt��|d<�nd�|j�}W�n,�t y��}�zt |�}W�Y�d}~n d}~0�0�|dur�t��|d<�||d <�t |�|d <�|�t ����|�t����|�dt|d�����i��t|��|��rtj|dd �S�|S�dS�)a��� Return statistics data :param as_json: return json string if True, dict otherwise :return: statistics data dict( `controlPanel`: EA3/EA4/Plesk/DirectAdmin/Unknown CP, `criu`: dict( `status`: running/stopped, `version`: version ), `domainStat`: dict( `version`: `domains_num`, ... ) or dict(`error`: description) if some error occurred, `lsapiConf`: dict( lsapi_with_connection_pool: on/off, lsapi_criu: on/off ) ) or its json-packed version N�cPanelz/etc/cpanel/ea4/is_ea4Z domainStatz7mod_lsapi domains stat is currently unsupported for EA3�Plesk�DirectAdminz7mod_lsapi domains stat is currently unsupported for {0}ZdomainStatErrorZcontrolPanelZtotalDomainT)Z sort_keys)r����name�os�path�exists�get_cpanel_ea4_stat�get_plesk_stat�get_da_stat�formatr����str�dict�update�get_lsapi_conf� get_crui_stat�sum�values�analyze_malfunctions�json�dumps)�as_json�errorZstatsZ control_panel�er���r���r����get"���s4���� r0���Tc�������������� ���C���sP��t���}t���}t���}z�td��d�}|D�]8}|�|�d�t����|�d���|�d�||�d�<�q&td��d�}t�dd ��|D���}t|����} |���D�]*\} }|�|t����� | |�| t���i��q�|r�t �|||�}|}|���D�].\} }|� t��t| �� t|�����t�����q�W�n2�tttf�yB���td �t����d����Y�n0�t|| |��S�)aY�� Collect mod_lsapi statistics for cPanel EA4 through WHM API :param lsapi_only: return only lsapi domains statistics if True, or full statistics if False :param with_selector: take into account the statistics of php selector :return: if lsapi_only return lsapi domains per version stat dict( `version`: `domains_num`, ... ) else return full statistics per handler stat dict( `handler`: {`version`: `domains_num`, ... } ... ) Zphp_get_vhost_versionsZversions�version�vhostZaccountZphp_get_handlers�version_handlersc�����������������S���s ���g�|�]}|��d��|��d�f�qS�)r1���Zcurrent_handler�r0�����.0�hr���r���r���� <listcomp>t��������z'get_cpanel_ea4_stat.<locals>.<listcomp>��� )r$���r���r0���� setdefault�set�add�list�keys�itemsr%����selector_usage_libZea4_selector_check�fromkeys� difference�KeyError� TypeErrorr���r����join� traceback� format_exc�splitr���)� lsapi_only� with_selectorZdomains_per_versionZ handlers_statZdomain_usersZvhosts_datar2���Z handlers_datar3���Zall_versionsZver�handlerZs_checked_version_handlersr7����vr���r���r���r���Y���s*���� $,r���c����������� ������C���s��d}d}t���}z�td�}dd��|D��}|D�]t}|�d�}d�|�d��d �d d���} tdd��td |d�D���} d|v�r�d}|j| d�}n|j| d�}| ||<�q*|r�t�||�}W�n6�t t tttj fy����td�t����d����Y�n0�ddd��|���D��i}|��r|d�S�|S�)a�� Collect mod_lsapi statistics for Plesk Collects lsapi domains ONLY :param lsapi_only: return only lsapi domains statistics if True, or full statistics if False :param with_selector: take into account the statistics of php selector :return: if lsapi_only return lsapi domains per version dict( `version`: `domains_num` ... ) else return stats with handler dict( `lsapi`: {`version`: `domains_num`, ... } ) z alt-php{v}z alt-php56r?���c�����������������S���s���g�|�]}d�|��d�v�r|�qS�)Zlsphp�idr4���r5���r���r���r���r8�������r9���z"get_plesk_stat.<locals>.<listcomp>rO���r:���ZfullVersion�.N���c�����������������S���s���g�|�]}|��d���qS�)�domainr4���)r6����dr���r���r���r8�������r9���z get-usage)rO���Zcustom)rN���r;���Zlsapic�����������������S���s���i�|�]\}}|t�|��qS�r���)�len)r6����krN���r���r���r���� <dictcomp>����r9���z"get_plesk_stat.<locals>.<dictcomp>)r$���r���r0���rG���rJ���r=���r"���rB���Zplesk_selector_checkrE���rF����AttributeErrorr���ZSelectorStatExceptionr���rH���rI���rA���) rK���rL���Zhandler_tmplZcustom_versionZdomain_version_statZall_handlersZlsphp_handlersrM���Z handler_idZphp_version�domainsZ version_idZresult_statr���r���r���r �������s,���� �r ���c��������������������s��d}t���}�z�t��}|d�d�}|d�d�}|d�d�}|d�d�}t|�} t|�} t��}t������fdd�|���D���|dkr�| ��i}| ��i||<��n|dkr�| ��i}| ��i||<�n�| t��| t��i}|���D�]�\} }|D�]v}|j| |d �}z<t|�\}}|� |d �}t||�d��}|� |��|��W�q��tj �yL���|� | ��|��Y�q�0�q�q�||k�rv| || �| || �i||<�n,| || �| t��i||<�| || �| t��i||<�|�r�t�|� | �|| �}|� |��|��W�n4�ttttf�y���td�t����d����Y�n0�t|| | g|��S�) aN�� Collect lsapi domains statistics fro DirectAdmin :param lsapi_only: return only lsapi domains statistics if True, or full statistics if False :param with_selector: take into account the statistics of php selector :return: if lsapi_only return lsapi domains per version stat dict( `version`: `domains_num`, ... ) else return full statistics per handler stat dict( `handler`: {`version`: `domains_num`, ... } ... ) z>/usr/local/directadmin/data/users/{user}/domains/{domain}.conf����r1�������rM���c��������������������s���g�|�]}����|��qS�r���)r%���)r6���rN����Zjoinedr���r���r8�������r9���zget_da_stat.<locals>.<listcomp>Zno)�userrR���Zphp1_selectr:���r;���)r$���r���r���r���r=���r)���rA���r"���r ���Zgetintr0���r>����configparserZ NoOptionErrorrB���Zda_selector_checkr%���rE���rF���rW���r���r���rG���rH���rI���rJ���r���)rK���rL���Zdomain_conf_pathZhandler_statZphp_optionsZphp1_verZphp2_verZphp1_handlerZphp2_handlerZ php1_labelZ php2_labelZuser_domainsZversion_statr\���rX���rR���Zconfig_pathZconf_parserZglobal_sectionZphp_settingr1���Zselector_updatedr���r[���r���r!�������s\���� � ��r!���c������������������C���sj���d��t�d��}�z tjg�d�tjtjd��d}W�n�tjyH���d}Y�n0�d||�r`|��d�d �nd d�iS�)z� Get criu service info :return: dict( `criu`: dict( `status`: running/stopped, `version`: version ) ) r:���z/usr/sbin/criu -V)z /sbin/service�criu�status)�stdout�stderrZrunning�stoppedr^���� rY���z not installed)r_���r1���)rG����exec_command� subprocessZ check_callZDEVNULLZCalledProcessErrorrJ���)Zcriu_versionZcriu_service_statusr���r���r���r'�����s���� ��r'���c������������������C���sT���t���}�t��}|�dd�}|��dd�|��dd�d�|��dd�tt��d�|sLd nd d�S�)al�� Retrieve lsapi configuration: - crui - connection pool and versions of module and library :return: dict( lsapiConf: dict( lsapi_with_connection_pool: on/off, lsapi_criu: on/off ), modVersion: version, libVersion: version ) Zlsapi_moduleN� lsapi_criuZoff�lsapi_with_connection_pool)rf���rg���r1���Zliblsapi_versionZdisabledZenabled)� lsapiConfZ modVersion� libVersion� modStatus)r ���r���r0���r ���r���)Zapache_confZapache_modulesZ mod_statusr���r���r���r&�����s���� � �r&���c��������������������st���t�������fdd�}dj|�d�d�|�d�d�d�}|�d �}|t|�d ���|t|��|t|����sbdS�|��d��i��dS�) z� Detect configuration malfunctions and update resulting statistics dict accordingly For now only criu malfunctions are presented See malfunctions in dashboard_malfunctions.py module :param stats_dict: resulting statistics dict c��������������������s*���z����|�|���W�n�ty$���Y�n0�d�S�)N)�appendrE���)Zmalfunc_dict�key��malfunctionsr���r����add_malfunctionH��s����z-analyze_malfunctions.<locals>.add_malfunctionz{opt}_{serv}rh���rf���r^���r_���)�optZservrj���ri���Nrn���)r?���r"���r���r���r���r%���)Z stats_dictro���Z criu_settingsZlsapi_settingsr���rm���r���r*���?��s���� � r*���)F)TT)TT)TT)#r���r+���rH���re���r]���rd����lve_diagnosticr���Zdashboard_malfunctionsr���r���r���� stat_utilsr���r���r���r ���r ���r���r���r ���r���r���r���r���rB���� Exceptionr���r0���r���r ���r!���r'���r&���r*���r���r���r���r����<module>���s(���$ 7 1 , O