adds custom field for host power status and combines two others #379 #440

This commit is contained in:
Ricardo Bartels
2025-02-20 17:43:35 +01:00
parent f88c5f73ed
commit 04cb13c8e0
4 changed files with 62 additions and 13 deletions
+2 -1
View File
@@ -630,7 +630,8 @@ class NetBoxObject:
if self.data_model.get(key) == NBCustomField:
if current_value is None:
current_value = dict()
new_value_str = str({**current_value, **new_value})
new_value = {**current_value, **new_value}
new_value_str = str(new_value)
elif isinstance(new_value, (NetBoxObject, NBObjectList)):
new_value_str = str(new_value.get_display_name())
else:
@@ -214,11 +214,6 @@ class CheckRedfish(SourceBase):
log.error(f"No system data found for '{self.device_object.get_display_name()}' in inventory file.")
return
# get status
status = "offline"
if get_string_or_none(grab(system, "power_state")) == "On":
status = "active"
serial = get_string_or_none(grab(system, "serial"))
name = get_string_or_none(grab(system, "host_name"))
manufacturer = get_string_or_none(grab(system, "manufacturer"))
@@ -230,9 +225,9 @@ class CheckRedfish(SourceBase):
"name": manufacturer
},
},
"status": status,
"custom_fields": {
"health": get_string_or_none(grab(system, "health_status"))
"health": get_string_or_none(grab(system, "health_status")),
"power_state": get_string_or_none(grab(system, "power_state"))
}
}
@@ -399,6 +394,7 @@ class CheckRedfish(SourceBase):
def update_memory(self):
items = list()
memory_size_total = 0
for memory in grab(self.inventory_file_content, "inventory.memory", fallback=list()):
if grab(memory, "operation_status") in ["NotPresent", "Absent"]:
@@ -416,6 +412,8 @@ class CheckRedfish(SourceBase):
if size_in_mb == 0 or (health_status is None and grab(memory, "operation_status") != "GoodInUse"):
continue
memory_size_total += size_in_mb
name_details = list()
if dimm_type is not None:
name_details.append(f"{dimm_type}")
@@ -448,9 +446,21 @@ class CheckRedfish(SourceBase):
self.update_all_items(items)
if memory_size_total > 0:
memory_size_total = memory_size_total / 1024
memory_size_unit = "GB"
if memory_size_total >= 1024:
memory_size_total = memory_size_total / 1024
memory_size_unit = "TB"
custom_fields_data = {"custom_fields": {"host_memory": f"{memory_size_total} {memory_size_unit}"}}
self.device_object.update(data=custom_fields_data, source=self)
def update_proc(self):
items = list()
num_cores = 0
cpu_name = ""
for processor in grab(self.inventory_file_content, "inventory.processor", fallback=list()):
if grab(processor, "operation_status") in ["NotPresent", "Absent"]:
@@ -465,6 +475,7 @@ class CheckRedfish(SourceBase):
health_status = get_string_or_none(grab(processor, "health_status"))
name = f"{socket} ({model})"
cpu_name = model
if current_speed is not None:
current_speed = f"{current_speed / 1000}GHz"
@@ -477,6 +488,7 @@ class CheckRedfish(SourceBase):
description.append(f"{instruction_set}")
if cores is not None:
description.append(f"Cores: {cores}")
num_cores += int(cores)
if threads is not None:
description.append(f"Threads: {threads}")
@@ -493,6 +505,10 @@ class CheckRedfish(SourceBase):
self.update_all_items(items)
if num_cores > 0:
custom_fields_data = {"custom_fields": {"host_cpu_cores": f"{num_cores} {cpu_name}"}}
self.device_object.update(data=custom_fields_data, source=self)
def update_physical_drive(self):
items = list()
@@ -1037,6 +1053,36 @@ class CheckRedfish(SourceBase):
"description": f"Marks objects synced from check_redfish inventory '{self.name}' to this NetBox Instance."
})
self.add_update_custom_field({
"name": "host_cpu_cores",
"label": "Physical CPU Cores",
"object_types": [
"dcim.device"
],
"type": "text",
"description": f"Reported Host CPU cores"
})
self.add_update_custom_field({
"name": "host_memory",
"label": "Memory",
"object_types": [
"dcim.device"
],
"type": "text",
"description": f"Reported size of Memory"
})
self.add_update_custom_field({
"name": "power_state",
"label": "Power State",
"object_types": [
"dcim.device"
],
"type": "text",
"description": "Device power state"
})
# add Firmware
self.add_update_custom_field({
"name": "firmware",
+3 -1
View File
@@ -269,7 +269,9 @@ class SourceBase:
# handle change to mac_address object from NetBox 4.2 on
interface_mac_address = None
if version.parse(self.inventory.netbox_api_version) >= version.parse("4.2.0"):
if version.parse(self.inventory.netbox_api_version) >= version.parse("4.2.0") and \
interface_data.get("mac_address") is not None:
interface_mac_address = interface_data.get("mac_address")
del(interface_data["mac_address"])
+4 -4
View File
@@ -797,22 +797,22 @@ class VMWareHandler(SourceBase):
if num_cpu_cores is not None:
custom_field = self.add_update_custom_field({
"name": "vcsa_host_cpu_cores",
"name": "host_cpu_cores",
"label": "Physical CPU Cores",
"object_types": [object_type],
"type": "text",
"description": f"vCenter '{self.name}' reported Host CPU cores"
"description": f"Reported Host CPU cores"
})
return_custom_fields[grab(custom_field, "data.name")] = f"{num_cpu_cores} {cpu_model}"
if isinstance(memory_size, int):
custom_field = self.add_update_custom_field({
"name": "vcsa_host_memory",
"name": "host_memory",
"label": "Memory",
"object_types": [object_type],
"type": "text",
"description": f"vCenter '{self.name}' reported Memory"
"description": f"Reported size of Memory"
})
memory_size = round(memory_size / 1024 ** 3)