def fetch_alarm_disposition_list(request): """ 获取故障处理工单数据 :param request: :return: """ req_params = parse_json(request) limit = req_params.get('limit', 20) current_page = req_params.get('page', 1) sj_org_code = req_params.get("SJ_ORG_CODE") one_solve = req_params.get("ONE_SOLVE") satisfaction = req_params.get("SATISFACTION") status = req_params.get("STATUS") # 执行sql语句 table_name = "v_alarm_disposition_9" try: keywords = [] if sj_org_code is not None and len(sj_org_code.strip()) > 0: keywords.append({ "key": "SJ_ORG_CODE", "value": sj_org_code, "condition": "=" }) if one_solve in [10, 20, 30]: keywords.append({ "key": "ONE_SOLVE", "value": str(one_solve), "condition": "=" }) if satisfaction in [10, 20, 30]: keywords.append({ "key": "SATISFACTION", "value": str(satisfaction), "condition": "=" }) if status in [10, 20, 30, 40]: keywords.append({ "key": "STATUS", "value": str(status), "condition": "=" }) sql, con_sql = splice_sql(table_name, limit, current_page, keywords=keywords) oracle_execute_sql = OracleExecuteSQL() object_list = oracle_execute_sql.fetchall_to_dict(sql) count = oracle_execute_sql.fetchone_to_dict(con_sql) data = { 'count': count.get("COUNT", 0), 'list': object_list, 'current_page': current_page } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)
def fetch_alarm_record_list(request): """ 获取基础故障告警数据 :param request: :return: """ req_params = parse_json(request) limit = req_params.get('limit', 20) current_page = req_params.get('page', 1) sj_org_code = req_params.get("SJ_ORG_CODE") name = req_params.get("NAME") severity = req_params.get("SEVERITY") pro_status = req_params.get("PRO_STATUS") # 执行sql语句 table_name = "v_alarm_record_9" try: keywords = [] if sj_org_code is not None and len(sj_org_code.strip()) > 0: keywords.append({ "key": "SJ_ORG_CODE", "value": sj_org_code, "condition": "=" }) if name is not None and len(name.strip()) > 0: keywords.append({ "key": "NAME", "value": name + "", "condition": "like" }) if severity in [0, 1, 2]: keywords.append({ "key": "SEVERITY", "value": str(severity), "condition": "=" }) if pro_status in [10, 20, 30]: keywords.append({ "key": "PRO_STATUS", "value": str(pro_status), "condition": "=" }) sql, con_sql = splice_sql(table_name, limit, current_page, keywords=keywords) oracle_execute_sql = OracleExecuteSQL() object_list = oracle_execute_sql.fetchall_to_dict(sql) count = oracle_execute_sql.fetchone_to_dict(con_sql) data = { 'count': count.get("COUNT", 0), 'list': object_list, 'current_page': current_page } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)
def fetch_network_perf_list(request): """ 获取网络设备监测指标数据 :param request: :return: """ req_params = parse_json(request) limit = req_params.get('limit', 20) current_page = req_params.get('page', 1) sj_org_code = req_params.get("ORG_CODE") net_dev_online_state = req_params.get("NET_DEV_ONLINE_STATE") net_dev_alert_level = req_params.get("NET_DEV_ALERT_LEVEL") # 执行sql语句 table_name = "v_network_perf_9" try: keywords = [] if sj_org_code is not None and len(sj_org_code.strip()) > 0: keywords.append({ "key": "ORG_CODE", "value": sj_org_code, "condition": "=" }) if net_dev_online_state in [10, 20]: keywords.append({ "key": "NET_DEV_ONLINE_STATE", "value": str(net_dev_online_state), "condition": "=" }) if net_dev_alert_level in [0, 1, 2, 3]: keywords.append({ "key": "NET_DEV_ALERT_LEVEL", "value": str(net_dev_alert_level), "condition": "=" }) sql, con_sql = splice_sql(table_name, limit, current_page, keywords=keywords) oracle_execute_sql = OracleExecuteSQL() object_list = oracle_execute_sql.fetchall_to_dict(sql) count = oracle_execute_sql.fetchone_to_dict(con_sql) data = { 'count': count.get("COUNT", 0), 'list': object_list, 'current_page': current_page } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)
def fetch_hardware_resource_list(request): """ 获取硬件资源数据 :param request: :return: """ req_params = parse_json(request) limit = req_params.get('limit', 20) current_page = req_params.get('page', 1) sj_org_code = req_params.get("SJ_ORG_CODE") sj_status = req_params.get("SJ_STATUS") sj_cl_network = req_params.get("SJ_CI_NETWORK") # 执行sql语句 table_name = "v_hardware_resource_9" try: keywords = [] if sj_org_code is not None and len(sj_org_code.strip()) > 0: keywords.append({ "key": "SJ_ORG_CODE", "value": sj_org_code + "", "condition": "=" }) if sj_status in [1, 2, 3, 4, 5, 6, 7, 8]: keywords.append({ "key": "SJ_STATUS", "value": str(sj_status), "condition": "=" }) if sj_cl_network in [1, 2]: keywords.append({ "key": "SJ_CI_NETWORK", "value": str(sj_cl_network), "condition": "=" }) sql, con_sql = splice_sql(table_name, limit, current_page, keywords=keywords) oracle_execute_sql = OracleExecuteSQL() object_list = oracle_execute_sql.fetchall_to_dict(sql) count = oracle_execute_sql.fetchone_to_dict(con_sql) data = { 'count': count.get("COUNT", 0), 'list': object_list, 'current_page': current_page } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)
def fetch_network_link_list(request): """ 获取网络骨干链路信息数据 :param request: :return: """ req_params = parse_json(request) limit = req_params.get('limit', 20) current_page = req_params.get('page', 1) sj_org_code = req_params.get("ORG_CODE") # 执行sql语句 table_name = "v_network_link_9" try: keywords = [] if sj_org_code is not None and len(sj_org_code.strip()) > 0: keywords.append({ "key": "ORG_CODE", "value": sj_org_code, "condition": "=" }) sql, con_sql = splice_sql(table_name, limit, current_page, keywords=keywords) oracle_execute_sql = OracleExecuteSQL() object_list = oracle_execute_sql.fetchall_to_dict(sql) count = oracle_execute_sql.fetchone_to_dict(con_sql) data = { 'count': count.get("COUNT", 0), 'list': object_list, 'current_page': current_page } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)
def get_data_source(request): """ 获取数据来源 """ try: # 微信轻应用数 wechat_data = PoliceWechatData.objects.filter( isDeleted=0).values('appName').annotate(count=Count("id")) # 动环告警未处理数据 alert_non_process = FaultAlert.objects.filter( proStatus=10, isDeleted=0).aggregate(count=Count("id")) # 故障告警未处理数据 sql = "SELECT COUNT(1) as count FROM " + get_table_name( 'v_alarm_record_9') + " WHERE PRO_STATUS='10'" oracle_execute_sql = OracleExecuteSQL() alarm_record = oracle_execute_sql.fetchone_to_dict(sql) # 云上服务类型数,云上应用数 ser_app_list = CloudDataAll.objects.filter(isDeleted=0) ser_app_count = get_ser_app_count(ser_app_list) ser_type_count = CloudDataAll.objects.filter( isDeleted=0).values('sJcloudBrand').annotate(count=Count("id")) # 软件实例数 soft_data = SoftData.objects.filter(isDeleted=0).aggregate( count=Count("id")) # 基础软件实例数 base_soft_data = BaseSoftData.objects.filter( isDeleted=0).values('sJsoftName').annotate(count=Count("id")) # 机房数 sql = "SELECT SJ_RM_CODE FROM " + get_table_name( 'v_room_situation_9') + "ORDER BY 'SJ_RM_CODE'" room_data = oracle_execute_sql.fetchall_to_dict(sql) # 工单未解决 sql = "SELECT COUNT(1) as count FROM " + get_table_name( 'v_alarm_disposition_9') + " WHERE ONE_SOLVE='30'" work_order = oracle_execute_sql.fetchone_to_dict(sql) # 硬件资源 sql = "SELECT SJ_CI_ID FROM " + get_table_name( 'v_hardware_resource_9') + "ORDER BY 'SJ_CI_ID'" hardware_resources = oracle_execute_sql.fetchall_to_dict(sql) # 获取网络设备指标 sql = "SELECT AVG(NET_DEV_CPU_RATE) as NET_DEV_CPU_RATE, AVG(NET_DEV_MEM_RATE) AS NET_DEV_MEM_RATE FROM " + get_table_name( 'v_network_perf_9') network_perf = oracle_execute_sql.fetchone_to_dict(sql) # 获取网络设备在线率 sql = "SELECT COUNT(1) as count FROM " + get_table_name( 'v_network_perf_9') + " WHERE NET_DEV_ONLINE_STATE = '10'" on_line = oracle_execute_sql.fetchone_to_dict(sql) sql = "SELECT COUNT(1) as count FROM " + get_table_name( 'v_network_perf_9') count = oracle_execute_sql.fetchone_to_dict(sql) on_line_rate = on_line.get("COUNT") / count.get("COUNT") * 100 data = { "data_source": { "wechat_data": len(wechat_data), # 微信轻应用数 "ser_app_count": ser_app_count, # 云上应用数 "ser_type_count": len(ser_type_count), # 云上服务类型数 "soft_data": soft_data.get("count"), # 软件实例数 "base_soft_data": len(base_soft_data) }, "top_data": { "room_data": len(room_data), "alert_non_process": alert_non_process.get("count") + alarm_record.get("COUNT"), # 告警未处理数据 "work_order_not_process": work_order.get("COUNT"), # 工单未处理数 "hardware_resources": len(hardware_resources) # 硬件资源 }, "network_perf": { "net_dev_cpu_rate": network_perf.get("NET_DEV_CPU_RATE"), "net_dev_men_rate": network_perf.get("NET_DEV_MEM_RATE"), "on_line_rate": on_line_rate } } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)
def branch(request): req_params = parse_json(request) limit = req_params.get('limit', 20) current_page = req_params.get('page', 1) sj_org_code = req_params.get("SJ_ORG_CODE") sj_rm_name = req_params.get("SJ_RM_NAME") sj_is_th_mon = req_params.get("SJ_IS_TH_MON") sj_is_water_mon = req_params.get("SJ_IS_WATER_MON") sj_is_fire_mon = req_params.get("SJ_IS_FIRE_MON") # 执行sql语句 table_name = "v_room_situation_9" try: keywords = [] if sj_org_code is not None and len(sj_org_code.strip()) > 0: keywords.append({ "key": "SJ_ORG_CODE", "value": sj_org_code, "condition": "=" }) if sj_rm_name is not None and len(sj_rm_name.strip()) > 0: keywords.append({ "key": "SJ_RM_NAME", "value": sj_rm_name + "", "condition": "like" }) if sj_is_th_mon in [10, 20]: keywords.append({ "key": "SJ_IS_TH_MON", "value": str(sj_is_th_mon), "condition": "=" }) if sj_is_water_mon in [10, 20]: keywords.append({ "key": "SJ_IS_WATER_MON", "value": str(sj_is_water_mon), "condition": "=" }) if sj_is_fire_mon in [10, 20]: keywords.append({ "key": "SJ_IS_FIRE_MON", "value": str(sj_is_fire_mon), "condition": "=" }) sql, con_sql = splice_sql(table_name, limit, current_page, keywords=keywords) oracle_execute_sql = OracleExecuteSQL() object_list = oracle_execute_sql.fetchall_to_dict(sql) count = oracle_execute_sql.fetchone_to_dict(con_sql) data = { 'count': count.get("COUNT", 0), 'list': object_list, 'current_page': current_page } return json_resp("success", data) except Exception as e: print(e) return json_resp("error", None, 500)