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

Add option to override structured data id length limit #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions rfc5424logging/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(
tls_client_key=None,
tls_key_password=None,
stream=None,
sd_id_limit_override=False,
):
"""
Returns a new instance of the Rfc5424SysLogHandler class intended to communicate with
Expand Down Expand Up @@ -216,6 +217,7 @@ def __init__(
self.tls_client_key = tls_client_key
self.tls_key_password = tls_key_password
self.stream = stream
self.sd_id_limit_override = sd_id_limit_override
self.transport = None

if not (isinstance(self.facility, int) and LOG_KERN <= self.facility <= LOG_LOCAL7):
Expand Down Expand Up @@ -400,11 +402,11 @@ def build_msg(self, record):
elif '@' in sd_id:
sd_id, enterprise_id = sd_id.rsplit('@', 1)

if len(enterprise_id) > 30:
if not self.sd_id_limit_override and len(enterprise_id) > 30:
raise ValueError("Enterprise ID is too long. Impossible to build structured data ID.")

sd_id = sd_id.replace('@', '')
if len(sd_id) + len(enterprise_id) > 32:
if not self.sd_id_limit_override and len(sd_id) + len(enterprise_id) > 32:
sd_id = sd_id[:31 - len(enterprise_id)]
if sd_id not in REGISTERED_SD_IDs:
sd_id = '@'.join((sd_id, enterprise_id))
Expand Down