Parsing error handling and MAC retrieval on new snapshots #27

Merged
pedro merged 12 commits from pr_25 into main 2024-11-12 13:57:05 +00:00
1 changed files with 4 additions and 32 deletions
Showing only changes of commit eb81b65e5b - Show all commits

View File

@ -22,8 +22,10 @@ def get_mac(lshw):
except json.decoder.JSONDecodeError:
hw = json.loads(repair_json(lshw))
networks = []
get_lshw_child(hw, networks, 'network')
nets = []
get_lshw_child(hw, nets, 'network')
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
if nets_sorted:
mac = nets_sorted[0]['serial']
@ -31,36 +33,6 @@ def get_mac(lshw):
return mac
def get_network_cards(child, nets):
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
nets.append(child)
if child.get('children'):
[get_network_cards(x, nets) for x in child['children']]
def get_mac(lshw):
nets = []
try:
if type(lshw) is dict:
hw = lshw
else:
hw = json.loads(lshw)
except json.decoder.JSONDecodeError:
hw = json.loads(repair_json(lshw))
try:
get_network_cards(hw, nets)
except Exception as ss:
logger.warning("%s", ss)
return
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
# This funcion get the network card integrated in motherboard
# integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
if nets_sorted:
return nets_sorted[0]['serial']
class Build:
def __init__(self, evidence_json, user, check=False):