From 787bf7ab66aad1d064bbd3da6d0fda0ef470e87d Mon Sep 17 00:00:00 2001 From: hubin Date: Wed, 9 Oct 2024 16:29:49 +0800 Subject: [PATCH] fix get_alarm length and timestamp Signed-off-by: hubin --- add-detail-time.patch | 32 ++++++++++++++++++++++ change-alarm-length.patch | 56 +++++++++++++++++++++++++++++++++++++++ sysSentry.spec | 10 ++++++- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 add-detail-time.patch create mode 100644 change-alarm-length.patch diff --git a/add-detail-time.patch b/add-detail-time.patch new file mode 100644 index 0000000..8e23452 --- /dev/null +++ b/add-detail-time.patch @@ -0,0 +1,32 @@ +From 9ecd4c2c9c9f9578f5ec4780360dc67b182b384a Mon Sep 17 00:00:00 2001 +From: jinsaihang +Date: Wed, 9 Oct 2024 08:09:04 +0000 +Subject: [PATCH 2/2] add detail time + +Signed-off-by: jinsaihang +--- + src/python/syssentry/alarm.py | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/python/syssentry/alarm.py b/src/python/syssentry/alarm.py +index 74a2716..d5337d3 100644 +--- a/src/python/syssentry/alarm.py ++++ b/src/python/syssentry/alarm.py +@@ -118,11 +118,13 @@ def get_alarm_result(task_name: str, time_range: int, detailed: bool) -> List[Di + logging.debug(f"get_alarm_result: final alarm_list of {alarm_id} has {len(alarm_list)} elements") + + def xalarm_to_dict(alarm_info: Xalarm) -> dict: ++ timestamp = alarm_info.timetamp.tv_sec + alarm_info.timetamp.tv_usec / 1000000 ++ dt_object = datetime.fromtimestamp(int(timestamp)) + return { + 'alarm_id': xalarm_getid(alarm_info), + 'alarm_type': xalarm_gettype(alarm_info), + 'alarm_level': xalarm_getlevel(alarm_info), +- 'timetamp': xalarm_gettime(alarm_info), ++ 'timestamp': dt_object.strftime("%Y-%m-%d %H:%M:%S"), + 'msg1': xalarm_getdesc(alarm_info) + } + +-- +2.27.0 + diff --git a/change-alarm-length.patch b/change-alarm-length.patch new file mode 100644 index 0000000..27c49ed --- /dev/null +++ b/change-alarm-length.patch @@ -0,0 +1,56 @@ +From 67439c0040b1fb0614ac009bf53062e9ec2880aa Mon Sep 17 00:00:00 2001 +From: jinsaihang +Date: Wed, 9 Oct 2024 11:55:35 +0800 +Subject: [PATCH 1/2] change alarm length + +Signed-off-by: jinsaihang +--- + src/python/syssentry/sentryctl | 3 +++ + src/python/syssentry/syssentry.py | 3 +++ + 2 files changed, 6 insertions(+) + +diff --git a/src/python/syssentry/sentryctl b/src/python/syssentry/sentryctl +index 675c17a..3de93d0 100644 +--- a/src/python/syssentry/sentryctl ++++ b/src/python/syssentry/sentryctl +@@ -25,6 +25,7 @@ MAX_PARAM_LENGTH = 256 + + RESULT_MSG_DATA_LEN = 4 + CTL_MSG_LEN_LEN = 3 ++ALARM_MSG_DATA_LEN = 6 + DEFAULT_ALARM_TIME_RANGE = 10 + + def status_output_format(res_data): +@@ -173,6 +174,8 @@ if __name__ == '__main__': + request_message = json.dumps(req_msg_struct) + if client_args.cmd_type == 'get_result': + result_message = client_send_and_recv(request_message, RESULT_MSG_DATA_LEN) ++ elif client_args.cmd_type == 'get_alarm': ++ result_message = client_send_and_recv(request_message, ALARM_MSG_DATA_LEN) + else: + result_message = client_send_and_recv(request_message, CTL_MSG_LEN_LEN) + if not result_message: +diff --git a/src/python/syssentry/syssentry.py b/src/python/syssentry/syssentry.py +index c2dee85..ea09095 100644 +--- a/src/python/syssentry/syssentry.py ++++ b/src/python/syssentry/syssentry.py +@@ -56,6 +56,7 @@ CTL_MSG_MAGIC_LEN = 3 + CTL_MSG_LEN_LEN = 3 + CTL_MAGIC = "CTL" + RES_MAGIC = "RES" ++ALARM_MSG_DATA_LEN = 6 + + CTL_LISTEN_QUEUE_LEN = 5 + SERVER_EPOLL_TIMEOUT = 0.3 +@@ -256,6 +257,8 @@ def server_recv(server_socket: socket.socket): + res_head = RES_MAGIC + if cmd_type == "get_result": + res_data_len = str(len(res_data)).zfill(RESULT_MSG_HEAD_LEN - RESULT_MSG_MAGIC_LEN) ++ elif cmd_type == "get_alarm": ++ res_data_len = str(len(res_data)).zfill(ALARM_MSG_DATA_LEN) + else: + res_data_len = str(len(res_data)).zfill(CTL_MSG_MAGIC_LEN) + res_head += res_data_len +-- +2.27.0 + diff --git a/sysSentry.spec b/sysSentry.spec index 2bc8093..7b57f0d 100644 --- a/sysSentry.spec +++ b/sysSentry.spec @@ -4,7 +4,7 @@ Summary: System Inspection Framework Name: sysSentry Version: 1.0.2 -Release: 24 +Release: 25 License: Mulan PSL v2 Group: System Environment/Daemons Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz @@ -35,6 +35,8 @@ Patch22: add-sentryctl-get_alarm-module_name-s-time_range-d.patch Patch23: fix-python-3.7-not-support-list-bool-type.patch Patch24: avg_block_io-send-alarm-to-xalarmd.patch Patch25: update-log-when-it-is-not-lock-collect.patch +Patch26: change-alarm-length.patch +Patch27: add-detail-time.patch BuildRequires: cmake gcc-c++ BuildRequires: python3 python3-setuptools @@ -287,6 +289,12 @@ rm -rf %{buildroot} %attr(0550,root,root) %{python3_sitelib}/sentryPlugins/ai_block_io %changelog +* Wed Oct 9 2024 hubin - 1.0.2-25 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:fix get_alarm length and timestamp + * Wed Oct 9 2024 zhuofeng - 1.0.2-24 - Type:bugfix - CVE:NA -- Gitee