forked from Sysdeploy/idlers-agent
Added SATA details in note
This commit is contained in:
parent
54d0b0decd
commit
bd6ecc3519
54
agent.py
54
agent.py
|
@ -5,6 +5,7 @@ import json
|
||||||
import http.client
|
import http.client
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
NON_UPDATABLE_KEYS = [
|
NON_UPDATABLE_KEYS = [
|
||||||
'server_type',
|
'server_type',
|
||||||
|
@ -28,6 +29,7 @@ class ServerData:
|
||||||
self.hostname = os.uname().nodename
|
self.hostname = os.uname().nodename
|
||||||
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()
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
def parse_dmidecode_output(self):
|
def parse_dmidecode_output(self):
|
||||||
|
@ -91,6 +93,48 @@ class ServerData:
|
||||||
pass
|
pass
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def parse_hdparm_output(self):
|
||||||
|
devices = {}
|
||||||
|
|
||||||
|
# Check if hdparm exists
|
||||||
|
if shutil.which('hdparm') is None:
|
||||||
|
logging.error("hdparm not found")
|
||||||
|
return devices
|
||||||
|
|
||||||
|
# Get the list of devices
|
||||||
|
try:
|
||||||
|
device_list = subprocess.check_output(['lsblk', '-d', '-o', 'NAME'], stderr=subprocess.STDOUT, universal_newlines=True).split()[1:]
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logging.error("Failed to get device list: {}".format(e))
|
||||||
|
return devices
|
||||||
|
|
||||||
|
for device in device_list:
|
||||||
|
# Only get details of devices that start with 'sd': sda, sdb, etc.
|
||||||
|
if not device.startswith('sd'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
device = '/dev/' + device
|
||||||
|
try:
|
||||||
|
# Get the output
|
||||||
|
output = subprocess.check_output(['hdparm', '-I', device], stderr=subprocess.STDOUT, universal_newlines=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logging.error("Failed to get hdparm output for {}: {}".format(device, e))
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Parse the output
|
||||||
|
details = {}
|
||||||
|
details['model_number'] = re.search(r'Model Number:\s*(.*)', output).group(1)
|
||||||
|
details['serial_number'] = re.search(r'Serial Number:\s*(.*)', output).group(1)
|
||||||
|
details['firmware_revision'] = re.search(r'Firmware Revision:\s*(.*)', output).group(1)
|
||||||
|
details['transport'] = re.search(r'Transport:\s*(.*)', output).group(1)
|
||||||
|
details['checksum'] = re.search(r'Checksum:\s*(.*)', output).group(1)
|
||||||
|
details['buffer_size'] = re.search(r'cache/buffer size\s*=\s*(.*)', output).group(1)
|
||||||
|
details['form_factor'] = re.search(r'Form Factor:\s*(.*)', output).group(1)
|
||||||
|
|
||||||
|
devices[device] = details
|
||||||
|
|
||||||
|
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:
|
||||||
|
@ -203,9 +247,15 @@ class ServerData:
|
||||||
serial_number = ram.get('Serial Number', 'Unknown')
|
serial_number = ram.get('Serial Number', 'Unknown')
|
||||||
ram_type = ram.get('Type', 'Unknown')
|
ram_type = ram.get('Type', 'Unknown')
|
||||||
ram_details.append("Size: {}, Speed: {} @ {}, ECC: {}, Serial Number: {}, Type: {}".format(size, speed, configured_speed, ecc, serial_number, ram_type))
|
ram_details.append("Size: {}, Speed: {} @ {}, ECC: {}, Serial Number: {}, Type: {}".format(size, speed, configured_speed, ecc, serial_number, ram_type))
|
||||||
|
|
||||||
|
# SATA Storage media
|
||||||
|
sata_details = []
|
||||||
|
for device, details in self.hdparm_data.items():
|
||||||
|
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']))
|
||||||
|
|
||||||
note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM 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))
|
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