diff --git a/venusclient/v1/anomaly.py b/venusclient/v1/anomaly.py new file mode 100644 index 0000000..4a02368 --- /dev/null +++ b/venusclient/v1/anomaly.py @@ -0,0 +1,51 @@ +# Copyright 2023 Inspur +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from venusclient.common import utils +from venusclient.v1 import basemodels + +CREATION_ATTRIBUTES = basemodels.CREATION_ATTRIBUTES + + +class LogAnomaly(basemodels.BaseModel): + model_name = "Anomaly" + + +class AnomalyManager(basemodels.BaseModelManager): + api_name = "anomaly" + base_url = "anomaly" + resource_class = LogAnomaly + + def rule_list(self, title='', desc='', keyword='', + log_type='', module_name='', host_name='', + page_num=1, page_size=10): + url = '/v1/anomaly/rule/list' + + params = { + 'title ': title, + 'desc': desc, + 'keyword': keyword, + 'log_type': log_type, + 'module_name': module_name, + 'flag': host_name, + 'page_num': page_num, + 'page_size': page_size + } + url += utils.prepare_query_string(params) + + try: + resp, body = self.api.json_request('GET', url) + return body + except Exception as e: + raise RuntimeError(str(e)) diff --git a/venusclient/v1/anomaly_shell.py b/venusclient/v1/anomaly_shell.py new file mode 100644 index 0000000..dd4221f --- /dev/null +++ b/venusclient/v1/anomaly_shell.py @@ -0,0 +1,20 @@ +# Copyright 2023 Inspur +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +def do_rule_list(cs, args): + """get anomaly rule list""" + endpoint = cs.anomaly.rule_list(args) + print(endpoint) + return endpoint diff --git a/venusclient/v1/client.py b/venusclient/v1/client.py index 9534ba0..34fd33e 100644 --- a/venusclient/v1/client.py +++ b/venusclient/v1/client.py @@ -18,6 +18,7 @@ from keystoneauth1 import session as ksa_session from oslo_utils import importutils from venusclient.common import httpclient from venusclient.v1 import analyse +from venusclient.v1 import anomaly from venusclient.v1 import config from venusclient.v1 import search @@ -184,6 +185,7 @@ class Client(object): self.config = config.ConfigManager(self.http_client) self.search = search.SearchManager(self.http_client) self.analyse = analyse.AnalyseManager(self.http_client) + self.anomaly = anomaly.AnomalyManager(self.http_client) profile = kwargs.pop("profile", None) if profiler and profile: diff --git a/venusclient/v1/shell.py b/venusclient/v1/shell.py index b616485..81f8db4 100644 --- a/venusclient/v1/shell.py +++ b/venusclient/v1/shell.py @@ -13,12 +13,13 @@ # under the License. from venusclient.v1 import analyse_shell +from venusclient.v1 import anomaly_shell from venusclient.v1 import config_shell from venusclient.v1 import search_shell - COMMAND_MODULES = [ config_shell, search_shell, - analyse_shell + analyse_shell, + anomaly_shell, ]