Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- 'pypy3.9'
- '3.12'
- '3.13'
- 'pypy3.10'
- 'pypy3.11'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ indent-after-paren=4
expected-line-ending-format=LF

[MESSAGES CONTROL]
disable=C0111,too-many-arguments,too-many-instance-attributes,deprecated-method
disable=C0111,too-many-arguments,too-many-instance-attributes,too-many-positional-arguments

[REPORTS]
reports=no
reports=no
28 changes: 16 additions & 12 deletions pygelf/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,26 @@ def __init__(self, validate=False, ca_certs=None, certfile=None, keyfile=None, *

GelfTcpHandler.__init__(self, **kwargs)

self.ca_certs = ca_certs
self.reqs = ssl.CERT_REQUIRED if validate else ssl.CERT_NONE
self.certfile = certfile
self.keyfile = keyfile if keyfile else certfile
self.ctx = ssl.create_default_context()

def makeSocket(self, timeout=1):
plain_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if not validate:
self.ctx.check_hostname = False
self.ctx.verify_mode = ssl.CERT_NONE

if ca_certs:
self.ctx.load_verify_locations(cafile=ca_certs)

if hasattr(plain_socket, 'settimeout'):
plain_socket.settimeout(timeout)
if certfile:
self.ctx.load_cert_chain(certfile, keyfile)

def makeSocket(self, timeout=1):
plain = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
plain.settimeout(timeout)

wrapped_socket = ssl.wrap_socket(plain_socket, ca_certs=self.ca_certs, cert_reqs=self.reqs,
keyfile=self.keyfile, certfile=self.certfile)
wrapped_socket.connect((self.host, self.port))
wrapped = self.ctx.wrap_socket(plain, server_hostname=self.host)
wrapped.connect((self.host, self.port))

return wrapped_socket
return wrapped


class GelfHttpHandler(BaseHandler, LoggingHandler):
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='pygelf',
version='0.4.2',
version='0.4.3',
packages=['pygelf'],
description='Logging handlers with GELF support',
keywords='logging udp tcp ssl tls graylog2 graylog gelf',
Expand All @@ -20,6 +20,8 @@
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: System :: Logging',
Expand Down
4 changes: 2 additions & 2 deletions tests/config/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ services:
- GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
- GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
volumes:
- ./cert.pem:/usr/share/graylog/data/cert.pem
- ./key.pem:/usr/share/graylog/data/key.pem
- ./cert.pem:/usr/share/graylog/data/cert.pem:ro
- ./key.pem:/usr/share/graylog/data/key.pem:ro
links:
- mongo
- elasticsearch
Expand Down
7 changes: 1 addition & 6 deletions tests/config/graylog-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ HTTPS_INPUT='{
"tls_key_file": "/usr/share/graylog/data/key.pem"
},
"type": "org.graylog2.inputs.gelf.http.GELFHttpInput",
"global": true
"global": true
}'

curl -u admin:admin "$API_URL/search/universal/relative?query=test&range=5&fields=message" > /dev/null
Expand All @@ -76,9 +76,4 @@ sleep 10
for _ in {1..5}; do
curl -X "POST" -H "Content-Type: application/json" "http://localhost:12203/gelf" -p0 -d '{"short_message": "warm-up", "host": "localhost"}'
sleep 1
curl -k -X "POST" -H "Content-Type: application/json" "https://localhost:12205/gelf" -p0 -d '{"short_message": "warm-up", "host": "localhost"}'
sleep 1
done

docker exec -u 0 $(docker ps |grep graylog | awk '{print $1}') chown graylog data/key.pem
docker exec -u 0 $(docker ps |grep graylog | awk '{print $1}') chmod 0600 data/key.pem
16 changes: 8 additions & 8 deletions tests/test_common_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@


@pytest.fixture(params=[
GelfTcpHandler(host='127.0.0.1', port=12201),
GelfUdpHandler(host='127.0.0.1', port=12202),
GelfUdpHandler(host='127.0.0.1', port=12202, compress=False),
GelfHttpHandler(host='127.0.0.1', port=12203),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False),
GelfTlsHandler(host='127.0.0.1', port=12204),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False),
GelfTcpHandler(host='localhost', port=12201),
GelfUdpHandler(host='localhost', port=12202),
GelfUdpHandler(host='localhost', port=12202, compress=False),
GelfHttpHandler(host='localhost', port=12203),
GelfHttpHandler(host='localhost', port=12203, compress=False),
GelfTlsHandler(host='localhost', port=12204),
GelfHttpsHandler(host='localhost', port=12205, validate=False),
GelfHttpsHandler(host='localhost', port=12205, validate=True, ca_certs='tests/config/cert.pem'),
GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
GelfTlsHandler(host='localhost', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
])
def handler(request):
return request.param
Expand Down
14 changes: 7 additions & 7 deletions tests/test_debug_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@


@pytest.fixture(params=[
GelfTcpHandler(host='127.0.0.1', port=12201, debug=True),
GelfUdpHandler(host='127.0.0.1', port=12202, debug=True),
GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, debug=True),
GelfHttpHandler(host='127.0.0.1', port=12203, debug=True),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, debug=True),
GelfTlsHandler(host='127.0.0.1', port=12204, debug=True),
GelfTlsHandler(host='127.0.0.1', port=12204, debug=True, validate=True, ca_certs='tests/config/cert.pem'),
GelfTcpHandler(host='localhost', port=12201, debug=True),
GelfUdpHandler(host='localhost', port=12202, debug=True),
GelfUdpHandler(host='localhost', port=12202, compress=False, debug=True),
GelfHttpHandler(host='localhost', port=12203, debug=True),
GelfHttpHandler(host='localhost', port=12203, compress=False, debug=True),
GelfTlsHandler(host='localhost', port=12204, debug=True),
GelfTlsHandler(host='localhost', port=12204, debug=True, validate=True, ca_certs='tests/config/cert.pem'),
GelfHttpsHandler(host='localhost', port=12205, debug=True, validate=True, ca_certs='tests/config/cert.pem')

])
Expand Down
16 changes: 8 additions & 8 deletions tests/test_dynamic_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def filter(self, record):


