# 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
# class gmailSettings():
# class SettingsHelper(gmailSettings):
# class send_gmail(object, SettingsHelper):
#     USERNAME = ""
#     SEND_ALERT_TO = []  # Must be a list
#     SETTINGS_FILE_PATH = "email_settings.json"
#     KEYRING_APP_ID = 'NetworkMonitor_email'
#     def loadSettings(cls):
#     def saveSettings(cls):
#     def __init__(self):
#     def test_login(self):
#     def send(self, subject, text):
#     def convert_to_list_to_csv(self):
#     def configure(self):
#     def clear_password_store(self):


from datetime import datetime
from Database import db_helpers
from Alerters import email_controller
import logging
        msg.append('# of services failed: ' + str(len(unique_failed_monitors)) + '\n\n')

        # Generates list of failed services
        msg.append('-' * 70 + '\n')
        msg.append("| {0} |".format(str('Failed Servers').ljust(66)) + '\n')
        msg.append('-' * 70 + '\n')
        for i in unique_failed_monitors:
            msg.append("| {0} |".format(str(i).ljust(66)))
            msg.append('\n')
        msg.append('-' * 70 + '\n\n')

        # Generates log of failures
        msg.append(email_actions.generate_fail_table(fail_list, monitor_list))  # Calls the fail table generator above

        # Generates table of monitored services
        msg.append("\nMonitored Servers / Services:" +
                   '\n' + '-' * 98 + '\n' + "| {0} | {1} | {2} | {3} |".format("Hostname".ljust(35), "Port".ljust(10),
                                                                               "Service".ljust(15),
                                                                               "Note".ljust(17 + 8)) +
                   '\n' + '-' * 98 + '\n')
        for i in monitor_list:
            msg.append("| {0} | {1} | {2} | {3} |".format(str(i[1]).ljust(35), str(i[2]).ljust(10),
                                                          str(i[3]).ljust(15), str(i[4]).ljust(17 + 8)), )
            msg.append('\n')
        msg.append('-' * 98)
        # FIXME Create nice looking table

        msg.append('\n\nReport Generated @ ' + str(datetime.now()))
        logging.debug('\n' + ''.join(msg))
        logging.debug('BREAKPOINT')

# 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
# class gmailSettings():
# class SettingsHelper(gmailSettings):
# class send_gmail(object, SettingsHelper):
#     USERNAME = ""
#     SEND_ALERT_TO = []  # Must be a list
#     SETTINGS_FILE_PATH = "email_settings.json"
#     KEYRING_APP_ID = 'NetworkMonitor_email'
#     def loadSettings(cls):
#     def saveSettings(cls):
#     def __init__(self):
#     def test_login(self):
#     def send(self, subject, text):
#     def convert_to_list_to_csv(self):
#     def configure(self):
#     def clear_password_store(self):


# Path: Alerters/email_alerts.py
from datetime import datetime
from Database import db_helpers
from Alerters import email_controller
import logging

        msg.append('# of services failed: ' + str(len(unique_failed_monitors)) + '\n\n')

        # Generates list of failed services
        msg.append('-' * 70 + '\n')
        msg.append("| {0} |".format(str('Failed Servers').ljust(66)) + '\n')
        msg.append('-' * 70 + '\n')
        for i in unique_failed_monitors:
            msg.append("| {0} |".format(str(i).ljust(66)))
            msg.append('\n')
        msg.append('-' * 70 + '\n\n')

        # Generates log of failures
        msg.append(email_actions.generate_fail_table(fail_list, monitor_list))  # Calls the fail table generator above

        # Generates table of monitored services
        msg.append("\nMonitored Servers / Services:" +
                   '\n' + '-' * 98 + '\n' + "| {0} | {1} | {2} | {3} |".format("Hostname".ljust(35), "Port".ljust(10),
                                                                               "Service".ljust(15),
                                                                               "Note".ljust(17 + 8)) +
                   '\n' + '-' * 98 + '\n')
        for i in monitor_list:
            msg.append("| {0} | {1} | {2} | {3} |".format(str(i[1]).ljust(35), str(i[2]).ljust(10),
                                                          str(i[3]).ljust(15), str(i[4]).ljust(17 + 8)), )
            msg.append('\n')
        msg.append('-' * 98)
        # FIXME Create nice looking table

        msg.append('\n\nReport Generated @ ' + str(datetime.now()))
        logging.debug('\n' + ''.join(msg))
        logging.debug('BREAKPOINT')

        email_controller.send_gmail().send(subject=subj, text=''.join(msg))