From 0b9087fa416ddf5c60d80d5e9753bad40f351632 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Tue, 23 Aug 2022 08:41:59 +0200 Subject: [PATCH 1/2] fix: inventory disk issue if size None ``` Traceback (most recent call last): File "/usr/bin/netbox_agent", line 33, in sys.exit(load_entry_point('netbox-agent==0.7.1', 'console_scripts', 'netbox_agent')()) File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/cli.py", line 50, in main return run(config) File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/cli.py", line 43, in run server.netbox_create_or_update(config) File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/server.py", line 417, in netbox_create_or_update self.inventory.create_or_update() File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/inventory.py", line 550, in create_or_update self.do_netbox_disks() File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/inventory.py", line 420, in do_netbox_disks disks = self.get_hw_disks() File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/inventory.py", line 344, in get_hw_disks size = int(disk.get('size', 0)) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' ``` --- netbox_agent/inventory.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/netbox_agent/inventory.py b/netbox_agent/inventory.py index 0c8fcfe..a1adce9 100644 --- a/netbox_agent/inventory.py +++ b/netbox_agent/inventory.py @@ -341,21 +341,23 @@ class Inventory(): for disk in self.lshw.get_hw_linux("storage"): if self.is_virtual_disk(disk, raid_devices): continue - size =int(disk.get('size', 0)) / 1073741824 - d = { - "name": "", - 'Size': '{} GB'.format(size), - 'logicalname': disk.get('logicalname'), - 'description': disk.get('description'), - 'SN': disk.get('serial'), - 'Model': disk.get('product'), - 'Type': disk.get('type'), - } - if disk.get('vendor'): - d['Vendor'] = disk['vendor'] - else: - d['Vendor'] = get_vendor(disk['product']) - disks.append(d) + size = int(getattr(disk, "size", 0)) + if size > 0: + size /= 1073741824 + d = { + "name": "", + 'Size': '{} GB'.format(size), + 'logicalname': disk.get('logicalname'), + 'description': disk.get('description'), + 'SN': disk.get('serial'), + 'Model': disk.get('product'), + 'Type': disk.get('type'), + } + if disk.get('vendor'): + d['Vendor'] = disk['vendor'] + else: + d['Vendor'] = get_vendor(disk['product']) + disks.append(d) # remove duplicate serials seen = set() From f4d7796094843834e3f4175f6e6a41c234ad8980 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Tue, 23 Aug 2022 08:55:02 +0200 Subject: [PATCH 2/2] fix: dvd-ram should be consider as virtual to be ignore --- netbox_agent/inventory.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/netbox_agent/inventory.py b/netbox_agent/inventory.py index a1adce9..e19608a 100644 --- a/netbox_agent/inventory.py +++ b/netbox_agent/inventory.py @@ -321,6 +321,7 @@ class Inventory(): 'virtual' in product.lower() or \ 'logical' in product.lower() or \ 'volume' in description.lower() or \ + 'dvd-ram' in description.lower() or \ description == 'SCSI Enclosure' or \ (size is None and logicalname is None): return True @@ -341,23 +342,21 @@ class Inventory(): for disk in self.lshw.get_hw_linux("storage"): if self.is_virtual_disk(disk, raid_devices): continue - size = int(getattr(disk, "size", 0)) - if size > 0: - size /= 1073741824 - d = { - "name": "", - 'Size': '{} GB'.format(size), - 'logicalname': disk.get('logicalname'), - 'description': disk.get('description'), - 'SN': disk.get('serial'), - 'Model': disk.get('product'), - 'Type': disk.get('type'), - } - if disk.get('vendor'): - d['Vendor'] = disk['vendor'] - else: - d['Vendor'] = get_vendor(disk['product']) - disks.append(d) + size = int(getattr(disk, "size", 0)) / 1073741824 + d = { + "name": "", + 'Size': '{} GB'.format(size), + 'logicalname': disk.get('logicalname'), + 'description': disk.get('description'), + 'SN': disk.get('serial'), + 'Model': disk.get('product'), + 'Type': disk.get('type'), + } + if disk.get('vendor'): + d['Vendor'] = disk['vendor'] + else: + d['Vendor'] = get_vendor(disk['product']) + disks.append(d) # remove duplicate serials seen = set()