# Path: Database/db_helpers.py
# class server_stats(object):
# class email_log(object):
# class monitor_list(object):
#     class tcp():
#     class host():
#     class url():
#     def failures_in_x_minutes_ago(last_x_minutes_of_failures):
#     def log_email_sent(to_list):
#     def email_sent_x_minutes_ago():
#     def get_server_list():
#     def get_time_from_last_failure():
#     def log_service_down(server_logger_obj):
#     def remove_server_from_monitor_list(index_to_remove):
#         def __init__(self):
#         def create_server(ip_address, port, note=None):
#         def __init__(self):
#         def create_server(ip_address, note=None):
#         def __init__(self):
#         def create_server(web_url, note=None):


import getpass
import json
import logging
import os
import smtplib  # For Authentication Error
import sys
import urllib2
import gmail
import keyring
        import distutils.util
from Database import db_helpers
from keyring.errors import PasswordDeleteError
        except urllib2.URLError:
            pass

        if http_response_code == 200:
            response_flag = True
        else:
            response_flag = False
            logging.error('Cannot reach gmail.com')

        logging.debug('Testing login')
        if response_flag:
            try:
                logging.debug(str(self.USERNAME) + str(self.PASSWORD))
                gmail.GMail(username=self.USERNAME, password=self.PASSWORD)
                login_flag = True
            except smtplib.SMTPAuthenticationError:
                logging.critical('Bad gmail login info, cannot send messages, exiting')
                sys.exit(1)
        else:
            login_flag = False

        if login_flag and response_flag:
            return True
        else:
            return False

    def send(self, subject, text):
        logging.info("Sending email")
        gmail.GMail(username=self.USERNAME, password=self.PASSWORD).send(
            gmail.Message(subject=subject, to=self.convert_to_list_to_csv(), text=text))

# Path: Database/db_helpers.py
# class server_stats(object):
# class email_log(object):
# class monitor_list(object):
#     class tcp():
#     class host():
#     class url():
#     def failures_in_x_minutes_ago(last_x_minutes_of_failures):
#     def log_email_sent(to_list):
#     def email_sent_x_minutes_ago():
#     def get_server_list():
#     def get_time_from_last_failure():
#     def log_service_down(server_logger_obj):
#     def remove_server_from_monitor_list(index_to_remove):
#         def __init__(self):
#         def create_server(ip_address, port, note=None):
#         def __init__(self):
#         def create_server(ip_address, note=None):
#         def __init__(self):
#         def create_server(web_url, note=None):


# Path: Alerters/email_controller.py
import getpass
import json
import logging
import os
import smtplib  # For Authentication Error
import sys
import urllib2
import gmail
import keyring
        import distutils.util
from Database import db_helpers
from keyring.errors import PasswordDeleteError

        except urllib2.URLError:
            pass

        if http_response_code == 200:
            response_flag = True
        else:
            response_flag = False
            logging.error('Cannot reach gmail.com')

        logging.debug('Testing login')
        if response_flag:
            try:
                logging.debug(str(self.USERNAME) + str(self.PASSWORD))
                gmail.GMail(username=self.USERNAME, password=self.PASSWORD)
                login_flag = True
            except smtplib.SMTPAuthenticationError:
                logging.critical('Bad gmail login info, cannot send messages, exiting')
                sys.exit(1)
        else:
            login_flag = False

        if login_flag and response_flag:
            return True
        else:
            return False

    def send(self, subject, text):
        logging.info("Sending email")
        gmail.GMail(username=self.USERNAME, password=self.PASSWORD).send(
            gmail.Message(subject=subject, to=self.convert_to_list_to_csv(), text=text))

        db_helpers.email_log.log_email_sent(self.SEND_ALERT_TO)