Beispiel #1
0
def ip_notice():
    """
    IP不通邮件通知 当发送机连续10分钟接收邮件都失败时,则通知相应管理员该发送机IP不通
    :return:
    """
    global notice_setting, bounce_setting
    subject = u'发送机IP不通通知'
    type = 'ip'
    redis = get_redis()
    while True:
        try:
            if notice_setting:
                outinfo('ip notice')
                ip_interval = notice_setting.ip_interval
                content_format = notice_setting.ip_content
                manager = notice_setting.manager
                need_time = datetime.datetime.now() - datetime.timedelta(
                    minutes=ip_interval)
                _, ip = redis.brpop('control_dispatch_exception')

                # 判断是否在发送间隔时间内, 如果在间隔时间内,则不发送通知
                if Notification.objects.filter(manager=manager,
                                               created__gt=need_time,
                                               type=type,
                                               content__icontains=ip):
                    gevent.sleep(300)
                    continue
                content = Common.safe_format(content_format, ip=ip)
                notice(subject, content, type, manager=manager)
            gevent.sleep(300)
        except:
            outerror(traceback.format_exc())
        gevent.sleep(300)
Beispiel #2
0
def get_dispatch_status(obj):
    msg = u"""队列大小:<code>{queue_size}</code> 线程数:<code>{pool_size}</code><br/> 通讯异常时间:<code>{exception_time}</code>"""
    redis = get_redis()
    ip = obj.ip
    try:
        status_dict = json.loads(redis.get('control_dispatch_state'))
    except:
        status_dict = {}
    rs = {
        'queue_size': status_dict.get(ip, {}).get('queue_size', 0),
        'pool_size': status_dict.get(ip, {}).get('pool_size', 0),
        'exception_time': status_dict.get(ip, {}).get('exception_time', 0)
    }
    return msg.format(**rs)
Beispiel #3
0
def collect_dielver_exception_notice():
    """
    网关客户服务器DOWN机要短信/邮件提醒管理员和客户管理员
    IP不通邮件通知 当发送机连续10分钟接收邮件都失败时,则通知相应管理员该发送机IP不通
    :return:
    """
    global notice_setting
    subject = u'网关客户服务器DOWN机通知'
    type = 'c_down'
    redis = get_redis()
    while True:
        try:
            if notice_setting:
                outinfo('collect deliver exception notice')
                interval = notice_setting.c_deliver_exception_interval
                content_format = notice_setting.c_deliver_exception_content
                manager = notice_setting.manager
                need_time = datetime.datetime.now() - datetime.timedelta(
                    minutes=interval)
                _, res = redis.brpop('collect_deliver_exception')
                customer_id, domain = res.split(',')
                customer = Customer.objects.get(id=customer_id)
                ip = ','.join(
                    list(
                        ColCustomerDomain.objects.filter(
                            customer=customer, domain=domain,
                            disabled=False).values_list('forward_address',
                                                        flat=True)))
                if customer.gateway_status == 'disabled' or not ip or get_mail_model2(
                        datetime.date.today().strftime('%Y%m%d')
                ).objects.filter(state__in=['retry', 'send'],
                                 customer=customer).count() < 10:
                    continue

                # 判断是否在发送间隔时间内, 如果在间隔时间内,则不发送通知
                if Notification.objects.filter(customer=customer,
                                               created__gt=need_time,
                                               type=type):
                    gevent.sleep(300)
                    continue
                content = Common.safe_format(content_format, **locals())
                notice(subject, content, type, customer=customer)
                notice(subject, content, type, manager=customer.tech)
            gevent.sleep(300)
        except:
            outerror(traceback.format_exc())
        gevent.sleep(300)
