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

