fix mac not recovered properly
This commit is contained in:
parent
79951f3c4b
commit
f2660dd877
|
@ -6,22 +6,13 @@ from dmidecode import DMIParse
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json
|
||||||
|
|
||||||
from evidence.models import Annotation
|
from evidence.models import Annotation
|
||||||
|
from evidence.parse_details import get_lshw_child
|
||||||
from evidence.xapian import index
|
from evidence.xapian import index
|
||||||
from utils.constants import CHASSIS_DH
|
from utils.constants import CHASSIS_DH
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
logger = logging.getLogger('django')
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
def get_mac(lshw):
|
||||||
nets = []
|
|
||||||
try:
|
try:
|
||||||
if type(lshw) is dict:
|
if type(lshw) is dict:
|
||||||
hw = lshw
|
hw = lshw
|
||||||
|
@ -30,19 +21,17 @@ def get_mac(lshw):
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
hw = json.loads(repair_json(lshw))
|
hw = json.loads(repair_json(lshw))
|
||||||
|
|
||||||
try:
|
networks = []
|
||||||
get_network_cards(hw, nets)
|
get_lshw_child(hw, networks, 'network')
|
||||||
except Exception as ss:
|
|
||||||
logger.warning("%s", ss)
|
|
||||||
return
|
|
||||||
|
|
||||||
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
|
nets_sorted = sorted(networks, key=lambda x: x['businfo'])
|
||||||
# This funcion get the network card integrated in motherboard
|
# This funcion get the network card integrated in motherboard
|
||||||
# integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
|
# integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
|
||||||
|
|
||||||
if nets_sorted:
|
if nets_sorted:
|
||||||
return nets_sorted[0]['serial']
|
mac = nets_sorted[0]['serial']
|
||||||
|
logger.debug(f"The snapshot has the following MAC: " + mac)
|
||||||
|
return mac
|
||||||
|
|
||||||
class Build:
|
class Build:
|
||||||
def __init__(self, evidence_json, user, check=False):
|
def __init__(self, evidence_json, user, check=False):
|
||||||
|
@ -131,9 +120,9 @@ class Build:
|
||||||
if not snapshot["data"].get('lshw'):
|
if not snapshot["data"].get('lshw'):
|
||||||
return f"{manufacturer}{model}{chassis}{serial_number}{sku}"
|
return f"{manufacturer}{model}{chassis}{serial_number}{sku}"
|
||||||
|
|
||||||
lshw = snapshot["data"]["lshw"]
|
lshw = snapshot["data"].get("lshw")
|
||||||
# mac = get_mac2(hwinfo_raw) or ""
|
# mac = get_mac2(hwinfo_raw) or ""
|
||||||
mac = get_mac(lshw) or ""
|
mac = get_mac(lshw)
|
||||||
if not mac:
|
if not mac:
|
||||||
txt = "Could not retrieve MAC address in snapshot %s"
|
txt = "Could not retrieve MAC address in snapshot %s"
|
||||||
logger.warning(txt, snapshot['uuid'])
|
logger.warning(txt, snapshot['uuid'])
|
||||||
|
|
Loading…
Reference in New Issue