HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/clconfig/__pycache__/lve_stats2_lib.cpython-37.pyc
B

}��-���@s�ddlmZddlZddlZddlmZmZmZmZm	Z	m
Z
mZddlm
Z
ddlmZGdd�de
�Zd	Zed
Zddd
dd�Zddddddd�Zddddd�Zddd�Zddd�Zd'd!d"�Zd(d#d$�Zd)d%d&�ZdS)*�)�absolute_importN�)�str_to_boolean�repack_dict�time_convertor_to_dict�is_positive_int�time_unit_to_letter�boolean_to_yes_no�min_num_notify_converter)�FormattedException)�mod_makedirsc@seZdZdS)�LveStats2ExceptionN)�__name__�
__module__�__qualname__�rr�py/clconfig/lve_stats2_lib.pyr
sr
z/etc/sysconfig/lvestats.configz/StatsNotifier.cfg�notifyAdmin�notifyResellers�notifyCustomers�notifyResellerCustomers)�NOTIFY_ADMIN�NOTIFY_RESELLER�NOTIFY_CUSTOMER� NOTIFY_INCLUDE_RESELLER_CUSTOMERZmemZiopsZnproc�ioZconcurrentConnectionsZcpu)�
NOTIFY_MEMORY�NOTIFY_IOPS�NOTIFY_NPROC�	NOTIFY_IO�	NOTIFY_EP�
NOTIFY_CPUZnotifyFromEmailZreportAdminMailZ
notifySubjectZ
notifyCharset)�NOTIFY_FROM_EMAIL�REPORT_ADMIN_EMAIL�NOTIFY_FROM_SUBJECT�NOTIFY_CHARSET_EMAIL�userZadmin)�NOTIFY_MIN_FAULTS_USER�NOTIFY_MIN_FAULTS_ADMIN)�NOTIFY_INTERVAL_ADMIN�NOTIFY_INTERVAL_USER�rcCst||d�S)N)�mode)�open)�	file_namer,rrr�_open9sr/c
Cs2t}tj�|�siSyt|�}|��}|��Wn@ttfk
rp}zt	dt
|�d|id���Wdd}~XYnXi}x>|D]6}|�d�s||��dkr�q||�
d�\}}|��||<q|Wt}	t}
t}t}t|	|t�}
t|
|t�}t||tdd	�}t||t�}tt|t
dd	�}||
d
<||
d<||
d<||
d
<d|
iS)a
    Retrieves lve-stats2 notifications parameters
    :param str reseller: reseller name, if we want notifications parameters for a reseller
    :return: dict. For example:
        {'faultsNotification': {'notifyResellerCustomers': True,
                                'notifyResellers': True,
                                'minimumNumberOfFaultsToNotify': {'admin': 0, 'user': 0},
                                'notifyAdmin': True,
                                'notify': {'admin': {'unitOfTime': 'hours', 'period': 12},
                                           'user': {'unitOfTime': 'hours', 'period': 12}
                                          },
                                'faultsToInclude': {'mem': True, 'iops': False, 'io': False,
                                                    'nproc': False, 'concurrentConnections': False,
                                                    'cpu': True},
                                'notifyCustomers': False
                               }
        }
    z%(lvestats_cfg)s read error: �lvestats_cfg)�message�contextN�#��=r)�defaultZfaultsToIncludeZminimumNumberOfFaultsToNotifyZnotifyZemail�faultsNotification)�StatsNotifierConfig�os�path�existsr/�	readlines�close�IOError�OSErrorr
