Compare commits
No commits in common. "75744e0010b075a706d998338e2d92a40994c2e9" and "ea4675a56ccf2506d099696f340966ca6d6aeaac" have entirely different histories.
75744e0010
...
ea4675a56c
62
agent.py
62
agent.py
|
@ -30,7 +30,6 @@ 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):
|
||||||
|
@ -104,8 +103,8 @@ class ServerData:
|
||||||
|
|
||||||
# Get the list of devices
|
# Get the list of devices
|
||||||
try:
|
try:
|
||||||
device_list = [device for device in os.listdir('/sys/block') if device.startswith('sd')]
|
device_list = subprocess.check_output(['lsblk', '-d', '-o', 'NAME'], stderr=subprocess.STDOUT, universal_newlines=True).split()[1:]
|
||||||
except OSError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
logging.error("Failed to get device list: {}".format(e))
|
logging.error("Failed to get device list: {}".format(e))
|
||||||
return devices
|
return devices
|
||||||
|
|
||||||
|
@ -136,53 +135,6 @@ 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('/sys/block') 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:
|
||||||
|
@ -302,15 +254,9 @@ 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 {} ||| NVME Details {}".format(
|
note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM Details: {} ||| SATA Details {}".format(
|
||||||
chassis_model, chassis_serial, processor_model, processor_count, ' | '.join(ram_details), ' | '.join(sata_details), ' | '.join(nvme_details))
|
chassis_model, chassis_serial, processor_model, processor_count, ' | '.join(ram_details), ' | '.join(sata_details))
|
||||||
|
|
||||||
note_data = {
|
note_data = {
|
||||||
'note': note,
|
'note': note,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user