Beispiel #4
0
def jam_notice():
    """
    实时监控服务器处理状态,当中继检测数+中继传输数+中继重试数+网关检测数超过阀值时,发送通知
    :return:
    """
    global notice_setting, bounce_setting
    subject = u'服务器拥堵通知'
    redis = get_redis()
    while True:
        try:
            if notice_setting:
                outinfo('jam notice')
                jam_interval = notice_setting.jam_interval
                content_format = notice_setting.jam_content
                count_max = notice_setting.jam_count
                manager = notice_setting.manager
                need_time = datetime.datetime.now() - datetime.timedelta(
                    minutes=jam_interval)

                # 判断是否在发送间隔时间内, 如果在间隔时间内,则不发送通知
                if Notification.objects.filter(manager=manager,
                                               created__gt=need_time,
                                               type='jam'):
                    gevent.sleep(300)
                    continue

                relay_check = get_mail_count(get_mail_model, 'check')
                relay_dispatch = get_mail_count(get_mail_model, 'dispatch')
                relay_retry = get_mail_count(get_mail_model, 'retry')
                collect_check = get_mail_count(get_mail_model2, 'check')
                collect_send = get_mail_count(get_mail_model2, 'send')
                relay_error = Common.get_file_count(
                    '/home/umail/data/mails-error/')
                collect_error = Common.get_file_count(
                    '/home/umail/data/collect-mails-error/')
                count = relay_check + relay_dispatch + collect_check + collect_send + relay_retry + relay_error + collect_error
                if count >= count_max:
                    content = Common.safe_format(content_format, **locals())
                    notice(subject, content, 'jam', manager=manager)
            gevent.sleep(300)
        except:
            outerror(traceback.format_exc())
        gevent.sleep(300)
Beispiel #5
0
    c_spam_score_max = 5.0
    night_spam_score_max = 5.0
    subject_max_size = 0
    content_max_size = 0
    sender_max_size = 0
    spam_max_size = 0
    dspam_max_size = 0
    esets_max_size = 0
    ctasd_max_size = 0
    attachment_min_size = 0
    collect_attachment_min_size = 0


# 对象
# redis = get_redis_connection('default')
redis = get_redis()
ctasd = Ctasd(django_settings.CTASD_HOST, django_settings.CTASD_PORT_IN)
setting = DefaultSetting()

# 变量
_DEBUG = False

# CYBER 自动拒绝主题正则表示
# 网关CYBER中的主题是纯英文的自动拒绝
RES_CYBER_REJECT = u'^[ -~]*$'

signal_stop = False
_MAXTHREAD = 50
blacklist = {}

spf_checklist = {}
Beispiel #6
0
        log.info(
            'received %s mail: pid=%s, uid=%s, mail_from=%s, ok_rcpts=%s, body_len=%s, mail_id=%s, client_ip=%s'
            % (type, os.getpid(), uid, mailfrom, rcpttos, len(data), mail_id,
               client_ip))


if __name__ == '__main__':
    globals()['_DEBUG'] = Common.check_debug()
    #Common.init_makedir()
    Common.init_pid_file('bs_esmtpd.pid')
    Common.init_cfg_default()
    # Common.init_logger('Esmtpd', len(sys.argv) > 1, _DEBUG, user=Common.cfgDefault.get('global', 'user'))
    Common.signal_init(kill_children)

    # redis_db = get_redis_connection('default')
    redis_db = get_redis()
    auth = Authentication(connection, redis_db)
    listen_ip = Common.cfgDefault.get('esmtpd', 'listen_ip')
    listen_ports = map(
        lambda x: int(x),
        Common.cfgDefault.get('esmtpd', 'listen_port').split(','))
    timeout = int(Common.cfgDefault.get('esmtpd', 'timeout'))

    for listen_port in listen_ports:
        SMTPServer((listen_ip, listen_port),
                   ip_validator=auth.auth_by_ip,
                   user_validator=auth.auth_by_password,
                   domain_validator=auth.auth_by_domain,
                   collect_domain_validator=auth.auth_by_collect_domain,
                   timeout=timeout)
        log.info('emstpd bind on: %s:%s' % (listen_ip, listen_port))