diff --git a/sysom_server/sysom_diagnosis/service_scripts/ossre_post.py b/sysom_server/sysom_diagnosis/service_scripts/ossre_post.py index 90451a8210b61f5601eb8b9076a1a090db5c3ab8..b84b8ba3ae54e8d257d4e30d640619134f56349c 100755 --- a/sysom_server/sysom_diagnosis/service_scripts/ossre_post.py +++ b/sysom_server/sysom_diagnosis/service_scripts/ossre_post.py @@ -9,6 +9,7 @@ from .base import DiagnosisJobResult, DiagnosisPostProcessor, PostProcessResult import json import time import traceback +from clogger import logger from sysom_utils import SysomFramework ERR_LEVEL = ["normal","warning","error","critical"] @@ -36,8 +37,8 @@ def make_tool_option(tool,instance): tool_pms = "%s%s=%s"%(tool_pms,x,TOOLS_MSG[tool]["params"][x]) ret = {"key":TOOLS_MSG[tool]["key"],"label":TOOLS_MSG[tool]["cn_name"],"type": "LINK","url":"%s%s"%(TOOLS_MSG[tool]["url"],tool_pms)} - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) pass return ret @@ -45,8 +46,8 @@ def make_ignore_option(instance_ip,key_tmp): ret = {} try: ret = {"key":"ossre_ignore-%s"%key_tmp,"label":"屏蔽检测","type": "INVOKE_DIAGNOSIS_HOOK","params":{"type":"ignore","instance":instance_ip,"key":key_tmp}} - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) pass return ret @@ -54,7 +55,8 @@ def make_release_ignore_option(instance_ip,key_tmp): ret = {} try: ret = {"key":"ossre_release_ignore-%s"%key_tmp,"label":"解除屏蔽","type": "INVOKE_DIAGNOSIS_HOOK","params":{"type":"release_ignore","instance":instance_ip,"key":key_tmp}} - except: + except Exception as e: + logger.exception(e) traceback.print_exc() pass return ret @@ -124,8 +126,8 @@ def flush_data(instance_ip,origin_data): origin_data[i]["inspect_result"] = inspect_result total_abnormal_count += abnormal_count - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) pass return total_abnormal_count,level_num,origin_data @@ -150,8 +152,8 @@ def flush_checkItems(origin_checkItems,errnum,levelnum): if origin_checkItems[i]["key"] == "正常项": ori_nornum = origin_checkItems[i]["value"] origin_checkItems[i]["value"] = ori_nornum + ori_errnum + ori_warnnum + ori_critnum - levelnum["warning"] - levelnum["error"] - levelnum["critical"] - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) pass return ori_nornum + ori_errnum + ori_warnnum + ori_critnum, origin_checkItems @@ -162,8 +164,8 @@ def flush_hostInfo(origin_hostInfo,errnum,levelnum,total_count): #line_list.append("共检测%s项,疑似有%s项风险"%(total_count,errnum)) line_list.append("共检测%s项,告警项%s个,错误项%s个,严重异常项%s个"%(total_count,levelnum["warning"],levelnum["error"],levelnum["critical"])) origin_hostInfo = "\n\n".join(line_list) - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) pass return origin_hostInfo @@ -323,8 +325,8 @@ def sysak_to_sysom_info(sysakdict): else: retdict["issue"][level]["summary"] = sysakdict["items"]["issue"][i]["solution"] - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) retdict["success"] = False pass return retdict @@ -332,17 +334,21 @@ def sysak_to_sysom_info(sysakdict): class PostProcessor(DiagnosisPostProcessor): def parse_diagnosis_result(self, results: List[DiagnosisJobResult]) -> PostProcessResult: postprocess_result = PostProcessResult( - code=0, + code=1, err_msg="", result={} ) ossre_ret = results[0].stdout instance_ip = results[0].job.instance - print (ossre_ret) + logger.info(ossre_ret) datas = [] piedatas = [] mddata = "" + summary_final = "" + status_final = "normal" + suggestion_final = "" + try: results = json.loads(ossre_ret) retdict = sysak_to_sysom_info(results["ossre"]) @@ -610,16 +616,33 @@ class PostProcessor(DiagnosisPostProcessor): total_count,new_checkItems = flush_checkItems(piedatas,total_abnormal_count,level_num) new_hostInfo = flush_hostInfo(mddata,total_abnormal_count,level_num,total_count) - except: - traceback.print_exc() + summary_final = "共检测%s项,告警项%s个,错误项%s个,严重异常项%s个"%(total_count,level_num["warning"],level_num["error"],level_num["critical"]) + if level_num["warning"] > 0 : + status_final = "warning" + if level_num["error"] > 0 : + status_final = "error" + if level_num["critical"] > 0 : + status_final = "critical" + if status_final != "normal": + suggestion_final = "查看具体检查列表异常项,根据提示对异常进行处理或进一步诊断。" + + postprocess_result.code = 0 + + except Exception as e: + logger.exception(e) + postprocess_result.err_msg = e pass try: postprocess_result.result = { - "OssreResult": {"data": new_data},"checkItems":{"data":new_checkItems},"hostInfo":{"data":new_hostInfo} + "OssreResult": {"data": new_data}, + "checkItems":{"data":new_checkItems}, + "hostInfo":{"data":new_hostInfo}, + "summary":{"status": status_final,"cause":summary_final,"suggestion":suggestion_final} } - except: - traceback.print_exc() + except Exception as e: + logger.exception(e) + postprocess_result.err_msg = e pass - print (postprocess_result.result) + logger.info(postprocess_result.result) return postprocess_result diff --git a/sysom_web/cypress/e2e/diagnosis/system_health_test.cy.js b/sysom_web/cypress/e2e/diagnosis/system_health_test.cy.js index 3f361d95fa6a2884623026051b3e65fb7ab1e90f..94191c0258669393859d035e326dfc974a5acfc6 100644 --- a/sysom_web/cypress/e2e/diagnosis/system_health_test.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/system_health_test.cy.js @@ -9,7 +9,7 @@ describe("SysOM Diagnosis Test -- system health", () => { //cy.wait(5000) cy.sysomDiagnosisCheck( // 诊断前端url - "diagnose/oscheck", + "diagnose/ossre", // 诊断参数 { @@ -39,4 +39,4 @@ describe("SysOM Diagnosis Test -- system health", () => { /* ==== End Cypress Studio ==== */ }) }) -}) \ No newline at end of file +}) diff --git a/sysom_web/public/resource/diagnose/v2/ossre.json b/sysom_web/public/resource/diagnose/v2/ossre.json index 0cb5f58fd564b73d69ab2a8530ee229164359e57..978352bb3a989b5e713200d1bd4d9eb1221b844c 100644 --- a/sysom_web/public/resource/diagnose/v2/ossre.json +++ b/sysom_web/public/resource/diagnose/v2/ossre.json @@ -35,7 +35,7 @@ { "key": "ossre_result", "type": "table", - "title": "", + "title": "检查列表", "datasource": "OssreResult", "columns": [ { @@ -112,4 +112,4 @@ } } ] -} \ No newline at end of file +}