From 842e3131acf26961e9cdbfe7a6e2ee2f847a86cf Mon Sep 17 00:00:00 2001 From: wenxin Date: Fri, 23 Dec 2022 12:43:34 +0800 Subject: [PATCH] Handle when the http response result is not 200 --- ...-the-http-response-result-is-not-200.patch | 151 ++++++++++++++++++ aops-ceres.spec | 6 +- 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 0003-Handle-when-the-http-response-result-is-not-200.patch diff --git a/0003-Handle-when-the-http-response-result-is-not-200.patch b/0003-Handle-when-the-http-response-result-is-not-200.patch new file mode 100644 index 0000000..88a4042 --- /dev/null +++ b/0003-Handle-when-the-http-response-result-is-not-200.patch @@ -0,0 +1,151 @@ +From b273525d63a037585a3c5c52609c59adc188f1ba Mon Sep 17 00:00:00 2001 +From: wenxin +Date: Tue, 13 Dec 2022 10:28:27 +0800 +Subject: [PATCH 1/2] adjust code type comments + +--- + ceres/function/register.py | 2 +- + ceres/function/util.py | 2 +- + ceres/manages/collect_manage.py | 2 +- + ceres/manages/plugin_manage.py | 4 ++-- + ceres/manages/vulnerability_manage.py | 6 +++--- + 5 files changed, 8 insertions(+), 8 deletions(-) + +diff --git a/ceres/function/register.py b/ceres/function/register.py +index 1f02252..a36a346 100644 +--- a/ceres/function/register.py ++++ b/ceres/function/register.py +@@ -25,7 +25,7 @@ from ceres.manages.collect_manage import Collect + from ceres.manages.token_manage import TokenManage + + +-def register_info_to_dict(string: str) -> Dict: ++def register_info_to_dict(string: str) -> dict: + """ + Convert JSON string to dictionary + Args: +diff --git a/ceres/function/util.py b/ceres/function/util.py +index d834085..5d1bc85 100644 +--- a/ceres/function/util.py ++++ b/ceres/function/util.py +@@ -146,7 +146,7 @@ def plugin_status_judge(plugin_name: str) -> str: + return res + + +-def get_dict_from_file(file_path: str) -> Dict: ++def get_dict_from_file(file_path: str) -> dict: + """ + Get json data from file and return related dict + Args: +diff --git a/ceres/manages/collect_manage.py b/ceres/manages/collect_manage.py +index f38dcb3..74f131b 100644 +--- a/ceres/manages/collect_manage.py ++++ b/ceres/manages/collect_manage.py +@@ -293,7 +293,7 @@ class Collect: + return res + + @staticmethod +- def _get_disk_info() -> List[Dict]: ++ def _get_disk_info() -> List[dict]: + """ + get disk capacity and model + +diff --git a/ceres/manages/plugin_manage.py b/ceres/manages/plugin_manage.py +index f0ddd42..671cead 100644 +--- a/ceres/manages/plugin_manage.py ++++ b/ceres/manages/plugin_manage.py +@@ -112,7 +112,7 @@ class Plugin: + installed_plugin.remove(plugin_name) + return installed_plugin + +- def get_plugin_status(self): ++ def get_plugin_status(self) -> str: + """ + Get plugin running status which is installed + +@@ -132,7 +132,7 @@ class Plugin: + return status + + @classmethod +- def get_pid(cls, rpm_name): ++ def get_pid(cls, rpm_name) -> str: + """ + Get main process id when plugin is running + +diff --git a/ceres/manages/vulnerability_manage.py b/ceres/manages/vulnerability_manage.py +index d4d25e2..6e08291 100644 +--- a/ceres/manages/vulnerability_manage.py ++++ b/ceres/manages/vulnerability_manage.py +@@ -29,7 +29,7 @@ from ceres.models.custom_exception import InputError + + + class VulnerabilityManage: +- def repo_set(self, data: Dict) -> int: ++ def repo_set(self, data: dict) -> int: + """ + Save the repo source to local, and do simple verification. + +@@ -83,7 +83,7 @@ class VulnerabilityManage: + repo_info = 'Error' + return "Error" not in repo_info + +- def cve_scan(self, cve_scan_args: Dict) -> Tuple[int, List]: ++ def cve_scan(self, cve_scan_args: dict) -> Tuple[int, list]: + """ + Scan CVEs in the machine + +@@ -113,7 +113,7 @@ class VulnerabilityManage: + return REPO_NOT_SET, [] + + @staticmethod +- def _check_cve_by_yum(repo_id: str) -> Tuple[int, List]: ++ def _check_cve_by_yum(repo_id: str) -> Tuple[int, list]: + """ + Detect which CVEs can be fixed from the update source + +-- +Gitee + + +From 11643982a9f56fce2172c17a0919336475d8a0d0 Mon Sep 17 00:00:00 2001 +From: wenxin +Date: Fri, 23 Dec 2022 12:26:02 +0800 +Subject: [PATCH 2/2] bug fix:Handle when the http response result is not 200 + +--- + ceres/function/register.py | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/ceres/function/register.py b/ceres/function/register.py +index a36a346..6e7f7fc 100644 +--- a/ceres/function/register.py ++++ b/ceres/function/register.py +@@ -76,7 +76,7 @@ def register(register_info: dict) -> int: + data['host_id'] = Collect.get_uuid() + data['public_ip'] = Collect.get_host_ip() + data['agent_port'] = register_info.get('ceres_port') or \ +- configuration.ceres.get('PORT') ++ configuration.ceres.get('PORT') + data["os_version"] = Collect.get_system_info() + + zeus_ip = register_info.get('zeus_ip') +@@ -88,11 +88,15 @@ def register(register_info: dict) -> int: + except requests.exceptions.RequestException as e: + LOGGER.error(e) + return HTTP_CONNECT_ERROR ++ ++ if ret.status_code != SUCCESS: ++ LOGGER.warning(ret.text) ++ return ret.status_code ++ + ret_data = json.loads(ret.text) + if ret_data.get('code') == SUCCESS: + TokenManage.set_value(ret_data.get('token')) +- save_data_to_file(json.dumps({"access_token": ret_data.get('token')}), +- DEFAULT_TOKEN_PATH) ++ save_data_to_file(json.dumps({"access_token": ret_data.get('token')}), DEFAULT_TOKEN_PATH) + return SUCCESS + LOGGER.error(ret_data) + return int(ret_data.get('code')) +-- +Gitee diff --git a/aops-ceres.spec b/aops-ceres.spec index 49997de..3e1f5b6 100644 --- a/aops-ceres.spec +++ b/aops-ceres.spec @@ -1,12 +1,13 @@ Name: aops-ceres Version: v1.1.0 -Release: 3 +Release: 4 Summary: An agent which needs to be adopted in client, it managers some plugins, such as gala-gopher(kpi collection), fluentd(log collection) and so on. License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} Source0: %{name}-%{version}.tar.gz Patch0001: 0001-update-register.patch Patch0002: 0002-update-cve-fix.patch +Patch0003: 0003-Handle-when-the-http-response-result-is-not-200.patch BuildRequires: python3-setuptools Requires: python3-requests python3-flask python3-connexion python3-configparser python3-jsonschema @@ -43,6 +44,9 @@ An agent which needs to be adopted in client, it managers some plugins, such as %changelog +* Fri Dec 23 2022 wenxin - v1.1.0-4 +- Handle when the http response result is not 200 + * Wed Dec 07 2022 wenxin - v1.1.0-3 - update cve fix