Remove ANSI escape sequences

This commit is contained in:
shixuantong 2024-08-11 18:38:48 +08:00
parent 31f314277d
commit 01ef8cc4ec
2 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,32 @@
From 91aa47999030503fda4935d4cc238b82d6842238 Mon Sep 17 00:00:00 2001
From: shixuantong <shixuantong1@huawei.com>
Date: Sun, 11 Aug 2024 18:36:23 +0800
Subject: [PATCH] Remove ANSI escape sequences
---
src/python/syssentry/cpu_sentry.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/python/syssentry/cpu_sentry.py b/src/python/syssentry/cpu_sentry.py
index 9287e2f..99af127 100644
--- a/src/python/syssentry/cpu_sentry.py
+++ b/src/python/syssentry/cpu_sentry.py
@@ -97,7 +97,14 @@ class CpuSentry:
if "ERROR" in stdout:
self.send_result["result"] = ResultLevel.FAIL
self.send_result["details"]["code"] = 1004
- self.send_result["details"]["msg"] = stdout.split("\n")[0]
+
+ # Remove ANSI escape sequences
+ error_info = stdout.split("\n")[0]
+ if error_info.startswith("\u001b"):
+ ansi_escape = r'\x1b\[([0-9]+)(;[0-9]+)*([A-Za-z])'
+ error_info = re.sub(ansi_escape, '', error_info)
+
+ self.send_result["details"]["msg"] = error_info
return
out_split = stdout.split("\n")
--
2.33.0

View File

@ -4,7 +4,7 @@
Summary: System Inspection Framework Summary: System Inspection Framework
Name: sysSentry Name: sysSentry
Version: 1.0.2 Version: 1.0.2
Release: 8 Release: 9
License: Mulan PSL v2 License: Mulan PSL v2
Group: System Environment/Daemons Group: System Environment/Daemons
Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz
@ -18,6 +18,7 @@ Patch5: cpu_utility-and-cpu_patrol-must-be-an-integer.patch
Patch6: setting-parameters-must-be-integer.patch Patch6: setting-parameters-must-be-integer.patch
Patch7: param-must-be-integer.patch Patch7: param-must-be-integer.patch
Patch8: add-deleted-code-to-plugin-rasdaemon.patch Patch8: add-deleted-code-to-plugin-rasdaemon.patch
Patch9: Remove-ANSI-escape-sequences.patch
BuildRequires: cmake gcc-c++ BuildRequires: cmake gcc-c++
BuildRequires: python3 python3-setuptools BuildRequires: python3 python3-setuptools
@ -175,6 +176,12 @@ rm -rf %{buildroot}
%attr(0550,root,root) %{python3_sitelib}/syssentry/cpu_* %attr(0550,root,root) %{python3_sitelib}/syssentry/cpu_*
%changelog %changelog
* Mon Sep 02 2024 shixuantong <shixuantong1@huawei.com> - 1.0.2-9
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:Remove ANSI escape sequences
* Sat Aug 31 2024 shixuantong <shixuantong1@huawei.com> - 1.0.2-8 * Sat Aug 31 2024 shixuantong <shixuantong1@huawei.com> - 1.0.2-8
- Type:bugfix - Type:bugfix
- CVE:NA - CVE:NA