Ejemplo n.º 1
0
 def process_response(self, request, response):
     from django.db import connection
     _sql_logger = xlogging.getLogger('djangosql')
     temp = 0
     for x in connection.queries:
         _sql_logger.info('{}:{}--{}'.format(os.getpid(),
                                             threading.get_ident(), x))
         temp += float(x['time'])
     _sql_logger.info('{}:{}:{}--time count:{}'.format(
         request, os.getpid(), threading.get_ident(), temp))
     return response
Ejemplo n.º 2
0
def _models_hook_init():
    if not _get_mq_param('enable'):
        _logger.warning(r'mq mode disable')
        return None
    _logger.warning(r'mq mode enable : {}'.format(MQ_PARAMS))
    from ClwMqClient.mq_client import ClwMqPublishClient, ClwMqConnection, ClwReconnectWithInterval, \
        ClwMqPublishFailoverCache
    publish_client = ClwMqPublishClient(
        'ModelsHook PublishClient',
        ClwMqConnection('ModelsHook Connection', _get_mq_param('MQ_HOST'),
                        _get_mq_param('MQ_USR'), _get_mq_param('MQ_PWD'),
                        xlogging.getLogger('ModelsHook_connection')),
        xlogging.getLogger('ModelsHook'),
        ClwReconnectWithInterval(_get_mq_param('MQ_RECONNECT_INTERVAL')),
        ClwMqPublishFailoverCache(
            _get_mq_param('MQ_FAILOVER_CACHE_PATH'),
            xlogging.getLogger('ModelsHook_FailoverCache')), True)

    assert (0 < len(_get_mq_param('MQ_NODE')) <= 4)
    post_save.connect(hook_post_save)
    return publish_client
Ejemplo n.º 3
0
import json
import requests
import threading

from apiv1.models import Host, RemoteBackupSchedule
from box_dashboard import xlogging
from rest_framework import status

_logger = xlogging.getLogger(__name__)


class NetWorkUnReachable(Exception):
    """
    网络不通
    """
    pass


class InvalidUser(Exception):
    """
    连接参数错误 用户名和密码
    """
    pass


def get_root_url(aio_ip, schedule):
    schedule = RemoteBackupSchedule.objects.get(id=schedule.id)
    sche_ext = json.loads(schedule.ext_config)
    enable_https = sche_ext.get('enable_https', {'value': False})
    if enable_https['value']:
        result = r'https://{}:{}/'.format(aio_ip, sche_ext.get('web_port', '443'))
Ejemplo n.º 4
0
# coding:utf-8
import json
import sys
import traceback
from datetime import datetime
from urllib import request, parse, error

from box_dashboard import xlogging

# from web_guard.models import WebGuardStrategy, EmergencyPlan, StrategyGroup, AlarmEventLog
_logger = xlogging.getLogger('NOTIFICATION')

# import logging
# _handler = logging.StreamHandler(sys.stdout)
# _handler.setFormatter(logging.Formatter('%(asctime)s %(name)-8s %(levelname)-6s: %(message)s'))
# _logger = logging.getLogger('NOTIFICATION')
# _logger.setLevel(logging.DEBUG)
# _logger.addHandler(_handler)

_aio_notice_url = 'http://update.clerware.com/sms/index.php/api/aionotice?'


def aio_email_notify(email_list, strategy_name, risk_text, risk_level, risk_time):
    _logger.debug('call email api: {}, {}, {}, {}, {}'.format(
        ','.join(email_list), strategy_name, risk_text, risk_level, risk_time))
    return 0, 'success'


def get_aio_id():
    return 'aio_id:NanJingAnJian01,sn:335727890'
Ejemplo n.º 5
0
# coding:utf-8
import sys

from box_dashboard import xlogging
from box_dashboard.boxService import box_service

_logger = xlogging.getLogger('XMAINTAINANCE')


def _find_srv_name_by_pid(info_list, pid):
    service_name = None
    for info in info_list:
        if info.dwProcessId == pid:
            service_name = info.lpServiceName
            break
    _logger.debug(
        '_find_srv_name_by_pid(info_list, pid={}) return: service_name={}'.
        format(pid, service_name))
    return service_name


def _get_bs(port, port_list, bs_list):
    for n, p in enumerate(port_list):
        if p == port and n < len(bs_list):
            return bs_list[n]
    return None


def _str_info_list(info_list):
    ret_string = ''
    for info in info_list: