h  zdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl Z ddl Z ddlmZddlmZdZd Zd Zd Zd Zd ZdZedZdZdefdZdefdZde edefdZdedefdZdedefdZ dZ!dZ"defdZ#dZ$dZ% d&ded e e&d!e d"d#e ed$e ef d%Z'dS)'z2Helper for integrate sentry in stand-alone scriptsN)suppress)Path)ListOptionalLiteral)tags)sentry imunify360zimunify-antiviruszimunify360-firewallz/var/imunify360/license.jsonz!/var/imunify360/license-free.json IMUNIFYAVUNKNOWNz,/opt/imunify360/venv/share/imunify360/sentryzQhttps://6de77a2763bd40c58fc9e3a89285aaa8@im360.sentry.cloudlinux.com/3?timeout=20returnc tdS#ttf$r t cYSwxYw)z,Return dsn from the file or the default one.ascii)encoding)SENTRY_DSN_PATH read_textstripOSErrorUnicodeDecodeErrorSENTRY_DSN_DEFAULTK/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/sentry.pyget_sentry_dsnrsW"(('(::@@BBB ' ("""!!!!"s,/A  A c tt5ttfD]}tt5t |5}t j|dcdddcdddccdddS#1swxYwYdddn #1swxYwY dddn #1swxYwYtS)Nid) r ExceptionLICENSE LICENSE_FREEFileNotFoundErroropenjsonload UNKNOWN_ID)filenamefiles r get_server_idr'$s )  -- ,/ - -H+,, - -d8nn -yt, - - - - - - - - - - - - - - - --------- - - - - - - - - - - - - - - - - - - - - - - - ---------------- s^%B;B" B $ B"0B; B B"B B" B;"B& &B;)B& *B;;B?B?cmdc tj|tjtjtj}n#t$rYdSwxYw|jdkrdSt j|jS)N)stdinstdoutstderrr) subprocessrunDEVNULLPIPEr returncodeosfsdecoder+)r(cps rcollect_outputr6,s{ ^ $?%     rr }r ;ry ! !!s69 AApkgc,ddd|g}t|S)Nrpmz-qz#--queryformat=%{VERSION}-%{RELEASE}r6r7r(s rget_rpm_versionr<;s $=s CC #  rc,ddd|g}t|S)Nz dpkg-queryz--showformat=${Version}z--showr:r;s rget_dpkg_versionr>@s 2Hc BC #  rc\tjd}|S)Nr)distrolinux_distributionlower) platform_oss rget_current_osrDEs'+--a0K     rct}t}|dkrttrt}nt}|SNubuntu)rDIMUNIFY360_PKGr<r IMUNIFY360)rC service_names rget_package_namerKJs< ""K!Lh?9#=#= ! rclt}|dkrt|}nt|}|SrF)rDr<r>)rJrCversions rget_service_versionrNTs9 ""Kh!,//"<00 Nrctjttj5}t }dt i|_|d||dt|tj tj D]\}}||| ddddS#1swxYwYdS)N)dsnrnamerM) sentry_sdkinitrconfigure_scoperKr'userset_tagrNr cached_fillr items)scopepackagetagvalues rconfigure_sentryr]]s)O(())))  # % %&"$$MOO,  fg&&& i!4W!=!=>>>  +----// & &JC MM#u % % % % & &&&&&&&&&&&&&&&&&&sB1C44C8;C8cftjjj}||ddSdS)Ng@)timeout)rRHubcurrentclientflush)rbs r flush_sentryrdks7 ^ # *F  S !!!!!rwarningmessage format_argslevel)fatalcriticalerrorreinfodebug fingerprint componentc ||i}|r! |jdi|}n#t$r|}YnwxYw|}|dd|s|rdtj5}|r|g|_|r|d|tj|fd|i|ddddS#1swxYwYdStj|fd|i|dS)a Helper function to log messages to Sentry with optional fingerprinting. This is useful when you need to log messages to Sentry without relying on error handling. Args: message: The message to log format_args: Dictionary of arguments to format the message with (optional) level: Log level (default: "warning") fingerprint: String for Sentry fingerprinting (optional) component: Component name to tag the message with (optional) **kwargs: Additional keyword arguments passed to sentry_sdk.capture_message() Common options include: - extra: dict of extra data to include - tags: dict of additional tags - contexts: dict of additional contexts Nrhror)formatKeyErrorpoprR push_scopernrVcapture_message)rfrgrhrnrokwargsformatted_messagerYs r log_messagerxqs6 $ ( . = = = =   ( ( ( '    ($ JJw Mi M  " $ $  2%0M! 6 k9555  &!  ). 28                       "#4LLELVLLLLLs  %%7BB"B)NreNN)(__doc__r"r3r. contextlibrpathlibrtypingrrrr@rRdefence360agent.applicationrdefence360agent.contractsr rIr rHrrFREE_IDr$rrstrrr'r6r<r>rDrKrNr]rddictrxrrrrsW88 ********** ,,,,,,,,,,,,  & (2   $EFFh"""""s "S "c " " " " ##   & & &"""#' !%#5M5M 5M$5M @ 5M # 5M}5M5M5M5M5M5Mr