ok

Mini Shell

Direktori : /proc/self/root/opt/alt/python37/lib/python3.7/site-packages/clsentry/
Upload File :
Current File : //proc/self/root/opt/alt/python37/lib/python3.7/site-packages/clsentry/client.py

#!/opt/cloudlinux/venv/bin/python3 -bb
# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import platform

from requests.exceptions import RequestException
from clcommon import cpapi, get_lve_version
from clcommon.lib.cledition import get_cl_edition_readable
from clcommon.utils import get_rhn_systemid_value
from clcommon.cpapi.const import UNKNOWN_CP_NAME
from raven import Client
from raven.transport import RequestsHTTPTransport
from clsentry.utils import get_pkg_version


class SafeRequestsHTTPTransport(RequestsHTTPTransport):

    def send(self, url, data, headers):
        try:
            super(SafeRequestsHTTPTransport, self).send(url, data, headers)
        except RequestException:
            # We hide errors while sending message to Sentry in varied cases:
            # problems with network, Sentry server is down, incorrect firewall's rules, etc
            pass


class UserlandClient(Client):
    """
    Userland's sentry client with some common settings.
    """
    def __init__(self, dsn, **options):
        options.update(dict(
            tags=self._get_user_tags(),
            ignore_exceptions=[
                KeyboardInterrupt,
            ],
            exclude_paths=[
                'sentry',
                'raven',
            ],
            auto_log_stacks=True,
            string_max_length=1000,
            list_max_length=100,
            processors=('clsentry.processors.UserlandSanitize', ),
            # async transport is noisy and prints messages like
            # 'Sentry is attempting to send 1 pending error messages'
            transport=SafeRequestsHTTPTransport,
        ))
        super(UserlandClient, self).__init__(dsn, **options)

    @classmethod
    def _get_user_tags(cls):
        """
        Get tags for easy search
        :rtype: dict
        """
        cp_description = cpapi.get_cp_description()
        cp_version = cp_description.get('version') if cp_description else None
        cp_name = cp_description.get('name') if cp_description else UNKNOWN_CP_NAME

        return {
            'Control Panel Name': cp_name,
            'Control Panel Version': cp_version,
            'CloudLinux version': get_rhn_systemid_value("os_release"),
            'Cloudlinux edition': get_cl_edition_readable(),
            'Architecture': get_rhn_systemid_value("architecture"),
            'lve_version': get_lve_version()[0],
            # TODO: use 'include_paths' instead
            'lvemanager': get_pkg_version('lvemanager'),
            'alt-python27-cllib': get_pkg_version('alt-python27-cllib'),
            'lve-stats': get_pkg_version('lve-stats'),
            'lve-utils': get_pkg_version('lve-utils'),
            'cl-end-server-tools': get_pkg_version('cl-end-server-tools'),
            'cl-node-exporter': get_pkg_version('cl-node-exporter'),
            'cagefs': get_pkg_version('cagefs'),
            'kernel': platform.release(),
        }

Zerion Mini Shell 1.0