| Server IP : 142.11.234.102 / Your IP : 216.73.217.78 Web Server : Apache System : Linux dal-shared-66.hostwindsdns.com 4.18.0-513.24.1.lve.1.el8.x86_64 #1 SMP Thu May 9 15:10:09 UTC 2024 x86_64 User : krnuyqrm ( 1183) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/cloudlinux/venv/lib/python3.11/site-packages/xray/continuous/ |
Upload File : |
# -*- coding: utf-8 -*-
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
"""
This module contains continuous tracing manager, aimed to enable|disable
tracing
"""
from urllib.parse import urlparse
from xray import gettext as _
from .common import ContinuousCommon
from ..internal.exceptions import XRayError, XRayManagerExit
from ..internal.utils import timestamp
class ContinuousManager(ContinuousCommon):
"""
enable|disable|start|stop|list continuous tracing
"""
@staticmethod
def url_sanitize(url: str) -> str:
"""
Leaves only domain path of URL, without www. prefix and :port postfix
"""
fragments = urlparse(url)
if fragments.netloc.startswith("www."):
_no_www_netloc = fragments.netloc[4:]
else:
_no_www_netloc = fragments.netloc
_no_port_netloc = _no_www_netloc.split(":")[0]
return f"{fragments.scheme}://{_no_port_netloc}"
def enable(self, domain: str, url: str, email: str) -> None:
"""
Enable continuous tracing
"""
if domain not in self.tracing_conf:
self.tracing_conf[domain] = {
"creation_time": timestamp(),
"domain": domain,
"original_url": self.url_sanitize(url),
"email": email,
"execution_count": 0,
"status": "running",
}
else:
raise XRayManagerExit(_('Continuous monitoring for domain "%s" is already enabled') % domain)
self.dump_tracing_configuration()
def disable(self, domain: str) -> None:
"""
Disable continuous tracing
"""
self.remove_tracing_configuration(domain)
def start(self, domain: str) -> None:
"""
Start continuous monitoring
"""
self.update_status(domain, "running")
def stop(self, domain: str) -> None:
"""
Stop continuous monitoring
"""
self.update_status(domain, "stopped")
def update_status(self, domain: str, status: str) -> None:
"""
Set given 'status' for requested 'domain'
"""
try:
if self.tracing_conf[domain]["status"] == status:
# minimal triage context only: avoid shipping the stored
# tracing entry (incl. recipient email) to telemetry
self.logger.error(
"Continuous monitoring is already %s",
status,
extra={"domain": domain, "current_status": status},
)
raise XRayError(_("Continuous monitoring for {} is already {}".format(domain, status)))
except KeyError:
# minimal triage context only: avoid shipping the whole
# cross-domain tracing map (every domain + recipient email)
self.logger.error(
"Continuous monitoring is not enabled",
extra={
"domain": domain,
"tracing_entries_count": len(self.tracing_conf),
},
)
raise XRayError(_("Continuous monitoring for %s is not enabled") % domain)
self.tracing_conf[domain]["status"] = status
self.dump_tracing_configuration()
def get_tracing_list(self):
"""
Return all continuous tracing tasks
"""
return list(self.tracing_conf.values())