From 4bb71adf007eb6d30f2c233c258d8cdbd04d5ac6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 21 Oct 2024 13:27:45 +0200 Subject: [PATCH 1/5] add hours of use --- evidence/parse_details.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/evidence/parse_details.py b/evidence/parse_details.py index 8465403..fd7f1c2 100644 --- a/evidence/parse_details.py +++ b/evidence/parse_details.py @@ -160,6 +160,7 @@ class ParseSnapshot: continue model = sm.get('model_name') manufacturer = None + hours = sm.get("power_on_time", {}).get("hours", 0) if model and len(model.split(" ")) > 1: mm = model.split(" ") model = mm[-1] @@ -175,6 +176,7 @@ class ParseSnapshot: "size": self.get_data_storage_size(sm), "variant": sm.get("firmware_version"), "interface": self.get_data_storage_interface(sm), + "hours": hours, } ) From 8d509e31c1de4d273f9f784fc6fe7fc40a6bc9a8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 21 Oct 2024 13:28:20 +0200 Subject: [PATCH 2/5] add date in list of events --- evidence/models.py | 2 +- evidence/templates/evidences.html | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/evidence/models.py b/evidence/models.py index 667945f..d971ce8 100644 --- a/evidence/models.py +++ b/evidence/models.py @@ -126,7 +126,7 @@ class Evidence: return Annotation.objects.filter( owner=user.institution, type=Annotation.Type.SYSTEM, - ).order_by("-created").values_list("uuid", flat=True).distinct() + ).order_by("-created").values_list("uuid", "created").distinct() def set_components(self): snapshot = ParseSnapshot(self.doc).snapshot_json diff --git a/evidence/templates/evidences.html b/evidence/templates/evidences.html index c67e9d9..b221d9b 100644 --- a/evidence/templates/evidences.html +++ b/evidence/templates/evidences.html @@ -14,10 +14,13 @@ {% for ev in evidences %} - {{ ev }} + {{ ev.0 }} - + {{ ev.1 }} + + + {% endfor %} From ff91bc9ad9ff0929f560e8c3bf468739ebca2259 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 21 Oct 2024 13:50:01 +0200 Subject: [PATCH 3/5] change TIME_ZONE for env variable --- dhub/settings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dhub/settings.py b/dhub/settings.py index 8b77fd7..23ea1a6 100644 --- a/dhub/settings.py +++ b/dhub/settings.py @@ -132,11 +132,14 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = "en-us" -TIME_ZONE = "UTC" +TIME_ZONE = config("TIME_ZONE", default="UTC") USE_I18N = True -USE_TZ = True +USE_TZ = False + +if TIME_ZONE == "UTC": + USE_TZ = True # Static files (CSS, JavaScript, Images) From e8d8c9670047f07bc36e92a00f7e7fb260b794eb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 21 Oct 2024 16:48:36 +0200 Subject: [PATCH 4/5] add anchor in tabs of details of devices --- device/templates/details.html | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/device/templates/details.html b/device/templates/details.html index 37f7487..51e97f1 100644 --- a/device/templates/details.html +++ b/device/templates/details.html @@ -12,25 +12,25 @@
@@ -214,3 +214,25 @@ {% endblock %} + +{% block extrascript %} + +{% endblock %} + From efcb53e062b6112a100d2b40511224d4e8067a29 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 21 Oct 2024 18:39:31 +0200 Subject: [PATCH 5/5] repair bad jsons --- evidence/parse.py | 9 ++++++++- evidence/parse_details.py | 8 +++++++- requirements.txt | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/evidence/parse.py b/evidence/parse.py index fa0903c..8688d6f 100644 --- a/evidence/parse.py +++ b/evidence/parse.py @@ -5,6 +5,8 @@ import hashlib from datetime import datetime from dmidecode import DMIParse +from json_repair import repair_json + from evidence.models import Annotation from evidence.xapian import index from utils.constants import ALGOS, CHASSIS_DH @@ -20,7 +22,12 @@ def get_network_cards(child, nets): def get_mac(lshw): nets = [] try: - get_network_cards(json.loads(lshw), nets) + hw = json.loads(lshw) + except json.decoder.JSONDecodeError: + hw = json.loads(repair_json(lshw)) + + try: + get_network_cards(hw, nets) except Exception as ss: print("WARNING!! {}".format(ss)) return diff --git a/evidence/parse_details.py b/evidence/parse_details.py index fd7f1c2..57ce4f9 100644 --- a/evidence/parse_details.py +++ b/evidence/parse_details.py @@ -3,6 +3,8 @@ import numpy as np from datetime import datetime from dmidecode import DMIParse +from json_repair import repair_json + from utils.constants import CHASSIS_DH, DATASTORAGEINTERFACE @@ -480,7 +482,11 @@ class ParseSnapshot: def loads(self, x): if isinstance(x, str): try: - return json.loads(x) + try: + hw = json.loads(lshw) + except json.decoder.JSONDecodeError: + hw = json.loads(repair_json(lshw)) + return hw except Exception as ss: print("WARNING!! {}".format(ss)) return {} diff --git a/requirements.txt b/requirements.txt index 1576d4f..32b8e86 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ pandas==2.2.2 xlrd==2.0.1 odfpy==1.4.1 pytz==2024.2 - +json-repair==0.30.0