You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hbyd_ueba/views/dashboard_views.py

55 lines
2.2 KiB

6 months ago
# coding=utf-8
"""
@Author: fu-zhe
@FileName: dashboard_views.py
@DateTime: 2024/5/20 17:34
@Description:
"""
4 months ago
import json,os
import traceback,time
6 months ago
from rest_framework import viewsets
from rest_framework.decorators import list_route, detail_route
4 months ago
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
6 months ago
class DashboardViewSets(viewsets.GenericViewSet):
@list_route(methods=['GET'])
4 months ago
def get_summary_data_list(self,request):
6 months ago
try:
4 months ago
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))
6 months ago
except Exception, e:
4 months ago
logger.error(traceback.format_exc())
6 months ago
return Result.failed("查询失败", str(e))
4 months ago
@list_route(methods=['POST'])
def write_audit_log(self, request):
6 months ago
try:
4 months ago
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))
6 months ago
except Exception, e:
4 months ago
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)
6 months ago
4 months ago
@list_route(methods=['GET'])
def create_index(self,request):
res= es_operation.createIndex()
logger.error(json.dumps(res))
return Result.ok(json.dumps(res))