g*ddlZddlZddlmZddlmZddlmZmZm Z m Z m Z m Z m Z GddeZdZed zZd d d d dZdddddddZdddddZdddZdddZd#d Zd$d!Zd$d"ZdS)%N)FormattedException) mod_makedirs)boolean_to_yes_nois_positive_intmin_num_notify_converter repack_dictstr_to_booleantime_convertor_to_dicttime_unit_to_letterceZdZdS)LveStats2ExceptionN)__name__ __module__ __qualname__N/opt/cloudlinux/venv/lib64/python3.11/site-packages/clconfig/lve_stats2_lib.pyrrsDrrz/etc/sysconfig/lvestats.configz/StatsNotifier.cfg notifyAdminnotifyResellersnotifyCustomersnotifyResellerCustomers) NOTIFY_ADMINNOTIFY_RESELLERNOTIFY_CUSTOMER NOTIFY_INCLUDE_RESELLER_CUSTOMERmemiopsnprocioconcurrentConnectionscpu) NOTIFY_MEMORY NOTIFY_IOPS NOTIFY_NPROC NOTIFY_IO NOTIFY_EP NOTIFY_CPUnotifyFromEmailreportAdminMail notifySubject notifyCharset)NOTIFY_FROM_EMAILREPORT_ADMIN_EMAILNOTIFY_FROM_SUBJECTNOTIFY_CHARSET_EMAILuseradmin)NOTIFY_MIN_FAULTS_USERNOTIFY_MIN_FAULTS_ADMIN)NOTIFY_INTERVAL_ADMINNOTIFY_INTERVAL_USERrc&t||dS)Nutf-8)modeencoding)open) file_namer:s r_openr>;s  w 7 7 77rc^t}tj|siS t |}|}|n>#ttf$r*}tdt|zd|id|d}~wwxYwi}|D]_}| ds| dkr0| d\}}| ||<`t} t} t } t"} t%| |t&} t%| |t&}t%| |t(d }t%| |t*}t%t,|td }|| 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 } } %(lvestats_cfg)s read error: lvestats_cfgmessagecontextN#=r)defaultfaultsToIncludeminimumNumberOfFaultsToNotifynotifyemailfaultsNotification)StatsNotifierConfigospathexistsr> readlinescloseIOErrorOSErrorrstr startswithstripsplit notify_dict faults_dictnumber_notify_dictnotify_time_dictr r rr email_notify_dict)reseller config_pathfconfige config_dictlinekeyvaluenotify_dfaults_dnumber_notify_d notify_time_dfaults_notification_dictfaults_include_dictmin_num_notify period_notifyemail_settingss rget_notificationrq?s&&K 7>>+ & & T +    W TTT -LsSTvv-U.#t$t0f$r*}td3t|zd|id|d}~wwxYw|D]\}} | |d2|  d5}t5t7|| } t9|dd675}|d8| dddn #1swxYwYn>#ttf$r*}td9t|zd|id|d}~wwxYwt?j d:d;ddS)?a 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 rNiwc6g|]}|SrrX.0res r z$set_notification..s ??? ???rr@rArBc t|SNrxs rz"set_notification..s2CA2F2FrzfaultsToInclude/cpuc t|Srzr{r|s rr~z"set_notification..s4Ea4H4HrzfaultsToInclude/nprocc t|Srzr{r|s rr~z"set_notification..1B11E1ErzfaultsToInclude/ioc t|Srzr{r|s rr~z"set_notification..s5Fq5I5IrzfaultsToInclude/memc t|Srzr{r|s rr~z"set_notification..rrz%faultsToInclude/concurrentConnectionsc t|Srzr{r|s rr~z"set_notification..s3DQ3G3GrzfaultsToInclude/iops)r(r%r&r#r'r$cBt|t|Srzrr r}ys rr~z"set_notification..s#/!2D2D/^FYZ[F\F\/^/^rznotify/admin/periodznotify/admin/unitOfTimecBt|t|Srzrrs rr~z"set_notification..s#1C1C.]EXYZE[E[.].]rznotify/user/periodznotify/user/unitOfTimec t|Srzr{r|s rr~z"set_notification..s#4Q#7#7rrc t|Srzr{r|s rr~z"set_notification..&7&:&:rrc t|Srzr{r|s rr~z"set_notification..rrrc t|Srzr{r|s rr~z"set_notification..s7H7K7Krrz#minimumNumberOfFaultsToNotify/adminz"minimumNumberOfFaultsToNotify/user)r5r6rrrrr4r3zemail/notifyFromEmailzemail/notifySubjectzemail/reportAdminMailzemail/notifyCharset)r-r/r.r0c|d} }|D] }||} n%#t$rd}|D] }||} YnwxYw|S)N/rM)rYKeyError)rP path_partspointpartnotifier_paramsparameters_dicts rget_val_by_pathz)set_notification..get_val_by_pathsZZ__  $#E" $ $d  $ $ $ $#$89E" $ $d  $ $ $ s(A  A c3.K|]}|VdSrzr)rwr}rs r z#set_notification..s-*O*O!??1+=+=*O*O*O*O*O*Orrc6g|]}|Srrurvs rrxz$set_notification..s ===tzz||===rrErFrGz%(lvestats_cfg)s format error: z: c|ds|dkrdS|d\}}|dkS)NrErFTrGNone)rWrXrY)_line__values rfilter_config_linesz-set_notification..filter_config_linessO   C  EKKMMR$7$74KK$$ 6rr9)r; z%(lvestats_cfg)s write error: z+/sbin/service lvestats reload &>/dev/null &Tz /bin/bashF)shell executablecheck)!rOrPrQrNlenrqdirnamerr>rSrRrTrUrrVupdateitems isinstancer enumeraterWrXrY ValueError IndexErrorappendlistfilterr< writelinesjoin subprocessrun)rr_r`ra config_linesrcfaults_config_map new_configrfvalconfig_to_writeidxrergrrrs` @@rset_notificationrxsI& 7>>- . .#o2F2F!2K2KO%K&((O 7>>"'//+66 7 7:RW__[115999 7>>+ & &( k3%%'''\ +  ?????   W \\\ -LsSTvv-U.<>Q-R"T"TUUZ[ \\ )G(FH]'^*H*HJa)b'E'EG[&\+I+IK`*a'E'EGn&o)G)GI_(` bb"^"^"7";"="^!]"6":!<87G::= ===OT"<00 $ $ICs## tzz||r'9'9 F!ZZ__ UU F F F(@cAgCWCWQUCWCWW . <*>*>??DEF Fj  *-'A'A 3'A'A$sO $ j !TTT -NQTUVQWQW-W.=)O2& O>2O66O>9O6:O>>P9%P44P9)r7rz)rOrclcommon.clexceptionrclcommon.utilsrclconfig_utilsrrrr r r r rStatsNotifierDirrNrZr[r^r\r]r>rqrrrrrs 333333''''''     +   4&)==,"3"33LNN !&$& 3" $$ +<+<,;-<>> 1718::.5,244 88886<6<6<6