add new parse for hwmd step1 scooter
This commit is contained in:
parent
99f4c71ee1
commit
ca4a995a27
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from binascii import Error as asciiError
|
from binascii import Error as asciiError
|
||||||
|
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
@ -21,6 +22,8 @@ from ereuse_devicehub.resources.action.views.snapshot import (
|
||||||
)
|
)
|
||||||
from ereuse_devicehub.resources.enums import Severity
|
from ereuse_devicehub.resources.enums import Severity
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
api = Blueprint('api', __name__, url_prefix='/api')
|
api = Blueprint('api', __name__, url_prefix='/api')
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +58,19 @@ class InventoryView(LoginMixin, SnapshotMixin):
|
||||||
if type(snapshot_json) == Response:
|
if type(snapshot_json) == Response:
|
||||||
return snapshot_json
|
return snapshot_json
|
||||||
|
|
||||||
self.snapshot_json = ParseSnapshotLsHw(snapshot_json).get_snapshot()
|
try:
|
||||||
|
self.snapshot_json = ParseSnapshotLsHw(snapshot_json).get_snapshot()
|
||||||
|
raise 1 == 2
|
||||||
|
except Exception as err:
|
||||||
|
logger.error("Error: {} \n{}\n".format(err, self.snapshot_json))
|
||||||
|
|
||||||
|
self.response = jsonify(
|
||||||
|
{
|
||||||
|
'error': err,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.response.status_code = 500
|
||||||
|
return self.response
|
||||||
|
|
||||||
snapshot = self.build()
|
snapshot = self.build()
|
||||||
snapshot.device.set_hid()
|
snapshot.device.set_hid()
|
||||||
|
|
|
@ -18,25 +18,28 @@ logger = logging.getLogger(__name__)
|
||||||
class ParseSnapshot:
|
class ParseSnapshot:
|
||||||
def __init__(self, snapshot, default="n/a"):
|
def __init__(self, snapshot, default="n/a"):
|
||||||
self.default = default
|
self.default = default
|
||||||
self.dmidecode_raw = snapshot["data"]["dmidecode"]
|
self.dmidecode_raw = snapshot["hwmd"]["dmidecode"]
|
||||||
self.smart_raw = snapshot["data"]["smart"]
|
self.smart_raw = snapshot["hwmd"]["smart"]
|
||||||
self.hwinfo_raw = snapshot["data"]["hwinfo"]
|
self.hwinfo_raw = snapshot["hwmd"]["hwinfo"]
|
||||||
|
self.lshw_raw = snapshot["hwmd"]["lshw"]
|
||||||
|
self.lscpi_raw = snapshot["hwmd"]["lspci"]
|
||||||
self.device = {"actions": []}
|
self.device = {"actions": []}
|
||||||
self.components = []
|
self.components = []
|
||||||
|
|
||||||
self.dmi = DMIParse(self.dmidecode_raw)
|
self.dmi = DMIParse(self.dmidecode_raw)
|
||||||
self.smart = self.loads(self.smart_raw)
|
self.smart = self.loads(self.smart_raw)
|
||||||
|
self.lshw = self.loads(self.lshw_raw)
|
||||||
self.hwinfo = self.parse_hwinfo()
|
self.hwinfo = self.parse_hwinfo()
|
||||||
|
|
||||||
self.set_basic_datas()
|
self.set_basic_datas()
|
||||||
self.set_components()
|
self.set_components()
|
||||||
self.snapshot_json = {
|
self.snapshot_json = {
|
||||||
"device": self.device,
|
"device": self.device,
|
||||||
"software": "Workbench",
|
"software": "UsodyOS",
|
||||||
"components": self.components,
|
"components": self.components,
|
||||||
"uuid": snapshot['uuid'],
|
"uuid": snapshot['uuid'],
|
||||||
"type": snapshot['type'],
|
"type": snapshot['type'],
|
||||||
"version": "14.0.0",
|
"version": "1.0.0",
|
||||||
"endTime": snapshot["timestamp"],
|
"endTime": snapshot["timestamp"],
|
||||||
"elapsed": 1,
|
"elapsed": 1,
|
||||||
"sid": snapshot["sid"],
|
"sid": snapshot["sid"],
|
||||||
|
@ -46,6 +49,7 @@ class ParseSnapshot:
|
||||||
return Snapshot().load(self.snapshot_json)
|
return Snapshot().load(self.snapshot_json)
|
||||||
|
|
||||||
def set_basic_datas(self):
|
def set_basic_datas(self):
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
self.device['manufacturer'] = self.dmi.manufacturer()
|
self.device['manufacturer'] = self.dmi.manufacturer()
|
||||||
self.device['model'] = self.dmi.model()
|
self.device['model'] = self.dmi.model()
|
||||||
self.device['serialNumber'] = self.dmi.serial_number()
|
self.device['serialNumber'] = self.dmi.serial_number()
|
||||||
|
@ -321,10 +325,10 @@ class ParseSnapshotLsHw:
|
||||||
self.uuid = snapshot.get("uuid")
|
self.uuid = snapshot.get("uuid")
|
||||||
self.sid = snapshot.get("sid")
|
self.sid = snapshot.get("sid")
|
||||||
self.version = str(snapshot.get("version"))
|
self.version = str(snapshot.get("version"))
|
||||||
self.dmidecode_raw = snapshot["data"]["dmidecode"]
|
self.dmidecode_raw = snapshot["hwmd"]["dmidecode"]
|
||||||
self.smart = snapshot["data"]["smart"]
|
self.smart = snapshot["hwmd"]["smart"]
|
||||||
self.hwinfo_raw = snapshot["data"]["hwinfo"]
|
self.hwinfo_raw = snapshot["hwmd"]["hwinfo"]
|
||||||
self.lshw = snapshot["data"]["lshw"]
|
self.lshw = snapshot["hwmd"]["lshw"]
|
||||||
self.device = {"actions": []}
|
self.device = {"actions": []}
|
||||||
self.components = []
|
self.components = []
|
||||||
self.components_obj = []
|
self.components_obj = []
|
||||||
|
|
|
@ -5,13 +5,24 @@ from marshmallow.fields import Dict, List, Nested, String
|
||||||
|
|
||||||
from ereuse_devicehub.resources.schemas import Thing
|
from ereuse_devicehub.resources.schemas import Thing
|
||||||
|
|
||||||
|
# from marshmallow_enum import EnumField
|
||||||
|
|
||||||
|
|
||||||
class Snapshot_lite_data(MarshmallowSchema):
|
class Snapshot_lite_data(MarshmallowSchema):
|
||||||
dmidecode = String(required=True)
|
hwmd_version = String(required=True)
|
||||||
hwinfo = String(required=True)
|
|
||||||
smart = List(Dict(), required=True)
|
|
||||||
lshw = Dict(required=True)
|
lshw = Dict(required=True)
|
||||||
|
dmidecode = String(required=True)
|
||||||
lspci = String(required=True)
|
lspci = String(required=True)
|
||||||
|
hwinfo = String(required=True)
|
||||||
|
smart = List(Dict(), required=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Test(MarshmallowSchema):
|
||||||
|
type = String(required=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Sanitize(MarshmallowSchema):
|
||||||
|
type = String(required=True)
|
||||||
|
|
||||||
|
|
||||||
class Snapshot_lite(Thing):
|
class Snapshot_lite(Thing):
|
||||||
|
@ -19,11 +30,18 @@ class Snapshot_lite(Thing):
|
||||||
version = String(required=True)
|
version = String(required=True)
|
||||||
schema_api = String(required=True)
|
schema_api = String(required=True)
|
||||||
software = String(required=True)
|
software = String(required=True)
|
||||||
|
# software = EnumField(
|
||||||
|
# SnapshotSoftware,
|
||||||
|
# required=True,
|
||||||
|
# description='The software that generated this Snapshot.',
|
||||||
|
# )
|
||||||
sid = String(required=True)
|
sid = String(required=True)
|
||||||
type = String(required=True)
|
type = String(required=True)
|
||||||
timestamp = String(required=True)
|
timestamp = String(required=True)
|
||||||
settings_version = String(required=False)
|
settings_version = String(required=False)
|
||||||
data = Nested(Snapshot_lite_data, required=True)
|
hwmd = Nested(Snapshot_lite_data, required=True)
|
||||||
|
tests = Nested(Test, many=True, collection_class=list, required=False)
|
||||||
|
sanitize = Nested(Sanitize, many=True, collection_class=list, required=False)
|
||||||
|
|
||||||
@validates_schema
|
@validates_schema
|
||||||
def validate_workbench_version(self, data: dict):
|
def validate_workbench_version(self, data: dict):
|
||||||
|
|
|
@ -15,6 +15,7 @@ class SnapshotSoftware(Enum):
|
||||||
Web = 'Web'
|
Web = 'Web'
|
||||||
DesktopApp = 'DesktopApp'
|
DesktopApp = 'DesktopApp'
|
||||||
WorkbenchDesktop = 'WorkbenchDesktop'
|
WorkbenchDesktop = 'WorkbenchDesktop'
|
||||||
|
UsodyOS = 'UsodyOS'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
Reference in New Issue