File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments