diff --git a/venus/db/alembic/versions/a6cf98f55b4d_.py b/venus/db/alembic/versions/a6cf98f55b4d_.py index 65a83f7..12ca317 100644 --- a/venus/db/alembic/versions/a6cf98f55b4d_.py +++ b/venus/db/alembic/versions/a6cf98f55b4d_.py @@ -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, diff --git a/venus/modules/anomaly_detect/action.py b/venus/modules/anomaly_detect/action.py index a9e6f3b..cf715d6 100644 --- a/venus/modules/anomaly_detect/action.py +++ b/venus/modules/anomaly_detect/action.py @@ -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): diff --git a/venus/modules/anomaly_detect/backends/sql.py b/venus/modules/anomaly_detect/backends/sql.py index 829784e..699eafd 100644 --- a/venus/modules/anomaly_detect/backends/sql.py +++ b/venus/modules/anomaly_detect/backends/sql.py @@ -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() diff --git a/venus/modules/anomaly_detect/controller.py b/venus/modules/anomaly_detect/controller.py index 5454015..477d5cd 100644 --- a/venus/modules/anomaly_detect/controller.py +++ b/venus/modules/anomaly_detect/controller.py @@ -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} diff --git a/venus/modules/custom_config/controller.py b/venus/modules/custom_config/controller.py index b3ea342..47ed321 100644 --- a/venus/modules/custom_config/controller.py +++ b/venus/modules/custom_config/controller.py @@ -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