diff --git a/README.md b/README.md index c6a3252..564fc6c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Netbox agent [![Build Status](https://travis-ci.com/Solvik/netbox-agent.svg?branch=master)](https://travis-ci.com/Solvik/netbox-agent) +# Netbox agent [![Build Status](https://travis-ci.com/Solvik/netbox_agent.svg?branch=master)](https://travis-ci.com/Solvik/netbox_agent) + This project aims to create hardware automatically into [Netbox](https://github.com/netbox-community/netbox) based on standard tools (dmidecode, lldpd, parsing /sys/, etc). diff --git a/netbox_agent/cli.py b/netbox_agent/cli.py index 3621828..505efdd 100644 --- a/netbox_agent/cli.py +++ b/netbox_agent/cli.py @@ -18,13 +18,12 @@ MANUFACTURERS = { def run(config): - dmi = dmidecode.parse() - manufacturer = dmidecode.get_by_type(dmi, 'Chassis')[0].get('Manufacturer') + manufacturer = dmidecode.get_by_type('Chassis')[0].get('Manufacturer') try: - server = MANUFACTURERS[manufacturer](dmi=dmi) + server = MANUFACTURERS[manufacturer](dmi=dmidecode) except KeyError: - server = GenericHost(dmi=dmi) + server = GenericHost if config.debug: server.print_debug() diff --git a/netbox_agent/lshw.py b/netbox_agent/lshw.py index 0fb6f24..3387c41 100644 --- a/netbox_agent/lshw.py +++ b/netbox_agent/lshw.py @@ -103,13 +103,14 @@ class LSHW(): self.disks.append(d) def find_cpus(self, obj): - c = {} - c["product"] = obj["product"] - c["vendor"] = obj["vendor"] - c["description"] = obj["description"] - c["location"] = obj["slot"] + if "product" in obj: + c = {} + c["product"] = obj["product"] + c["vendor"] = obj["vendor"] + c["description"] = obj["description"] + c["location"] = obj["slot"] - self.cpus.append(c) + self.cpus.append(c) def find_memories(self, obj): if "children" not in obj: diff --git a/netbox_agent/power.py b/netbox_agent/power.py index 8cd4eab..dd0b17e 100644 --- a/netbox_agent/power.py +++ b/netbox_agent/power.py @@ -1,6 +1,5 @@ import logging -import netbox_agent.dmidecode as dmidecode from netbox_agent.config import netbox_instance as nb PSU_DMI_TYPE = 39 @@ -17,7 +16,7 @@ class PowerSupply(): def get_power_supply(self): power_supply = [] - for psu in dmidecode.get_by_type(self.server.dmi, PSU_DMI_TYPE): + for psu in self.server.dmi.get_by_type(PSU_DMI_TYPE): if 'Present' not in psu['Status'] or psu['Status'] == 'Not Present': continue diff --git a/netbox_agent/vendors/dell.py b/netbox_agent/vendors/dell.py index 82bad93..6e038c6 100644 --- a/netbox_agent/vendors/dell.py +++ b/netbox_agent/vendors/dell.py @@ -20,7 +20,7 @@ class DellHost(ServerBase): ` Location In Chassis: Slot 03` """ if self.is_blade(): - return self.baseboard[0].get('Location In Chassis').strip() + return self.dmi.get_by_type('Baseboard')[0].get('Location In Chassis').strip() return None def get_chassis_name(self): @@ -30,12 +30,12 @@ class DellHost(ServerBase): def get_chassis(self): if self.is_blade(): - return self.chassis[0]['Version'].strip() + return self.dmi.get_by_type('Chassis')[0]['Version'].strip() return self.get_product_name() def get_chassis_service_tag(self): if self.is_blade(): - return self.chassis[0]['Serial Number'].strip() + return self.dmi.get_by_type('Chassis')[0]['Serial Number'].strip() return self.get_service_tag() def get_power_consumption(self): diff --git a/netbox_agent/vendors/generic.py b/netbox_agent/vendors/generic.py index 6080112..695c0d2 100644 --- a/netbox_agent/vendors/generic.py +++ b/netbox_agent/vendors/generic.py @@ -5,7 +5,7 @@ from netbox_agent.server import ServerBase class GenericHost(ServerBase): def __init__(self, *args, **kwargs): super(GenericHost, self).__init__(*args, **kwargs) - self.manufacturer = dmidecode.get_by_type(self.dmi, 'Baseboard')[0].get('Manufacturer') + self.manufacturer = dmidecode.get_by_type('Baseboard')[0].get('Manufacturer') def is_blade(self): return None diff --git a/netbox_agent/vendors/hp.py b/netbox_agent/vendors/hp.py index 30b36ce..92ae0ba 100644 --- a/netbox_agent/vendors/hp.py +++ b/netbox_agent/vendors/hp.py @@ -1,4 +1,3 @@ -import netbox_agent.dmidecode as dmidecode from netbox_agent.server import ServerBase @@ -20,7 +19,7 @@ class HPHost(ServerBase): """ # FIXME: make a dmidecode function get_by_dminame() ? if self.is_blade(): - locator = dmidecode.get_by_type(self.dmi, 204) + locator = self.dmi.get_by_type(204) if self.get_product_name() == 'ProLiant BL460c Gen10': locator = locator[0]['Strings'] return { diff --git a/netbox_agent/vendors/qct.py b/netbox_agent/vendors/qct.py index 5582d11..6051da1 100644 --- a/netbox_agent/vendors/qct.py +++ b/netbox_agent/vendors/qct.py @@ -7,12 +7,12 @@ class QCTHost(ServerBase): self.manufacturer = 'QCT' def is_blade(self): - return 'Location In Chassis' in self.baseboard[0].keys() + return 'Location In Chassis' in self.dmi.get_by_type('Baseboard')[0].keys() def get_blade_slot(self): if self.is_blade(): return 'Slot {}'.format( - self.baseboard[0].get('Location In Chassis').strip() + self.dmi.get_by_type('Baseboard')[0].get('Location In Chassis').strip() ) return None @@ -23,10 +23,10 @@ class QCTHost(ServerBase): def get_chassis(self): if self.is_blade(): - return self.chassis[0]['Version'].strip() + return self.dmi.get_by_type('Chassis')[0]['Version'].strip() return self.get_product_name() def get_chassis_service_tag(self): if self.is_blade(): - return self.chassis[0]['Serial Number'].strip() + return self.dmi.get_by_type('Chassis')[0]['Serial Number'].strip() return self.get_service_tag()