initial commit
This commit is contained in:
61
RAS.py
Normal file
61
RAS.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import subprocess
|
||||
|
||||
def convertToDict(RAS_dump):
|
||||
ras_status = {}
|
||||
current_driver = ""
|
||||
lines = RAS_dump.split('\n')
|
||||
|
||||
for line in lines:
|
||||
if line == '':
|
||||
continue
|
||||
if '\t' in line:
|
||||
try:
|
||||
item = line.split(': ')
|
||||
ras_status[current_driver][item[1]] = {}
|
||||
if "Corrected" in line:
|
||||
ras_status[current_driver][item[1]]["corrected"] = int(line.replace('\t', '').split(' ')[0])
|
||||
ras_status[current_driver]["total_errors"] += int(line.replace('\t', '').split(' ')[0])
|
||||
else:
|
||||
ras_status[current_driver][item[1]]["uncorrected"] = int(line.replace('\t', '').split(' ')[0])
|
||||
ras_status[current_driver]["total_errors"] += int(line.replace('\t', '').split(' ')[0])
|
||||
except:
|
||||
item = line.replace('\t', '').split(' ')
|
||||
ras_status[current_driver][item[0]] = {}
|
||||
ras_status[current_driver][item[0]]["uncorrected"] = int(line.replace('\t', '').split(' ')[2])
|
||||
ras_status[current_driver]["total_errors"] += int(line.replace('\t', '').split(' ')[2])
|
||||
else:
|
||||
current_driver = ""
|
||||
if "No" in line:
|
||||
words = line.split(' ')
|
||||
for word in words:
|
||||
if word == "No":
|
||||
continue
|
||||
if "errors" in word:
|
||||
current_driver = current_driver[:-1]
|
||||
break
|
||||
current_driver += word+" "
|
||||
else:
|
||||
words = line.split(' ')
|
||||
for word in words:
|
||||
if word == "events":
|
||||
current_driver = current_driver[:-1]
|
||||
break
|
||||
if "errors" in word:
|
||||
current_driver = current_driver[:-1]
|
||||
break
|
||||
current_driver += word+" "
|
||||
ras_status[current_driver] = {}
|
||||
ras_status[current_driver]["total_errors"] = 0
|
||||
|
||||
return ras_status
|
||||
|
||||
def readRAS():
|
||||
result = subprocess.run(['ras-mc-ctl', '--summary'], stdout=subprocess.PIPE)
|
||||
result = result.stdout.decode('utf-8')
|
||||
|
||||
return convertToDict(result)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(readRAS())
|
||||
Reference in New Issue
Block a user