Changeset - 5f9e26cdf064
[Not reviewed]
default
0 2 0
Dennis Fink - 10 years ago 2014-10-17 14:54:42
dennis.fink@c3l.lu
Enable debug_log if user specified it in the webapp config
2 files changed with 11 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/functions.py
Show inline comments
 
@@ -3,12 +3,14 @@ import re
 
import json
 

	
 
from datetime import datetime
 

	
 
import pygeoip
 

	
 
from flask import current_app
 

	
 
from ennstatus.status.functions import _send_mail
 

	
 

	
 
FINGERPRINT_REGEX = re.compile(r'^[A-Z0-9]{40}$', re.I)
 

	
 
IP_REGEX = (r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
 
@@ -71,12 +73,13 @@ def check_json_format(server):
 

	
 
    return True
 

	
 

	
 
def _send_offline_mail(server_name, last_updated):
 

	
 
    current_app.logger.info('Sending tor status offline mail!')
 
    subject = '[Ennstatus] %s Tor status went offline'
 
    _send_mail(server_name, last_updated, subject)
 
    mail_cache[server_name] = datetime.utcnow()
 

	
 

	
 
def update_server(server, ip):
 
@@ -104,20 +107,27 @@ def update_server(server, ip):
 
    except Exception as e:
 
        return e
 

	
 
    if server['tor_status'] == 'Offline':
 

	
 
        if server_name in mail_cache:
 

	
 
            current_app.logger.debug('Mail cache is %s' % str(mail_cache))
 

	
 
            send_date = mail_cache[server_name]
 
            now = datetime.utcnow()
 
            delta = now - send_date
 

	
 
            if delta.seconds <= 7200:
 
                current_app.logger.debug('Server is in mail cache but not old enough to resend mail')
 
                return server
 
            else:
 
                current_app.logger.debug('Server tor status is offline for more than 7200 seconds')
 
                _send_offline_mail(server_name, server['last_updated'])
 
        else:
 
            current_app.logger.debug('Server is not in mail cache')
 
            _send_offline_mail(server_name, server['last_updated'])
 
    elif server_name in mail_cache:
 
        current_app.logger.debug('Removing server from mail cache')
 
        del mail_cache[server_name]
 

	
 
    return server
ennstatus/log.py
Show inline comments
 
@@ -21,13 +21,13 @@ def init_logging(app):
 
        maxBytes=1300000,
 
        backupCount=10,
 
        encoding='utf-8')
 
    rotating_file_handler.setLevel(logging.INFO)
 
    rotating_file_handler.setFormatter(logging_formatter)
 

	
 
    if app.debug:
 
    if app.debug or app.config['ENABLE_DEBUG_LOG']:
 
        second_rotating_file_handler = logging.handlers.RotatingFileHandler(
 
            'log/ennstatus_debug.log',
 
            maxBytes=1300000,
 
            backupCount=20,
 
            encoding='utf-8')
 
        second_rotating_file_handler.setLevel(logging.DEBUG)
0 comments (0 inline, 0 general)