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

49 lines
1.9 KiB

6 months ago
# coding=utf-8
"""
@Author: fu-zhe
@FileName: dashboard_views.py
@DateTime: 2024/5/20 17:34
@Description:
"""
5 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
5 months ago
from uebaMetricsAnalysis.utils.ext_logging import logger
from uebaMetricsAnalysis.lib.result import Result
from uebaMetricsAnalysis.utils import config
4 months ago
from uebaMetricsAnalysis.utils.dashboard_data_pg import entry
6 months ago
class DashboardViewSets(viewsets.GenericViewSet):
@list_route(methods=['GET'])
5 months ago
def get_summary_data_list(self,request):
6 months ago
try:
5 months ago
data_type = request.GET.get('type')
4 months ago
startTime = request.GET.get('startDate')
endTime = request.GET.get('endDate')
5 months ago
#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:
5 months ago
logger.error(traceback.format_exc())
6 months ago
return Result.failed("查询失败", str(e))
5 months ago
@list_route(methods=['POST'])
def write_audit_log(self, request):
6 months ago
try:
5 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:
5 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)
4 months ago
return Result.ok(rule_data)