Added nvme details #20

Merged
PeterSurda merged 2 commits from swapnil/idlers-agent:main into main 2024-07-01 16:39:46 +02:00
Showing only changes of commit 2c19f2eefc - Show all commits

View File

@ -30,6 +30,7 @@ class ServerData:
self.public_ip = self.get_public_ip() self.public_ip = self.get_public_ip()
self.dmidecode_data = self.parse_dmidecode_output() self.dmidecode_data = self.parse_dmidecode_output()
self.hdparm_data = self.parse_hdparm_output() self.hdparm_data = self.parse_hdparm_output()
self.nvme_data = self.parse_nvme_devices()
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
def parse_dmidecode_output(self): def parse_dmidecode_output(self):
@ -103,8 +104,8 @@ class ServerData:
# Get the list of devices # Get the list of devices
try: try:
device_list = subprocess.check_output(['lsblk', '-d', '-o', 'NAME'], stderr=subprocess.STDOUT, universal_newlines=True).split()[1:] device_list = [device for device in os.listdir('/sys/block') if device.startswith('sd')]
except subprocess.CalledProcessError as e: except OSError as e:
logging.error("Failed to get device list: {}".format(e)) logging.error("Failed to get device list: {}".format(e))
return devices return devices
@ -135,6 +136,53 @@ class ServerData:
return devices return devices
def parse_nvme_devices(self):
'''
Example nvme id-ctrl output:
NVME Identify Controller:
vid : 0x144d
ssvid : 0x144d
sn : S3RVNA0K502408F
mn : Samsung SSD 970 EVO Plus 1TB
fr : 2B2QEXM7
rab : 2
....
'''
devices = {}
# Check if nvme exists
if shutil.which('nvme') is None:
print("nvme not found")
return devices
# Get the list of nvme devices starting with 'nvme'
nvme_devices = [device for device in os.listdir('/dev') if device.startswith('nvme')]
for device in nvme_devices:
device_path = '/dev/' + device
try:
# Get the output of nvme id-ctrl command
output = subprocess.check_output(['nvme', 'id-ctrl', device_path], stderr=subprocess.STDOUT, universal_newlines=True)
except subprocess.CalledProcessError as e:
print(f"Failed to get nvme id-ctrl output for {device_path}: {e}")
continue
# Split the output into lines
lines = output.split('\n')
# Parse each line
device_info = {}
for line in lines:
if ':' in line:
key, value = line.split(':', 1)
device_info[key.strip()] = value.strip()
devices[device_path] = device_info
return devices
def get_ram_and_disk(self): def get_ram_and_disk(self):
# RAM information # RAM information
with open('/proc/meminfo', 'r') as f: with open('/proc/meminfo', 'r') as f:
@ -254,9 +302,15 @@ class ServerData:
for device, details in self.hdparm_data.items(): for device, details in self.hdparm_data.items():
sata_details.append("Device: {}, Model: {}, Serial: {}, Checksum: {}, Buffer Size: {}, Form Factor: {}".format( sata_details.append("Device: {}, Model: {}, Serial: {}, Checksum: {}, Buffer Size: {}, Form Factor: {}".format(
device, details['model_number'], details['serial_number'], details['checksum'], details['buffer_size'], details['form_factor'])) device, details['model_number'], details['serial_number'], details['checksum'], details['buffer_size'], details['form_factor']))
# NVMe Storage media
nvme_details = []
for device, details in self.nvme_data.items():
nvme_details.append("Device: {}, Model: {}, Serial: {}, Firmware: {}".format(
device, details.get('mn', 'Unknown'), details.get('sn', 'Unknown'), details.get('fr', 'Unknown')))
note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM Details: {} ||| SATA Details {}".format( note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM Details: {} ||| SATA Details {} ||| NVME Details {}".format(
chassis_model, chassis_serial, processor_model, processor_count, ' | '.join(ram_details), ' | '.join(sata_details)) chassis_model, chassis_serial, processor_model, processor_count, ' | '.join(ram_details), ' | '.join(sata_details), ' | '.join(nvme_details))
note_data = { note_data = {
'note': note, 'note': note,