fix parsing to old devicehub

This commit is contained in:
Cayo Puigdefabregas 2024-09-30 17:48:38 +02:00
parent fc603b2240
commit 515f2cbc81
1 changed files with 6 additions and 15 deletions

View File

@ -16,22 +16,13 @@ from datetime import datetime
## Legacy Functions ## ## Legacy Functions ##
def convert_to_legacy_snapshot(snapshot): def convert_to_legacy_snapshot(snapshot):
snapshot["sid"] = str(uuid.uuid4()).split("-")[0] snapshot["sid"] = str(uuid.uuid4()).split("-")[0]
snapshot["software"] = "UsodyOS" snapshot["software"] = "Workbench"
snapshot["version"] = "2023.4.0-alpha" snapshot["version"] = "2023.4.0-alpha"
snapshot["schema_api"] = "1.0.0" snapshot["schema_api"] = "1.0.0"
snapshot["settings_version"] = "No Settings Version (NaN)" snapshot["settings_version"] = "No Settings Version (NaN)"
snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T") snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T")
snapshot["tests"] = [] snapshot["data"]["smart"] = snapshot["data"]["disks"]
snapshot["sanitize"] = [] snapshot["data"].pop("disks")
snapshot["hwmd"] = {
"hwmd_version": "1.1.0-alpha",
"lshw": snapshot["data"].get("lshw", ""),
"hwinfo": snapshot["data"].get("hwinfo", ""),
"smart": snapshot["data"].get("smart", ""),
"dmidecode": snapshot["data"].get("dmidecode", ""),
"lspci": snapshot["data"].get("lspci", "")
}
snapshot.pop("data")
snapshot.pop("code") snapshot.pop("code")
snapshot.pop("erase") snapshot.pop("erase")
@ -239,7 +230,7 @@ def exec_smart(disk):
def smartctl(all_disks, disk=None): def smartctl(all_disks, disk=None):
if disk: if disk:
return exec_smart(disk) return [exec_smart(disk)]
data_list = [] data_list = []
for disk in all_disks: for disk in all_disks:
@ -259,7 +250,7 @@ def get_data(all_disks):
hwinfo = 'sudo hwinfo --reallyall' hwinfo = 'sudo hwinfo --reallyall'
dmidecode = 'sudo dmidecode' dmidecode = 'sudo dmidecode'
data = { data = {
'lshw': exec_cmd(lshw), 'lshw': json.loads(exec_cmd(lshw) or "{}"),
'disks': smartctl(all_disks), 'disks': smartctl(all_disks),
'hwinfo': exec_cmd(hwinfo), 'hwinfo': exec_cmd(hwinfo),
'dmidecode': exec_cmd(dmidecode) 'dmidecode': exec_cmd(dmidecode)
@ -307,7 +298,7 @@ def save_snapshot_in_disk(snapshot, path):
# url = 'http://127.0.0.1:8000/api/snapshot/' # url = 'http://127.0.0.1:8000/api/snapshot/'
def send_snapshot_to_devicehub(snapshot, token, url): def send_snapshot_to_devicehub(snapshot, token, url):
headers = { headers = {
f"Authorization": "Basic {token}", "Authorization": f"Bearer {token}",
"Content-Type": "application/json" "Content-Type": "application/json"
} }
try: try: