diagnostics: Fix panic when a NIC doesn't have a mac address
@@ -377,11 +377,18 @@ fn disk_hardware_info(collector: &mut Vec<ServerInfoItem>) {
}
}
+fn mac_address(mac: Option<pnet_datalink::MacAddr>) -> String {
+ match mac {
+ Some(mac) => mac.to_string(),
+ None => "none".to_string(),
+ }
+}
+
fn nic_hardware_info(collector: &mut Vec<ServerInfoItem>) {
let nics = pnet_datalink::interfaces();
for nic in nics.into_iter() {
let mut infos = vec![
- ("mac", nic.mac_address().to_string()),
+ ("mac", mac_address(nic.mac)),
("flag", nic.flags.to_string()),
("index", nic.index.to_string()),
("is-up", nic.is_up().to_string()),
