Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding journald and enabling syslog logging #542

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions conpot/core/loggers/syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,31 @@
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from logging.handlers import SysLogHandler
import logging
import socket

from logging.handlers import SysLogHandler


class SysLogger(object):
def __init__(self, host, port, facility, logdevice, logsocket):
logger = logging.getLogger()
self.logger = logging.getLogger("conpot")
handler = logging.StreamHandler()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we're silently swallowing configuration errors (typos mostly). It's also a bit odd to have a "SyslogLogger" print to the console. I'd rather raise an error below.

Alternatively we could make this behavior explicit, like if str(logsocket).lower() == "stderr":, because it should actually be useful to have events printed to the console. At that point we may as well rename "socket" to "mode".

But then we should be able to use /dev/stderr to the same effect - but I haven't tested it.


if str(logsocket).lower() == "udp":
logger.addHandler(
SysLogHandler(
address=(host, port),
facility=getattr(SysLogHandler, "LOG_" + str(facility).upper()),
socktype=socket.SOCK_DGRAM,
)
handler = SysLogHandler(
address=(host, port),
facility=getattr(SysLogHandler, "LOG_" + str(facility).upper()),
socktype=socket.SOCK_DGRAM,
)
elif str(logsocket).lower() == "dev":
logger.addHandler(SysLogHandler(logdevice))
handler = SysLogHandler(address=logdevice)

formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)

def log(self, data):
# stub function since the additional handler has been added to the root loggers instance.
pass
def log(self, event):
self.logger.info(event)
3 changes: 2 additions & 1 deletion conpot/testing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ device = /dev/log
host = localhost
port = 514
facility = local0
socket = dev ; udp (sends to host:port), dev (sends to device)
;udp (sends to host:port), dev (sends to device)
socket = dev

[hpfriends]
enabled = False
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ cpppo
fs==2.3.0
python-slugify
tftpy
# some freezegun versions broken
freezegun!=0.3.13
freezegun==1.1.0
pytest
pycrypto
sphinx_rtd_theme
Expand Down