Skip to content

Commit 1ff10fa

Browse files
committed
[385] Fix for stuck consumers due to unsafe host key access
Vendors like IOS-XR by default send messages with no hostname. Log parsers were updated to support this. This PR fixes the server.py unsafe access for the host key in msg_dict which cause the consumer/listeners to become stuck as they are expecting messages to have a host key for lookup. Signed-off-by: Adrian Arumugam <[email protected]>
1 parent 1778d79 commit 1ff10fa

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

napalm_logs/server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ def start(self):
301301
if self._buffer:
302302
message = "{dev_os}/{host}/{msg}".format(
303303
dev_os=dev_os.decode(),
304-
host=msg_dict["host"],
304+
# Host is not always present (e.g IOS-XR by default doesn't include the hostname in the message)
305+
# This ensures the key is safely accessed and returns 'unknown' if not present.
306+
host=msg_dict.get("host", "unknown"),
305307
msg=msg_dict["message"],
306308
)
307309
message_key = base64.b64encode(bytes(message, "utf-8")).decode()
@@ -327,7 +329,9 @@ def start(self):
327329
if self.opts.get("metrics_server_include_attributes", True):
328330
napalm_logs_server_messages_attrs.labels(
329331
device_os=dev_os.decode(),
330-
host=msg_dict["host"],
332+
# Host is not always present (e.g IOS-XR by default doesn't include the hostname in the message).
333+
# This ensures the key is safely accessed and returns 'unknown' if not present.
334+
host=msg_dict.get("host", "unknown"),
331335
tag=msg_dict["tag"],
332336
).inc()
333337

0 commit comments

Comments
 (0)