# Path: ramjet/engines.py
# class LazyExecutor:
#     def __init__(self, executor_class, *args, **kw):
#     def setup_executor(self):
#     def __getattr__(self, name):
# def shutdown_all_engines():
# 
# Path: ramjet/utils/mail.py
# def send_mail(*, to_addrs, subject, content, from_addr=MAIL_FROM_ADDR):
#     """Send email
# 
#     Args:
#         fr (string):
#         to (list): receivers' addresses
#     """
#     smtp = smtplib.SMTP(host=MAIL_HOST, port=MAIL_PORT)
#     smtp.starttls()
#     smtp.login(MAIL_USERNAME, MAIL_PASSWD)
# 
#     msg = MIMEMultipart("alternative")
#     msg.set_charset("utf-8")
#     msg["From"] = from_addr
#     msg["To"] = ", ".join(to_addrs[0].split(";"))
#     msg["Subject"] = subject
#     msg.attach(MIMEText(content, "plain"))
#     try:
#         smtp.sendmail(from_addr, to_addrs, msg.as_string())
#     except Exception:
#         smtp.close()
#         raise
# 
# Path: ramjet/tasks/monitors/base.py



import socket
import datetime
import ssl
from textwrap import dedent
from ramjet.engines import ioloop, thread_executor
from ramjet.utils import send_mail
from .base import logger as monitor_logger


ALERT_RECEIVERS = ['ppcelery@gmail.com']
DOMAINS = [
    'blog.laisky.com',
]


logger = monitor_logger.getChild('ssl_cert')


def bind_task():
    def run():
        logger.info('running...')
        thread_executor.submit(main)
        ioloop.call_later(24*3600, run)

    run()


def main():
    try:
        for domain in DOMAINS:
            expired_at = load_ssl_expiry_datetime(domain)
            if is_need_to_alert(expired_at):
                send_alert_email(domain, expired_at)
    except Exception as err:
        logger.exception(err)



# Path: ramjet/engines.py
# class LazyExecutor:
#     def __init__(self, executor_class, *args, **kw):
#     def setup_executor(self):
#     def __getattr__(self, name):
# def shutdown_all_engines():
# 
# Path: ramjet/utils/mail.py
# def send_mail(*, to_addrs, subject, content, from_addr=MAIL_FROM_ADDR):
#     """Send email
# 
#     Args:
#         fr (string):
#         to (list): receivers' addresses
#     """
#     smtp = smtplib.SMTP(host=MAIL_HOST, port=MAIL_PORT)
#     smtp.starttls()
#     smtp.login(MAIL_USERNAME, MAIL_PASSWD)
# 
#     msg = MIMEMultipart("alternative")
#     msg.set_charset("utf-8")
#     msg["From"] = from_addr
#     msg["To"] = ", ".join(to_addrs[0].split(";"))
#     msg["Subject"] = subject
#     msg.attach(MIMEText(content, "plain"))
#     try:
#         smtp.sendmail(from_addr, to_addrs, msg.as_string())
#     except Exception:
#         smtp.close()
#         raise
# 
# Path: ramjet/tasks/monitors/base.py



# Path: ramjet/tasks/monitors/ssl_cert.py
import socket
import datetime
import ssl
from textwrap import dedent
from ramjet.engines import ioloop, thread_executor
from ramjet.utils import send_mail
from .base import logger as monitor_logger



ALERT_RECEIVERS = ['ppcelery@gmail.com']
DOMAINS = [
    'blog.laisky.com',
]


logger = monitor_logger.getChild('ssl_cert')


def bind_task():
    def run():
        logger.info('running...')
        thread_executor.submit(main)
        ioloop.call_later(24*3600, run)

    run()


def main():
    try:
        for domain in DOMAINS:
            expired_at = load_ssl_expiry_datetime(domain)
            if is_need_to_alert(expired_at):
                send_alert_email(domain, expired_at)
    except Exception as err:
        logger.exception(err)



def send_alert_email(domain, expired_at):