# 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



__author__ = 'Jesse Laptop'


class email_actions():
    def __init__(self):
        pass

    @staticmethod
    def send_alert(server_info_object):

        logging.debug(server_info_object)

        subj = server_info_object.sl_service_type + " @ " + server_info_object.sl_host + ' is DOWN'
        # noinspection PyListCreation
        msg = []  # Email Message Body
        msg.append('Report: ')

        msg.append('\nHost: ' + server_info_object.sl_host)
        msg.append('\nPort: ' + str(server_info_object.sl_port))
        msg.append('\nService: ' + server_info_object.sl_service_type)
        msg.append('\nNote: ' + str(server_info_object.sl_note))

        msg.append('\n\nReport Generated @ ' + str(datetime.now()))

        logging.debug('Subject:' + subj)
        logging.debug(''.join(msg))
        email_controller.send_gmail().send(subject=subj, text=''.join(msg))

# 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




__author__ = 'Jesse Laptop'


class email_actions():
    def __init__(self):
        pass

    @staticmethod
    def send_alert(server_info_object):

        logging.debug(server_info_object)

        subj = server_info_object.sl_service_type + " @ " + server_info_object.sl_host + ' is DOWN'
        # noinspection PyListCreation
        msg = []  # Email Message Body
        msg.append('Report: ')

        msg.append('\nHost: ' + server_info_object.sl_host)
        msg.append('\nPort: ' + str(server_info_object.sl_port))
        msg.append('\nService: ' + server_info_object.sl_service_type)
        msg.append('\nNote: ' + str(server_info_object.sl_note))

        msg.append('\n\nReport Generated @ ' + str(datetime.now()))

        logging.debug('Subject:' + subj)
        logging.debug(''.join(msg))
        email_controller.send_gmail().send(subject=subj, text=''.join(msg))

        db_helpers.email_log.log_email_sent(''.join(msg))