From 984cecc3892a87ed81e1003b0ea1003dd1013ba1 Mon Sep 17 00:00:00 2001 From: Sviatoslav Boichuk Date: Tue, 24 Sep 2024 17:18:31 +0300 Subject: [PATCH] Try to get serial from state message or from state message params --- src/cgw_ucentral_ap_parser.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/cgw_ucentral_ap_parser.rs b/src/cgw_ucentral_ap_parser.rs index 4d64d8a..abea4ea 100644 --- a/src/cgw_ucentral_ap_parser.rs +++ b/src/cgw_ucentral_ap_parser.rs @@ -359,11 +359,17 @@ fn parse_state_event_data( } }; - let serial = MacAddress::from_str( - state_map["serial"] - .as_str() - .ok_or_else(|| Error::UCentralParser("Failed to parse mac address"))?, - )?; + let serial = { + if let Value::String(mac) = ¶ms["serial"] { + MacAddress::from_str(mac)? + } else if let Value::String(mac) = &state_map["serial"] { + MacAddress::from_str(mac)? + } else { + return Err(Error::UCentralParser( + "Failed to parse state: mac address is missing", + )); + } + }; if let Value::Object(state_map) = &state_map["state"] { let mut lldp_links: HashMap< @@ -448,11 +454,18 @@ fn parse_state_event_data( "Parsed, decompressed state message but failed to find state object", )); } else if let Value::Object(state_map) = ¶ms["state"] { - let serial = MacAddress::from_str( - params["serial"] - .as_str() - .ok_or_else(|| Error::UCentralParser("Failed to parse mac address"))?, - )?; + let serial = { + if let Value::String(mac) = ¶ms["serial"] { + MacAddress::from_str(mac)? + } else if let Value::String(mac) = &state_map["serial"] { + MacAddress::from_str(mac)? + } else { + return Err(Error::UCentralParser( + "Failed to parse state: mac address is missing", + )); + } + }; + let mut lldp_links: HashMap> = HashMap::new(); let mut clients_links: HashMap<