From 515f2cbc81b3c7883255cdc13e9c1df2aba888fb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 30 Sep 2024 17:48:38 +0200 Subject: [PATCH] fix parsing to old devicehub --- workbench-script.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index 411d6e7..1116092 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -16,22 +16,13 @@ from datetime import datetime ## Legacy Functions ## def convert_to_legacy_snapshot(snapshot): snapshot["sid"] = str(uuid.uuid4()).split("-")[0] - snapshot["software"] = "UsodyOS" + snapshot["software"] = "Workbench" snapshot["version"] = "2023.4.0-alpha" snapshot["schema_api"] = "1.0.0" snapshot["settings_version"] = "No Settings Version (NaN)" snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T") - snapshot["tests"] = [] - snapshot["sanitize"] = [] - 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["data"]["smart"] = snapshot["data"]["disks"] + snapshot["data"].pop("disks") snapshot.pop("code") snapshot.pop("erase") @@ -239,7 +230,7 @@ def exec_smart(disk): def smartctl(all_disks, disk=None): if disk: - return exec_smart(disk) + return [exec_smart(disk)] data_list = [] for disk in all_disks: @@ -259,7 +250,7 @@ def get_data(all_disks): hwinfo = 'sudo hwinfo --reallyall' dmidecode = 'sudo dmidecode' data = { - 'lshw': exec_cmd(lshw), + 'lshw': json.loads(exec_cmd(lshw) or "{}"), 'disks': smartctl(all_disks), 'hwinfo': exec_cmd(hwinfo), 'dmidecode': exec_cmd(dmidecode) @@ -307,7 +298,7 @@ def save_snapshot_in_disk(snapshot, path): # url = 'http://127.0.0.1:8000/api/snapshot/' def send_snapshot_to_devicehub(snapshot, token, url): headers = { - f"Authorization": "Basic {token}", + "Authorization": f"Bearer {token}", "Content-Type": "application/json" } try: