mirror of https://gitee.com/anolis/sysom.git
53 lines
1.5 KiB
Python
Executable File
53 lines
1.5 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# coding=utf-8
|
|
import sys
|
|
import json
|
|
import random
|
|
def iosdiagJoinData(raw):
|
|
postprocess_result = {
|
|
"code": 0,
|
|
"err_msg": "",
|
|
"result": {}
|
|
}
|
|
stat = {}
|
|
data = []
|
|
if raw.startswith("normal"):
|
|
stat["iodiagnoseOverview"] = {
|
|
"data": [{'key': 'Check Result', "value": "normal"},
|
|
{'key': "IOs problem detected", "value": 0}]}
|
|
postprocess_result['result'] = stat
|
|
return
|
|
diagnose_list = raw.split('\n')
|
|
num = 0
|
|
for s in diagnose_list:
|
|
try:
|
|
obj = json.loads(s)
|
|
data.append({
|
|
"diag_type": obj['diag_type'],
|
|
'devname': obj['devname'],
|
|
'diagret': obj['diagret'],
|
|
'reason': obj['reason'],
|
|
'solution': obj['solution']
|
|
})
|
|
num += 1
|
|
except Exception:
|
|
continue
|
|
stat["iodiagnoseOverview"] = {
|
|
"data": [{'key': 'Check Result', "value": "abnormal"},
|
|
{'key': "IOs problem detected", "value": num}]}
|
|
stat["iodiagnoseDetail"] = {"data": data}
|
|
postprocess_result['result'] = stat
|
|
s = json.dumps(postprocess_result, indent=4)
|
|
print(s)
|
|
|
|
def extract_params():
|
|
path, res, task_id = sys.argv[1], "", sys.argv[2]
|
|
with open(path, 'r') as tmp:
|
|
res = tmp.read()
|
|
return res, task_id
|
|
|
|
|
|
if __name__ == "__main__":
|
|
res, _ = extract_params()
|
|
iosdiagJoinData(res)
|