a ƒ¬ i­"ã@s´ddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z dZdZdd„Ze jdd „ƒZd d „Zd=d d„ZdZdddœZd>dd„Zdd„Zdd„Zdd„Ze jdd„ƒZe jdd„ƒZ e jd d!„ƒZ!d"d#„Z"d$d%„Z#d&d'„Z$d(d)„Z%e j&e j'd*d+d,„ƒZ(e j&e j'd*d-d.„ƒZ)e je j&e j'd*d/d0„ƒƒZ*e j&e j'dd1d2d3„ƒZ+e j&e j'dd1d4d5„ƒZ,e j&e j'd*d6d7„ƒZ-e j&e j'd8d1d9d:„ƒZ.d;d<„Z/dS)?éNé)ÚconfigÚ constantsÚ log_utilsÚ process_utilsÚselinuxÚutilsz/usr/libexec/kcare/virt-whatz/proccCs2tjdd…dkrt ¡Sddl}|jddSdS)Né)éérF)Zfull_distribution_name)ÚsysÚ version_infoÚplatformZlinux_distributionÚdistro)r©rú4/usr/libexec/kcare/python/kcarectl/platform_utils.pyÚ get_distrosrcCs t ¡dS)Nr )rÚunamerrrrÚget_system_unamesrcCsdtjdtjdfS)Nz%s.%srr)r r rrrrÚget_python_version$srFc Csžtƒtjdœ}t ¡r^tjddddtt  ¡ƒgdd\}}}|sN|  ¡d}nd |}||d <|rlt   |¡St |ƒ}d }|D]}|d |||f7}q|| ¡S) N)Úpython_versionÚ agent_versionZpsz-Zz --no-headersz--pidT)Ú catch_stdoutrz error: %sÚselinux_contextÚz%s: %s )rrÚVERSIONrZis_selinux_enabledrÚ run_commandÚstrÚosÚgetpidÚsplitÚjsonÚdumpsÚsortedÚrstrip) Úis_jsonÚinfoÚrcÚstdoutÚstderrrZ info_keysZinfo_strZinfo_keyrrrÚapp_info(s þ& r*z/sys/firmware/efi/efivarsz$8be4df61-93ca-11d2-aa0d-00e098032b8cz$605dab50-e046-4300-abb6-3dd810dd8b23)ÚglobalÚshimécCs^tj td||f¡}tj |¡s&dSt|dƒ}| |¡WdƒS1sP0YdS)Nz%s-%sÚrb)rÚpathÚjoinÚ EFIVARS_PATHÚexistsÚopenÚread)ÚnameÚvendorZ max_bytesZvar_pathÚvarrrrÚ_read_uefi_varIs   r8cCs@z(tdtdƒ}|r&|dd…dkWSWnty:Yn0dS)NÚ SecureBootr+éÿÿÿÿóF)r8Ú EFI_VENDORSÚ Exception)Zsecure_boot_varrrrÚis_secure_bootRs r>c Cs^zt||ƒ}|durWdSWn0tyL}zt|ƒ ¡}WYd}~n d}~00t t |¡¡S©N)r8r=rÚencoderÚnstrÚbase64Úurlsafe_b64encode)r5r6Z value_bytesÚerrrÚ_get_uefi_var_encoded]s  "rEc Cst tj td¡¡}|r0t|ƒdkr0|dd…}|tj tj t ¡¡dœ}|dsV|Sz„t dd„dDƒƒ|d<t d d „t  t ¡Dƒƒ}d |i|d <t gd ¢ƒ}|D]4}|dvsÀ| d¡r¢||vr¢t|td ƒ|d |<q¢Wn0ty }zt |¡WYd}~n d}~00|S)NÚcmdlinei)rFÚhas_efirGcss |]}|t|tdƒfVqdS)r+N)rEr<©Ú.0r7rrrÚ róz#secure_boot_info..)r9Z SetupModer+cSs4g|],}| td¡r|dttdƒ d…‘qS)r,rr)Úendswithr<ÚlenrHrrrÚ trKz$secure_boot_info..Úvarsr,)Z MokListRTZ MokListXRTZMokListTrustedRTZ SbatLevelRT)Z HSIStatusZ MokIgnoreDBZRT)rÚ try_to_readrr/r0ÚPROC_DIRrMr2Údirnamer1Údictr#ÚlistdirÚsetrLrEr<r=rÚlogwarn)rFr&Z shim_varsZshim_exclude_varsr7ÚerrrrrÚsecure_boot_infohs& ÿ   rXc Csttjrhz&t t ¡ddddtj¡dd}Wqptjyd}zt |¡t   ¡}WYd}~qpd}~00nt   ¡}|S)Nrr ) rÚ REPORT_FQDNÚsocketÚ getaddrinfoÚ gethostnameÚ AI_CANONNAMEÚgaierrorrÚlogerrorrÚnode)ÚhostnameÚgerrrÚ get_hostname€s&  rccCsTtj td¡}tj |¡rPt|dƒ}| ¡}ttt |  ¡dƒƒƒ}|  ¡|SdS)NÚuptimeÚrrz-1) rr/r0rQÚisfiler3ÚreadlinerÚintÚfloatr Úclose)Z uptime_fileÚfÚlineÚresultrrrÚ get_uptimes  rncCs tj t¡rt tg¡ ¡SdS)Nz no-virt-what)rr/rfÚVIRTWHATrÚ check_outputÚstriprrrrÚget_virts rrcCs tj d¡S)Nz/usr/local/cpanel/cpanel©rr/rfrrrrÚ is_cpanel¤srtcCs2tj tj tdd¡¡o0tj tj tdd¡¡ S)NZvzZveinfoÚversion)rr/r2r0rQrrrrÚinside_vz_container¨srvcCsdttj tdd¡ƒ ¡vS)Nz/lxc/Ú1Zcgroup)r3rr/r0rQr4rrrrÚinside_lxc_container¬srxcCs tj d¡S)Nz /.dockerenvrsrrrrÚinside_docker_container°sry)ÚloggercCsFt tj td¡¡}|sdS| dd¡\}}}}t|ƒt|ƒt|ƒfS)NÚloadavgú r )rrPrr/r0rQr ri)r{Zm1Zm5Zm15Ú_rrrÚget_load_average´s r~csDt tj td¡¡}|sdSd‰t‡fdd„dd„| ¡DƒDƒƒS)z!Returns dict of memory info in kBÚmeminfoN)ZMemTotalZMemFreeZ SwapTotalZSwapFreec3s&|]\}}|ˆvr|t|ƒfVqdSr?)rh)rIÚkÚv©Z filter_paramsrrrJÈrKzget_mem_info..css"|]}t d|¡dd…VqdS)z[\s:]+Nr ©Úrer ©rIrlrrrrJÈrK)rrPrr/r0rQrSÚ splitlines)rrr‚rÚ get_mem_info¾s r‡c Cs¼t tj td¡¡}|sdSdd„| d¡Dƒ}t|ƒttdd„|Dƒƒƒ|d  d¡t |d  d d¡ƒ|d  d ¡t |d  d d¡ƒt |d  d d¡ƒ|d  d ¡|d  dd¡ ¡dœ S)NÚcpuinfocSs&g|]}|rtdd„| ¡Dƒƒ‘qS)css|]}t d|¡VqdS)z\s*:\s*Nrƒr…rrrrJÓrKz*get_cpu_info...)rSr†)rIZ cpu_linesrrrrNÒsþz get_cpu_info..z css"|]}| d¡| d¡fVqdS)z physical idzcore idN)Úget)rIZcpurrrrJÙrKzget_cpu_info..rÚ vendor_idÚmodelz model namez cpu familyÚsteppingÚ microcodeÚflagsr) Z logical_coresZphysical_coresrŠr‹Z model_nameZ cpu_familyrŒrrŽ) rrPrr/r0rQr rMrUr‰rh)rˆZcpusrrrÚ get_cpu_infoËs þ   ÷r)rzÚdefault_returncCstdd„t t¡DƒƒS)NcSsg|]}| ¡r|‘qSr)Úisdigit)rIÚdrrrrNçrKz%get_process_count..)rMrrTrQrrrrÚget_process_countäsr“cCs(t tj td¡¡}t|pd ¡dƒS)Nzsys/fs/file-nrÚ0r)rrPrr/r0rQrhr )Zfd_inforrrÚget_opened_files_countêsr•cCs$t d¡D]\}}}t|ƒSdS)Nz/sys/kernel/debug/kvm)rÚwalkrM)Ú_rootÚdirsÚ_filesrrrÚget_vm_count_kvmñs rš)rrcCs(dd„}|dƒ|dƒ|dƒ|dƒfS)z8Return tuple of total numbers of TCP and UDP connectionscSs4t tj td|¡¡}|sdStt| ¡ƒddƒS)NÚnetrr) rrPrr/r0rQÚmaxrMr†)ÚprotoÚrecordsrrrÚconn_records_countþsz9get_network_connections_count..conn_records_countZtcpZtcp6ZudpZudp6r)rŸrrrÚget_network_connections_countùsr c Cs,tƒ\}}tƒtƒtƒtƒtƒtƒ||dœS)N)Z load_averageZmem_infoZcpu_infoZvm_countZ processesZ open_filesZtcp_connectionsZudp_connections)r r~r‡rršr“r•)Zconn_tcpZconn_udprrrÚget_performance_metricss ør¡)F)r-)0rBr!rrr„rZr rrrrrrrÚAnyÚDictÚOptionalÚTuplerorQrÚcachedrrr*r1r<r8r>rErXrcrnrrrtrvrxryÚ catch_errorsrVr~r‡rr“r•ršr r¡rrrrÚs`    þ