-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added method sonicprobe.libs.workerpool.WorkerPool.run_args.
- Loading branch information
Adrien Delle Cave
committed
Jan 13, 2020
1 parent
113ced1
commit eb8952c
Showing
8 changed files
with
112 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.3.23 | ||
0.3.24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.3.23 | ||
0.3.24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
httpdis>=0.6.10 | ||
httpdis>=0.6.11 | ||
pyOpenSSL | ||
python-magic | ||
psutil>=2.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2015-2019 Adrien Delle Cave | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
"""sonicprobe.sp_logging.handlers""" | ||
|
||
import smtplib | ||
|
||
try: | ||
from email.utils import formatdate | ||
except ImportError: | ||
from email.Utils import formatdate | ||
|
||
from logging.handlers import SMTPHandler | ||
|
||
import six | ||
|
||
|
||
class QueueSMTPHandler(SMTPHandler): | ||
def __init__(self, mailhost, fromaddr, toaddrs, subject, | ||
credentials = None, secure = None, timeout = 5.0, logger_name = None): | ||
self.queues = {} | ||
self.logger_name = logger_name | ||
self._timeout = timeout | ||
|
||
if six.PY2: | ||
SMTPHandler.__init__(self, mailhost, fromaddr, toaddrs, subject, credentials, secure) | ||
else: | ||
SMTPHandler.__init__(self, mailhost, fromaddr, toaddrs, subject, credentials, secure, timeout) | ||
|
||
def isEmpty(self): | ||
return len(self.queues) == 0 | ||
|
||
def getSubject(self, record): | ||
if self.logger_name: | ||
return "[%s] %s Event" % (self.logger_name, record.levelname) | ||
return "%s Event" % record.levelname | ||
|
||
def emit(self, record): | ||
if record.levelname not in self.queues: | ||
self.queues[record.levelname] = [] | ||
|
||
self.queues[record.levelname].append(record) | ||
|
||
def purge(self): | ||
if self.isEmpty(): | ||
return | ||
|
||
queues = dict(self.queues) | ||
self.queues = {} | ||
|
||
for records in six.itervalues(queues): | ||
msg = "" | ||
record = None | ||
|
||
for record in records: | ||
msg += "%s\n" % self.format(record) | ||
|
||
if not record: | ||
continue | ||
|
||
smtp = None | ||
|
||
try: | ||
port = self.mailport | ||
if not port: | ||
port = smtplib.SMTP_PORT | ||
smtp = smtplib.SMTP(self.mailhost, port, timeout=self._timeout) | ||
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % | ||
(self.fromaddr, | ||
",".join(self.toaddrs), | ||
self.getSubject(record), | ||
formatdate(), | ||
msg)) | ||
if self.username: | ||
if self.secure is not None: | ||
smtp.ehlo() | ||
smtp.starttls(*self.secure) | ||
smtp.ehlo() | ||
smtp.login(self.username, self.password) | ||
smtp.sendmail(self.fromaddr, self.toaddrs, msg) | ||
except (KeyboardInterrupt, SystemExit): | ||
raise | ||
except Exception: | ||
self.handleError(record) | ||
finally: | ||
if smtp: | ||
smtp.quit() |