|9eZ*ddlmZddlZddlZddlmZmZmZmZm Z m Z m Z ddl m Z ddlmZGdde Zd Zed zZd d d ddZdddddddZdddddZdddZdddZd$d!Zd%d"Zd%d#ZdS)&)absolute_importN)str_to_boolean repack_dicttime_convertor_to_dictis_positive_inttime_unit_to_letterboolean_to_yes_nomin_num_notify_converter)FormattedException) mod_makedirsceZdZdS)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||S)N)mode)open) file_namer:s r_openr=9s   % % %%rc\t}tj|siS t |}|}|n=#ttf$r)}tdt|zd|idd}~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_dictrrr remail_notify_dict)reseller config_pathfconfige config_dictlinekeyvaluenotify_dfaults_dnumber_notify_d notify_time_dfaults_notification_dictfaults_include_dictmin_num_notify period_notifyemail_settingss rget_notificationrp=s&&K 7>>+ & & M +    W MMM -LsSTvv-U.z$set_notification..s 999a 999rr?r@rAc t|SNr xs 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%cDdt|t|fzSNz%d%srr r}ys rr~z"set_notification..s"v9K9KM`abMcMc8d/drznotify/admin/periodznotify/admin/unitOfTimecDdt|t|fzSrrrs rr~z"set_notification..s"f8J8JL_`aLbLb7c.crznotify/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)r6r7rrrrr5r4zemail/notifyFromEmailzemail/notifySubjectzemail/reportAdminMailzemail/notifyCharset)r.r0r/r1c|d} }|D] }||} n%#t$rd}|D] }||} YnwxYw|S)N/rL)rXKeyError)rO path_partspointpartnotifier_paramsparameters_dicts rget_val_by_pathz)set_notification..get_val_by_pathsZZ__  $#E" $ $d  $ $ $ $#$89E" $ $d  $ $ $ s(A  A c3.K|]}|VdSrzr)rvr}rs r z#set_notification..s-*O*O!??1+=+=*O*O*O*O*O*Orrc6g|]}|Srrtrus rrxz$set_notification..s 777Qqwwyy777rrDrErFz(%(lvestats_cfg)s format error : {0}: {1}z%(lvestats_cfg)s format error: c|ds|dkrdS|d\}}|dkS)NrDrETrFNone)rVrWrX)_line__values rfilter_config_linesz-set_notification..filter_config_linessO   C  EKKMMR$7$74KK$$ 6r z%(lvestats_cfg)s write error: z+/sbin/service lvestats reload &>/dev/null &Tz /bin/bash)shell executable)"rNrOrPrMlenrpdirnamer r=rRrQrSrTrrUupdateitems isinstancer enumeraterVrWrX ValueErrorformat IndexErrorappendlistfilterr; writelinesjoin subprocessrun)rr^r_r` config_linesrbfaults_config_map new_configrevalconfig_to_writeidxrdrfrrrs` @@rset_notificationrvs& 7>>- . .#o2F2F!2K2KO%K&((O 7>>"'//+66 7 7:RW__[115999 7>>+ & &( k3%%'''U +  991;;==999   W UUU -LsSTvv-U.<>Q-R"T"TUU UU )G(FH]'^*H*HJa)b'E'EG[&\+I+IK`*a'E'EGn&o)G)GI_(` bb"d"d"7";"="d!c"6":!<87G::*>??? ?j  25##z#'G$sO $ j !MMM -NQTUVQWQW-W.rs'&&&&& 433333''''''     +   4&)==,"3"33LNN !&$& 3" $$ +<+<,;-<>> 1718::.5,244 &&&&6<6<6<6