�str�
startswith�strip�split�notify_dict�faults_dict�number_notify_dict�notify_time_dictrrr
r�email_notify_dict)�reseller�config_path�fZconfig�eZconfig_dict�line�key�valueZnotify_dZfaults_dZnumber_notify_dZ
notify_time_dZfaults_notification_dictZfaults_include_dictZmin_num_notifyZ
period_notifyZemail_settingsrrr�get_notification=s< 
rPcs�tj�t�rt��dkrdSi�t}t��tj�tj�|��sPttj�|�d�tj�|�sjt|d��	�y&t|�}dd�|�
�D�}|�	�Wn@ttfk
r�}zt
dt|�dtid	���Wdd}~XYnXd
d�dfd
d�dfdd�dfdd�dfdd�dfdd�dfd�}|�dd�ddfdd�ddfdd�dfd d�d!fd"d�d#fd$d�d%fd&d'd(��|�d)d*d+d,d-��i}��fd.d/��xv|��D]j\}}	yDt|	t��r��|	�||<n&|	d�fd0d1�|	d2d�D��||<Wntk
�r��w�YnX�q�Wd3d�|D�}
y�x�t|�D]�\}}|�d4��s|��d5k�rB�qy|�d6�\}}
Wn4tk
�r�t
d7�|d2|�d|id	���YnX||k�rd8|||f|
|<||=�qWWnBttfk
�r�}zt
d9t|�d|id	���Wdd}~XYnXx(|��D]\}}
|
�d8||
f��qWd:d;�}tt||
��}
y&t|d�}|�d<�|
��|�	�WnBttfk
�r�}zt
d=t|�d|id	���Wdd}~XYnXt j!d>d?d@dA�dS)Ba�
    Sets lve-stats2 notifications parameters
    :param parameters_dict: Parametres to set. For example:
        {u'notifyResellers': True,
         u'faultsToInclude': {u'mem': True, u'iops': False, u'io': False, u'nproc': False,
                                u'concurrentConnections': False, u'cpu': True},
         u'minimumNumberOfFaultsToNotify': {u'admin': 0, u'user': 0},
         u'notifyAdmin': True,
         u'notify': {u'admin': {u'unitOfTime': u'hours', u'period': 12},
                     u'user': {u'unitOfTime': u'hours', u'period': 12}
                    },
         u'notifyResellerCustomers': True,
         u'notifyCustomers': False
        }
    :param str reseller: either reseller name or None
    rNi��wcSsg|]}|���qSr)rB)�.0�lrrr�
<listcomp>�sz$set_notification.<locals>.<listcomp>z%(lvestats_cfg)s read error: r0)r1r2cSst|�S)N)r	)�xrrr�<lambda>��z"set_notification.<locals>.<lambda>zfaultsToInclude/cpucSst|�S)N)r	)rUrrrrV�rWzfaultsToInclude/nproccSst|�S)N)r	)rUrrrrV�rWzfaultsToInclude/iocSst|�S)N)r	)rUrrrrV�rWzfaultsToInclude/memcSst|�S)N)r	)rUrrrrV�rWz%faultsToInclude/concurrentConnectionscSst|�S)N)r	)rUrrrrV�rWzfaultsToInclude/iops)r!rrrr rcSsdt|�t|�fS)Nz%d%s)rr)rU�yrrrrV�rWznotify/admin/periodznotify/admin/unitOfTimecSsdt|�t|�fS)Nz%d%s)rr)rUrXrrrrV�rWznotify/user/periodznotify/user/unitOfTimecSst|�S)N)r	)rUrrrrV�rWrcSst|�S)N)r	)rUrrrrV�rWrcSst|�S)N)r	)rUrrrrV�rWrcSst|�S)N)r	)rUrrrrV�rWrz#minimumNumberOfFaultsToNotify/adminz"minimumNumberOfFaultsToNotify/user)r)r*rrrrr(r'zemail/notifyFromEmailzemail/notifySubjectzemail/reportAdminMailzemail/notifyCharset)r"r$r#r%cs`|�d�}y�}x|D]}||}qWWn2tk
rZ�d}x|D]}||}qFWYnX|S)N�/r7)rC�KeyError)r:�
path_partsZpoint�part)�notifier_params�parameters_dictrr�get_val_by_path�s


z)set_notification.<locals>.get_val_by_pathc3s|]}�|�VqdS)Nr)rRrU)r_rr�	<genexpr>�sz#set_notification.<locals>.<genexpr>rcSsg|]}|���qSr)rB)rRrSrrrrT�sr3r4r5z(%(lvestats_cfg)s format error : {0}: {1}z%s=%sz%(lvestats_cfg)s format error: cSs0|�d�s|��dkrdS|�d�\}}|dkS)Nr3r4Tr5�None)rArBrC)�_line�_Z_valuerrr�filter_config_lines�sz-set_notification.<locals>.filter_config_lines�
z%(lvestats_cfg)s write error: z+/sbin/service lvestats reload &>/dev/null &Tz	/bin/bash)�shell�
executable)"r9r:r;r8�lenrP�dirnamerr/r=r<r>r?r
r@�update�items�
isinstancerZ�	enumeraterArBrC�
ValueError�format�
IndexError�append�list�filterr-�
writelines�join�
subprocess�run)r^rIrJrKZconfig_linesrLZfaults_config_mapZ
new_configrN�valZconfig_to_write�idxrMrOrdr)r_r]r^r�set_notificationvs� 










*
 
 rz)r+)N)N)Z
__future__rr9rvZclconfig_utilsrrrrrr	r
Zclcommon.clexceptionrZclcommon.utilsrr
ZStatsNotifierDirr8rDrErHrFrGr/rPrzrrrr�<module>
s:$

9