Changeset - dcff662d5fd1
[Not reviewed]
default
0 1 0
Dennis Fink - 11 years ago 2014-07-15 19:48:56
dennis.fink@c3l.lu
Don't send mail if server status is already unknown and the new status is not
offline
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ennstatus/status/functions.py
Show inline comments
 
@@ -39,48 +39,49 @@ def _check_server(data):
 
    filename = os.path.join('data', '.'.join([server_name.lower(), 'json']))
 

	
 
    date = datetime.strptime(last_updated, '%d-%m-%Y %H:%M:%S')
 
    now = datetime.utcnow()
 
    delta = now - date
 

	
 
    if delta.days >= 7:
 
        os.remove(filename)
 
        current_app.logger.error('%s was removed!' % server_name)
 
        return False
 
    elif data['server_status'] == 'Offline':
 
        return data
 

	
 
    if delta.seconds >= 3600:
 
        status = 'Offline'
 
    elif delta.seconds >= 1200:
 
        status = 'Unknown'
 
    else:
 
        status = None
 

	
 
    if status is not None:
 
        current_app.logger.error('%s is set to %s' % (server_name,
 
                                 status))
 

	
 
        if data['server_status'] != 'Unknown' and status != 'Offline':
 
        _send_mail(server_name, status, last_updated)
 

	
 
        for key in ('server_status', 'tor_status'):
 
            data[key] = status
 

	
 
        with open(filename, mode='w', encoding='utf-8') as file_object:
 
            json.dump(data, file_object)
 

	
 
    return data
 

	
 

	
 
def _load_single_server(filename):
 

	
 
    try:
 
        with open(filename, encoding='utf-8') as f:
 
            server = json.load(f)
 
    except IOError:
 
        return False
 

	
 
    server = _check_server(server)
 
    return server
 

	
 

	
 
def single_server(name):
0 comments (0 inline, 0 general)