|
|
|
# coding=utf-8
|
|
|
|
"""
|
|
|
|
@Author: fu-zhe
|
|
|
|
@FileName: dashboard_views.py
|
|
|
|
@DateTime: 2024/5/20 17:34
|
|
|
|
@Description:
|
|
|
|
"""
|
|
|
|
|
|
|
|
import json,os
|
|
|
|
import traceback,time
|
|
|
|
|
|
|
|
from rest_framework import viewsets
|
|
|
|
from rest_framework.decorators import list_route, detail_route
|
|
|
|
from uebaMetricsAnalysis.utils.ext_logging import logger
|
|
|
|
from uebaMetricsAnalysis.lib.result import Result
|
|
|
|
from uebaMetricsAnalysis.utils import config
|
|
|
|
from uebaMetricsAnalysis.utils.dashboard_data import entry
|
|
|
|
class DashboardViewSets(viewsets.GenericViewSet):
|
|
|
|
@list_route(methods=['GET'])
|
|
|
|
def get_summary_data_list(self,request):
|
|
|
|
try:
|
|
|
|
data_type = request.GET.get('type')
|
|
|
|
startTime = "2024-01-01T00:00:00Z"# request.GET.get('startDate')
|
|
|
|
endTime = "2024-07-11T00:00:00Z" #request.GET.get('endDate')
|
|
|
|
#1:ip,2:账号,3:接口,4:菜单
|
|
|
|
logger.info("获取分析结构数据:"+data_type+";" + startTime +";"+ endTime)
|
|
|
|
return Result.ok(entry(data_type,startTime,endTime))
|
|
|
|
except Exception, e:
|
|
|
|
logger.error(traceback.format_exc())
|
|
|
|
return Result.failed("查询失败", str(e))
|
|
|
|
|
|
|
|
@list_route(methods=['POST'])
|
|
|
|
def write_audit_log(self, request):
|
|
|
|
try:
|
|
|
|
body = json.loads(request.body)
|
|
|
|
action =body.get("action")
|
|
|
|
username = request.session.get('username',"unknown user")
|
|
|
|
params = body.get("params")
|
|
|
|
logger.info("Audit_Log:"+username+","+action +",params:"+json.dumps(params))
|
|
|
|
except Exception, e:
|
|
|
|
logger.info("Audit_Log:{}, err: {}, traceback: {}".format(username, str(e), traceback.format_exc()))
|
|
|
|
return Result.ok("ok")
|
|
|
|
|
|
|
|
@list_route(methods=['GET'])
|
|
|
|
def get_default_rule(self,request):
|
|
|
|
conf_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'conf')
|
|
|
|
jsonfile_path = os.path.join(conf_path, 'defaultRule.json')
|
|
|
|
rule_data = config.read_json_config(jsonfile_path)
|
|
|
|
return Result.ok(rule_data)
|
|
|
|
|
|
|
|
@list_route(methods=['GET'])
|
|
|
|
def create_index(self,request):
|
|
|
|
res= es_operation.createIndex()
|
|
|
|
logger.error(json.dumps(res))
|
|
|
|
return Result.ok(json.dumps(res))
|