Skip to content

Commit

Permalink
added debug logging and local connection to test
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtycajunrice committed Jan 13, 2019
1 parent 9561ecb commit 39c827b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pyouroboros/notifiers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests

from email.message import EmailMessage
from smtplib import SMTP, SMTPConnectError, SMTPAuthenticationError
from smtplib import SMTP, SMTPConnectError, SMTPAuthenticationError, SMTPServerDisconnected
from logging import getLogger
from datetime import datetime, timezone
from requests.exceptions import RequestException
Expand Down Expand Up @@ -32,9 +32,12 @@ def __init__(self, config, data_manager):
self.data_manager = data_manager

self.logger = getLogger()
self.server = self.initialize()
if self.config.smtp_host:
self.server = True
else:
self.server = False

def initialize(self):
def get_server(self):
try:
server = SMTP(
host=self.config.smtp_host,
Expand Down Expand Up @@ -75,7 +78,13 @@ def send(self, container_tuples, socket):
CONTAINER_UPDATES=container_updates)

msg.set_content(template)
self.server.send_message(msg)
server = self.get_server()
server.set_debuglevel(1)
try:
server.send_message(msg)
except SMTPServerDisconnected as e:
self.server = False
self.logger.error('Could not properly talk to SMTP server. Disabling SMTP. Error: %s', e)


class Webhooks(object):
Expand Down

0 comments on commit 39c827b

Please sign in to comment.