fix components
This commit is contained in:
parent
54ef0bb41c
commit
59f6ac705c
|
@ -102,7 +102,8 @@ class Device:
|
||||||
|
|
||||||
def get_last_evidence(self):
|
def get_last_evidence(self):
|
||||||
annotations = self.get_annotations()
|
annotations = self.get_annotations()
|
||||||
if annotations:
|
if not annotations.count():
|
||||||
|
return
|
||||||
annotation = annotations.first()
|
annotation = annotations.first()
|
||||||
self.last_evidence = Evidence(annotation.uuid)
|
self.last_evidence = Evidence(annotation.uuid)
|
||||||
|
|
||||||
|
|
|
@ -180,9 +180,12 @@
|
||||||
<small class="text-muted">{{ evidence.created }}</small>
|
<small class="text-muted">{{ evidence.created }}</small>
|
||||||
</div>
|
</div>
|
||||||
<p class="mb-1">
|
<p class="mb-1">
|
||||||
{{ c.manufacturer }}<br />
|
{% for k, v in c.items %}
|
||||||
{{ c.model }}<br />
|
{% if k not in "actions,type" %}
|
||||||
{{ c.serialNumber }}<br />
|
{{ k }}: {{ v }}<br />
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
</p>
|
</p>
|
||||||
<small class="text-muted">
|
<small class="text-muted">
|
||||||
</small>
|
</small>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404, Http404
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic.edit import (
|
from django.views.generic.edit import (
|
||||||
CreateView,
|
CreateView,
|
||||||
|
@ -87,6 +87,9 @@ class DetailsView(DashboardView, TemplateView):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.pk = kwargs['pk']
|
self.pk = kwargs['pk']
|
||||||
self.object = Device(id=self.pk)
|
self.object = Device(id=self.pk)
|
||||||
|
if not self.object.last_evidence:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
|
@ -19,8 +19,12 @@ def get_network_cards(child, nets):
|
||||||
|
|
||||||
def get_mac(lshw):
|
def get_mac(lshw):
|
||||||
nets = []
|
nets = []
|
||||||
|
try:
|
||||||
get_network_cards(json.loads(lshw), nets)
|
get_network_cards(json.loads(lshw), nets)
|
||||||
|
except Exception as ss:
|
||||||
|
print("WARNING!! {}".format(ss))
|
||||||
|
return
|
||||||
|
|
||||||
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
|
nets_sorted = sorted(nets, 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', '')]
|
||||||
|
|
|
@ -3,7 +3,6 @@ import numpy as np
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dmidecode import DMIParse
|
from dmidecode import DMIParse
|
||||||
from evidence import base2, unit
|
|
||||||
from utils.constants import CHASSIS_DH, DATASTORAGEINTERFACE
|
from utils.constants import CHASSIS_DH, DATASTORAGEINTERFACE
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,9 +80,9 @@ class ParseSnapshot:
|
||||||
"threads": int(cpu.get('Thread Count', 1)),
|
"threads": int(cpu.get('Thread Count', 1)),
|
||||||
"manufacturer": cpu.get('Manufacturer'),
|
"manufacturer": cpu.get('Manufacturer'),
|
||||||
"serialNumber": serial,
|
"serialNumber": serial,
|
||||||
"generation": None,
|
|
||||||
"brand": cpu.get('Family'),
|
"brand": cpu.get('Family'),
|
||||||
"address": self.get_cpu_address(cpu),
|
"address": self.get_cpu_address(cpu),
|
||||||
|
"bogomips": self.get_bogomips(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -182,16 +181,26 @@ class ParseSnapshot:
|
||||||
def sanitize(self, action):
|
def sanitize(self, action):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def get_bogomips(self):
|
||||||
|
if not self.hwinfo:
|
||||||
|
return self.default
|
||||||
|
|
||||||
|
bogomips = 0
|
||||||
|
for row in self.hwinfo:
|
||||||
|
for cel in row:
|
||||||
|
if 'BogoMips' in cel:
|
||||||
|
try:
|
||||||
|
bogomips += float(cel.split(":")[-1])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return bogomips
|
||||||
|
|
||||||
def get_networks(self):
|
def get_networks(self):
|
||||||
networks = []
|
networks = []
|
||||||
get_lshw_child(self.lshw, networks, 'network')
|
get_lshw_child(self.lshw, networks, 'network')
|
||||||
|
|
||||||
for c in networks:
|
for c in networks:
|
||||||
capacity = c.get('capacity')
|
capacity = c.get('capacity')
|
||||||
units = c.get('units')
|
|
||||||
speed = None
|
|
||||||
if capacity and units:
|
|
||||||
speed = unit.Quantity(capacity, units).to('Mbit/s').m
|
|
||||||
wireless = bool(c.get('configuration', {}).get('wireless', False))
|
wireless = bool(c.get('configuration', {}).get('wireless', False))
|
||||||
self.components.append(
|
self.components.append(
|
||||||
{
|
{
|
||||||
|
@ -200,9 +209,10 @@ class ParseSnapshot:
|
||||||
"model": c.get('product'),
|
"model": c.get('product'),
|
||||||
"manufacturer": c.get('vendor'),
|
"manufacturer": c.get('vendor'),
|
||||||
"serialNumber": c.get('serial'),
|
"serialNumber": c.get('serial'),
|
||||||
"speed": speed,
|
"speed": capacity,
|
||||||
"variant": c.get('version', 1),
|
"variant": c.get('version', 1),
|
||||||
"wireless": wireless,
|
"wireless": wireless or False,
|
||||||
|
"integrated": "PCI:0000:00" in c.get("businfo", ""),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -300,7 +310,7 @@ class ParseSnapshot:
|
||||||
if 'x' not in sizes:
|
if 'x' not in sizes:
|
||||||
return 0
|
return 0
|
||||||
w, h = [int(x) for x in sizes.split('x')]
|
w, h = [int(x) for x in sizes.split('x')]
|
||||||
return np.sqrt(w**2 + h**2) * i
|
return "{:.2f}".format(np.sqrt(w**2 + h**2) * i)
|
||||||
|
|
||||||
def get_cpu_address(self, cpu):
|
def get_cpu_address(self, cpu):
|
||||||
default = 64
|
default = 64
|
||||||
|
@ -367,25 +377,16 @@ class ParseSnapshot:
|
||||||
return slots
|
return slots
|
||||||
|
|
||||||
def get_ram_size(self, ram):
|
def get_ram_size(self, ram):
|
||||||
try:
|
|
||||||
memory = ram.get("Size", "0")
|
memory = ram.get("Size", "0")
|
||||||
memory = memory.split(' ')
|
return memory
|
||||||
if len(memory) > 1:
|
|
||||||
size = int(memory[0])
|
|
||||||
units = memory[1]
|
|
||||||
return base2.Quantity(size, units).to('MiB').m
|
|
||||||
return int(size.split(" ")[0])
|
|
||||||
except Exception as err:
|
|
||||||
logger.error("get_ram_size error: {}".format(err))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def get_ram_speed(self, ram):
|
def get_ram_speed(self, ram):
|
||||||
size = ram.get("Speed", "0")
|
size = ram.get("Speed", "0")
|
||||||
return int(size.split(" ")[0])
|
return size
|
||||||
|
|
||||||
def get_cpu_speed(self, cpu):
|
def get_cpu_speed(self, cpu):
|
||||||
speed = cpu.get('Max Speed', "0")
|
speed = cpu.get('Max Speed', "0")
|
||||||
return float(speed.split(" ")[0]) / 1024
|
return speed
|
||||||
|
|
||||||
def get_sku(self):
|
def get_sku(self):
|
||||||
return self.dmi.get("System")[0].get("SKU Number", self.default).strip()
|
return self.dmi.get("System")[0].get("SKU Number", self.default).strip()
|
||||||
|
@ -468,11 +469,7 @@ class ParseSnapshot:
|
||||||
self.errors("{}".format(err))
|
self.errors("{}".format(err))
|
||||||
|
|
||||||
def get_data_storage_size(self, x):
|
def get_data_storage_size(self, x):
|
||||||
total_capacity = x.get('user_capacity', {}).get('bytes')
|
return x.get('user_capacity', {}).get('bytes')
|
||||||
if not total_capacity:
|
|
||||||
return 1
|
|
||||||
# convert bytes to Mb
|
|
||||||
return total_capacity / 1024**2
|
|
||||||
|
|
||||||
def parse_hwinfo(self):
|
def parse_hwinfo(self):
|
||||||
hw_blocks = self.hwinfo_raw.split("\n\n")
|
hw_blocks = self.hwinfo_raw.split("\n\n")
|
||||||
|
@ -480,7 +477,11 @@ class ParseSnapshot:
|
||||||
|
|
||||||
def loads(self, x):
|
def loads(self, x):
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
|
try:
|
||||||
return json.loads(x)
|
return json.loads(x)
|
||||||
|
except Exception as ss:
|
||||||
|
print("WARNING!! {}".format(ss))
|
||||||
|
return {}
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def errors(self, txt=None):
|
def errors(self, txt=None):
|
||||||
|
|
Loading…
Reference in New Issue