@pytest.fixture(params=[
GelfTcpHandler(host='127.0.0.1', port=12201, include_extra_fields=True),
GelfUdpHandler(host='127.0.0.1', port=12202, include_extra_fields=True),
GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, include_extra_fields=True),
GelfHttpHandler(host='127.0.0.1', port=12203, include_extra_fields=True),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, include_extra_fields=True),
GelfTlsHandler(host='127.0.0.1', port=12204, include_extra_fields=True),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False, include_extra_fields=True),
GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', include_extra_fields=True),
GelfTcpHandler(host='localhost', port=12201, include_extra_fields=True),
GelfUdpHandler(host='localhost', port=12202, include_extra_fields=True),
GelfUdpHandler(host='localhost', port=12202, compress=False, include_extra_fields=True),
GelfHttpHandler(host='localhost', port=12203, include_extra_fields=True),
GelfHttpHandler(host='localhost', port=12203, compress=False, include_extra_fields=True),
GelfTlsHandler(host='localhost', port=12204, include_extra_fields=True),
GelfHttpsHandler(host='localhost', port=12205, validate=False, include_extra_fields=True),
GelfTlsHandler(host='localhost', port=12204, validate=True, ca_certs='tests/config/cert.pem', include_extra_fields=True),
])
def handler(request):
return request.param
Expand Down
6 changes: 3 additions & 3 deletions tests/test_handler_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

def test_tls_handler_init():
with pytest.raises(ValueError):
GelfTlsHandler(host='127.0.0.1', port=12204, validate=True)
GelfTlsHandler(host='localhost', port=12204, validate=True)

with pytest.raises(ValueError):
GelfTlsHandler(host='127.0.0.1', port=12204, keyfile='/dev/null')
GelfTlsHandler(host='localhost', port=12204, keyfile='/dev/null')


def test_https_handler_init():
with pytest.raises(ValueError):
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=True)
GelfHttpsHandler(host='localhost', port=12205, validate=True)
16 changes: 8 additions & 8 deletions tests/test_queuehandler_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@


@pytest.fixture(params=[
GelfTcpHandler(host='127.0.0.1', port=12201),
GelfUdpHandler(host='127.0.0.1', port=12202),
GelfUdpHandler(host='127.0.0.1', port=12202, compress=False),
GelfHttpHandler(host='127.0.0.1', port=12203),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False),
GelfTlsHandler(host='127.0.0.1', port=12204),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False),
GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
GelfTcpHandler(host='localhost', port=12201),
GelfUdpHandler(host='localhost', port=12202),
GelfUdpHandler(host='localhost', port=12202, compress=False),
GelfHttpHandler(host='localhost', port=12203),
GelfHttpHandler(host='localhost', port=12203, compress=False),
GelfTlsHandler(host='localhost', port=12204),
GelfHttpsHandler(host='localhost', port=12205, validate=False),
GelfTlsHandler(host='localhost', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
GelfHttpsHandler(host='localhost', port=12205, validate=True, ca_certs='tests/config/cert.pem'),
])
def handler(request):
Expand Down
30 changes: 15 additions & 15 deletions tests/test_static_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@


@pytest.fixture(params=[
GelfTcpHandler(host='127.0.0.1', port=12201, **STATIC_FIELDS),
GelfUdpHandler(host='127.0.0.1', port=12202, **STATIC_FIELDS),
GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, **STATIC_FIELDS),
GelfHttpHandler(host='127.0.0.1', port=12203, **STATIC_FIELDS),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, **STATIC_FIELDS),
GelfTlsHandler(host='127.0.0.1', port=12204, **STATIC_FIELDS),
GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', **STATIC_FIELDS),
GelfTcpHandler(host='127.0.0.1', port=12201, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfUdpHandler(host='127.0.0.1', port=12202, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfUdpHandler(host='127.0.0.1', port=12202, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfHttpHandler(host='127.0.0.1', port=12203, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfTlsHandler(host='127.0.0.1', port=12204, static_fields=STATIC_FIELDS),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfTcpHandler(host='localhost', port=12201, **STATIC_FIELDS),
GelfUdpHandler(host='localhost', port=12202, **STATIC_FIELDS),
GelfUdpHandler(host='localhost', port=12202, compress=False, **STATIC_FIELDS),
GelfHttpHandler(host='localhost', port=12203, **STATIC_FIELDS),
GelfHttpHandler(host='localhost', port=12203, compress=False, **STATIC_FIELDS),
GelfTlsHandler(host='localhost', port=12204, **STATIC_FIELDS),
GelfTlsHandler(host='localhost', port=12204, validate=True, ca_certs='tests/config/cert.pem', **STATIC_FIELDS),
GelfTcpHandler(host='localhost', port=12201, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfUdpHandler(host='localhost', port=12202, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfUdpHandler(host='localhost', port=12202, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfHttpHandler(host='localhost', port=12203, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfHttpHandler(host='localhost', port=12203, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfTlsHandler(host='localhost', port=12204, static_fields=STATIC_FIELDS),
GelfHttpsHandler(host='localhost', port=12205, validate=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfTlsHandler(host='localhost', port=12204, validate=True, ca_certs='tests/config/cert.pem', static_fields=STATIC_FIELDS, _ozzy='billie jean'),
])
def handler(request):
return request.param
Expand Down