fix anomaly detect api bugs
Change-Id: Ic9d6c8d99c12728c0acb40d0e1e5a2ef8d13b431
This commit is contained in:
parent
cdf6c050b6
commit
f92c940b9e
@ -133,7 +133,7 @@ def upgrade() -> None:
|
||||
|
||||
# create anomaly record table
|
||||
op.create_table(
|
||||
't_mo_anomaly_record',
|
||||
't_mo_anomaly_records',
|
||||
sa.Column('id', sa.String(64), nullable=False, primary_key=True),
|
||||
sa.Column('title', sa.String(1024), nullable=True,
|
||||
primary_key=False),
|
||||
@ -145,7 +145,8 @@ def upgrade() -> None:
|
||||
primary_key=False),
|
||||
sa.Column('module', sa.String(1024), nullable=True,
|
||||
primary_key=False),
|
||||
sa.Column('flag', sa.Integer, nullable=True, primary_key=False),
|
||||
sa.Column('logs', sa.String(10240), nullable=True,
|
||||
primary_key=False),
|
||||
sa.Column('start_time', sa.DateTime, nullable=True,
|
||||
primary_key=False, default='0000-00-00 00:00:00'),
|
||||
sa.Column('end_time', sa.DateTime, nullable=True,
|
||||
|
@ -29,7 +29,7 @@ class AnomalyDetectCore(object):
|
||||
return res
|
||||
|
||||
def get_rule_list(self, params):
|
||||
res = self.sql.get_rule_list(self, params)
|
||||
res = self.sql.get_rule_list(params)
|
||||
return res
|
||||
|
||||
def update_rule(self, params):
|
||||
@ -45,7 +45,7 @@ class AnomalyDetectCore(object):
|
||||
return res
|
||||
|
||||
def get_record_list(self, params):
|
||||
res = self.sql.get_record_list(self, params)
|
||||
res = self.sql.get_record_list(params)
|
||||
return res
|
||||
|
||||
def delete_record(self, id):
|
||||
|
@ -49,7 +49,7 @@ class AnomalyDetectSql(object):
|
||||
def get_rule_list(self, params):
|
||||
title = params["title"]
|
||||
module = params["module"]
|
||||
flag = int(params["flag"])
|
||||
flag = params["flag"]
|
||||
page_num = int(params["page_num"])
|
||||
page_size = int(params["page_size"])
|
||||
|
||||
@ -62,8 +62,8 @@ class AnomalyDetectSql(object):
|
||||
if module:
|
||||
query = query.filter(models.AnomalyRules.module == module)
|
||||
if flag:
|
||||
query = query.filter(models.AnomalyRules.flag == flag)
|
||||
query = query.limit(page_size).offset((page_num - 1) * page_num)
|
||||
query = query.filter(models.AnomalyRules.flag == int(flag))
|
||||
query = query.limit(page_size).offset((page_num - 1) * page_size)
|
||||
res = query.all()
|
||||
return res
|
||||
|
||||
@ -80,6 +80,8 @@ class AnomalyDetectSql(object):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
rule = session.query(models.AnomalyRules).filter_by(id=id).first()
|
||||
if rule is None:
|
||||
return None
|
||||
if title:
|
||||
rule.title = title
|
||||
if desc:
|
||||
@ -93,6 +95,7 @@ class AnomalyDetectSql(object):
|
||||
if flag:
|
||||
rule.flag = int(flag)
|
||||
rule.update_time = t
|
||||
return rule
|
||||
|
||||
def delete_rule(self, id):
|
||||
session = get_session()
|
||||
|
@ -83,7 +83,18 @@ class AnomalyDetectController(wsgi.Controller):
|
||||
params["flag"] = req.params.get("flag", None)
|
||||
params["page_num"] = req.params.get("page_num", "1")
|
||||
params["page_size"] = req.params.get("page_size", "10")
|
||||
rules = self.api.get_rule_list(params)
|
||||
res = self.api.get_rule_list(params)
|
||||
rules = []
|
||||
for r in res:
|
||||
rule = dict()
|
||||
rule["title"] = r.title
|
||||
rule["desc"] = r.desc
|
||||
rule["keyword"] = r.keyword
|
||||
rule["log_type"] = r.log_type
|
||||
rule["module"] = r.module
|
||||
rule["create_time"] = r.create_time
|
||||
rule["update_time"] = r.update_time
|
||||
rules.append(rule)
|
||||
|
||||
return {"code": 0, "msg": "OK", "rules": rules}
|
||||
|
||||
@ -100,9 +111,11 @@ class AnomalyDetectController(wsgi.Controller):
|
||||
params["log_type"] = body.get("log_type", None)
|
||||
params["module"] = body.get("module", None)
|
||||
params["flag"] = body.get("flag", None)
|
||||
self.api.update_rule(params)
|
||||
|
||||
return {"code": 0, "msg": "OK"}
|
||||
rule = self.api.update_rule(params)
|
||||
if rule:
|
||||
return {"code": 0, "msg": "OK", "rule": rule}
|
||||
else:
|
||||
return {"code": -1, "msg": "no found"}
|
||||
|
||||
@wsgi.wrap_check_policy
|
||||
def delete_rule(self, req, id):
|
||||
@ -119,7 +132,21 @@ class AnomalyDetectController(wsgi.Controller):
|
||||
params["end_time"] = req.params.get("end_time", None)
|
||||
params["page_num"] = req.params.get("page_num", "1")
|
||||
params["page_size"] = req.params.get("page_size", "10")
|
||||
records = self.api.get_record_list(params)
|
||||
res = self.api.get_record_list(params)
|
||||
|
||||
records = []
|
||||
for r in res:
|
||||
record = dict()
|
||||
record["title"] = r.title
|
||||
record["desc"] = r.desc
|
||||
record["keyword"] = r.keyword
|
||||
record["log_type"] = r.log_type
|
||||
record["module"] = r.module
|
||||
record["logs"] = r.logs
|
||||
record["start_time"] = r.create_time
|
||||
record["end_time"] = r.create_time
|
||||
record["create_time"] = r.create_time
|
||||
records.append(record)
|
||||
|
||||
return {"code": 0, "msg": "OK", "rules": records}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class CustomConfigController(wsgi.Controller):
|
||||
@wsgi.wrap_check_policy
|
||||
def get_config(self, req):
|
||||
result = dict()
|
||||
result["log_save_days"] = self.config_api.get_config("es_index_length")
|
||||
result["log_save_days"] = self.config_api.get_config("log_save_days")
|
||||
return result
|
||||
|
||||
@wsgi.wrap_check_policy
|
||||
|
Loading…
Reference in New Issue
Block a user