jdZddlZddlZddlZddlmZmZddlmZm Z ddl m Z dZ ej dZGd d eZdS) a This module contains SSA specific config parser: - has defaults - adds default values for ones missing in config file - allows duplicates, the latest value is loaded - performs value normalization during loading items: - to int - to float - to bool - 'correlation' is case-insensitive and allowed to be on, off, 1, 0, yes, no, true, false - loads default configuration in case of missing config file N) ConfigParserNoSectionError)CallableList) config_filessa_confssa_configuration_parserc eZdZdZfdZedefdZedefdZedefdZ de de d e de fd Z e d d fde d ededeefdZdZddZdedd fdZddZdZdZxZS)SSAConfigParserz2 SSA specific configparser implementation c dddddddddd }d d d d d ddddd |_||_t|ddS)N g@Tg?) domains_number urls_numberrequest_numberrequests_durationtime correlationcorrelation_coefficient ignore_listsummary_notification_enabledz!Size of TOP list for slow domainszSize of TOP list for slow urlsz[The threshold value of slow requests number in the period of time to mark URL as a slow onez2The threshold value of request duration in secondsz:Period of time in hours required to analyze these requestsz.Flag to enable or disable correlation (On/Off)z.The threshold value of correlation coefficientzEList of URLs or domains that should not be included in a daily reportzBFlag to enable or disable sending daily reports by e-mail (On/Off)F)strict) _commentscopy ssa_defaultssuper__init__)selfdefaults __class__s O/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/configuration/parser.pyr zSSAConfigParser.__init__(s  !$'*,0   B;{!UPK'Wb,p   %MMOO %00000returncdS)N)rrrrr!s r$ int_optionszSSAConfigParser.int_optionsBsHHr%cdS)N)rrr(r)s r$ float_optionszSSAConfigParser.float_optionsFs==r%cdS)N)rrr(r)s r$ bool_optionszSSAConfigParser.bool_optionsJs<.value_getterjs***00'179994+++00gvNNN4---0017999y r%c*g|]}||fSr(r().0r1r?s r$ z)SSAConfigParser.items..vs(GGG6f--.GGGr%) _defaultsrupdate _sectionsKeyErrordefault_sectionloggerinforestore_default_conflistkeys)r!r0r8r3 orig_keysr>r?s`` @@r$itemszSSAConfigParser.itemsZs N   ! ! ( HHT^G, - - - - ( ( ($... 7#%%%  % % ' ' ' ' '  ( NN  ! ! ! ! ! ! !HGGGYGGGGs AABBc tt5 dddn #1swxYwY|tdS#t$r2|t |iYdSwxYw)z` Try to read configuration from file, load defaults if file not present N)openrreadFileNotFoundError read_dictrGr"r)s r$ read_ssa_confzSSAConfigParser.read_ssa_confxs  ?k""                  IIk " " " " "  ? ? ? NNOT]]__= > > > > > > ?s,A $ A (A (A 8BBcLd} tjdtjt d}||dtj|jt |S| tj |jrtj |jdSdSdS#|R| tj |jrtj |jwwwxYw)z= Try to write current configuration to file, NwF)modedirdelete)space_around_delimiters) tempfileNamedTemporaryFileospathdirnamerwriterenamenamecloseexistsremove)r! temp_files r$write_ssa_confzSSAConfigParser.write_ssa_confs   . 3"'//R]B^B^glmmmI JJy%J @ @ @ Iink 2 2 2$!!!7>>).11.Iin-----%$..$!!!7>>).11.Iin----%.s A/C AD#argsct|vrtn|d}|D])\}}|||t |*dS)zQ Load options from the dict into the main section of the config. rN)rGsectionsrNsetstr)r!rhr0r1values r$overridezSSAConfigParser.overridesq&5 %G%G//T]]__]^M_!ZZ\\ 2 2MFE HHWfc%jj 1 1 1 1 2 2r%Tc|r!d|jd}n |jd}|jD]7}||||j||8dS)z Parent method is overrided in order to: - do not print default section - call its own write_section method instead of parent one. z {} rN)format _delimitersrE write_sectionrN)r!fprZr>r0s r$r`zSSAConfigParser.writes # $ d.q122AA #A~ D DG   r7 $w 7 = = ? ? D D D D D Dr%c  |jr |jdnd}|d||D]\}}|j||||}||js'|t |ddz}nd}|j |d}||||d||d |d||d|ddS) z The difference between this one and the parent _write_section method is in writing the comments to every option also r#z[{}] N z rz  ) _comment_prefixesr`rp_interpolation before_write_allow_no_valuerlreplacerget) r!rs section_name section_items delimitercomment_prefixkeyrmcomments r$rrzSSAConfigParser.write_sections- 7;6LU/22RU ..///' J JJC'44T<5:<u>>>X>=e===X=  C %( -0    $3HHSHHH$(KHHHH< ? ? ?...."2T2d2222 D D D D* : : : : : : :r%r )rloggingr]r[ configparserrrtypingrrinternal.constantsrrG getLoggerrHr r(r%r$rs   55555555!!!!!!!!-,,,,,  5 6 6j:j:j:j:j:lj:j:j:j:j:r%