# HG changeset patch # User Dennis Fink # Date 2015-08-21 16:17:13 # Node ID 45f57c8cb5d564766f94065201f9dc6a798c39f3 # Parent 1585155d7c8ae46773368b64150ed94a5e473d98 Remove offline mail feature diff --git a/ennstatus/status/functions.py b/ennstatus/status/functions.py --- a/ennstatus/status/functions.py +++ b/ennstatus/status/functions.py @@ -13,91 +13,6 @@ from ..api.model import Server mail = Mail() -def _send_mail(server_name, last_updated, subject=None): - - current_app.logger.info('Try sending mail') - try: - if subject is None: - subject = '[Ennstatus] %s went offline' - msg = Message(subject % server_name, - sender='ennstatus@enn.lu') - recipient = current_app.config['SERVER_ADMINS'][server_name] - msg.add_recipient(recipient) - - body = ('%s went offline. I received the last update at %s' - % (server_name, last_updated)) - - if current_app.extensions['gnupg']: - body = str(current_app.extensions['gnupg'].encrypt(body, recipient, - always_trust=True)) - msg.body = body - - mail.send(msg) - except KeyError: - current_app.logger.error('Admin for %s not found!' % server_name) - except AssertionError: - pass - except Exception as e: - current_app.logger.error('Unexpected error: %s' % e, - exc_info=True) - current_app.logger.info('Finished trying!') - - -def _check_server(data): - - server_name = data['server_name'] - last_updated = data['last_updated'] - current_status = data['server_status'] - 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 current_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 (current_status == 'Online' or current_status == 'Unknown') and \ - status == 'Offline': - _send_mail(server_name, 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): - - current_app.logger.info('Loading {}'.format(filename)) - try: - with open(filename, encoding='utf-8') as f: - server = json.load(f) - except (IOError, ValueError): - return False - - server = _check_server(server) - return server - - def single_server(name): server = Server.from_file_by_name(name)