Compare commits

..

6 Commits

Author SHA1 Message Date
d6afa1c5eb
getting os details with /api/os 2024-07-05 23:28:14 +05:30
a07225a0eb
F-string removal 2024-07-05 23:24:00 +08:00
bee43980da
Fix core/thread count calculation 2024-07-05 23:07:33 +08:00
ca77ce4c45
Docu typo 2024-07-05 22:57:34 +08:00
9a9a98edf7
Fix "Unknown" RAM size
- "Unknown" isn't an int
2024-07-05 22:56:08 +08:00
601bed9a34
skip device which doesn't have model number 2024-07-05 18:42:18 +05:30
2 changed files with 21 additions and 7 deletions

View File

@ -3,5 +3,5 @@
Agent for my-idlers
```
export API_KEY=<API_KEY> HOST=https://idlers.test2.sysdeploy.org/api/servers;python3 main.py
```
export AGENT_API=<API_KEY> HOST=https://idlers.test2.sysdeploy.org/api/servers;python3 agent.py
```

View File

@ -124,7 +124,12 @@ class ServerData:
# Parse the output
details = {}
details['model_number'] = re.search(r'Model Number:\s*(.*)', output).group(1)
model_number_match = re.search(r'Model Number:\s*(.*)', output)
if model_number_match is None:
logging.warning("Skipping device {} as it does not have a model number".format(device))
continue
details['model_number'] = model_number_match.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)
@ -166,7 +171,7 @@ class ServerData:
# 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}")
print("Failed to get nvme id-ctrl output for {}: {}".format(device_path, e))
continue
# Split the output into lines
@ -212,7 +217,10 @@ class ServerData:
if section['DMIType'] == 4: # 4 corresponds to processor
core_count = int(section.get('Core Count', '0'))
thread_count = int(section.get('Thread Count', '0'))
cpu_count = core_count * thread_count
if thread_count:
cpu_count += thread_count
else:
cpu_count += core_count
if cpu_count == 0:
with open('/proc/cpuinfo', 'r') as f:
cpuinfo = f.read()
@ -351,8 +359,14 @@ class ServerData:
size = ram.get('Size', 'Unknown')
speed = ram.get('Speed', 'Unknown')
configured_speed = ram.get('Configured Memory Speed', 'Unknown')
total_width = int(ram.get('Total Width', "0").split()[0])
data_width = int(ram.get('Data Width', "0").split()[0])
try:
total_width = int(ram.get('Total Width', "0").split()[0])
except ValueError:
total_width = 0
try:
data_width = int(ram.get('Data Width', "0").split()[0])
except ValueError:
data_width = 0
ecc = 'Yes' if total_width > data_width else 'No'
serial_number = ram.get('Serial Number', 'Unknown')
ram_type = ram.get('Type', 'Unknown')