Projects
Eulaceura:Factory
sysSentry
_service:obs_scm:precise-alarm-query-time.patch
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:precise-alarm-query-time.patch of Package sysSentry
From 7fa9e80531bb3d4fa587e5fb7a99e3af59feda7e Mon Sep 17 00:00:00 2001 From: jinsaihang <jinsaihang@h-partners.com> Date: Sat, 12 Oct 2024 16:51:37 +0800 Subject: [PATCH] precise alarm query time Signed-off-by: jinsaihang <jinsaihang@h-partners.com> --- sysSentry-1.0.2/src/python/syssentry/alarm.py | 25 +++++++++++++++++-- .../src/python/syssentry/load_mods.py | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/python/syssentry/alarm.py b/src/python/syssentry/alarm.py index 43c1065..d012901 100644 --- a/src/python/syssentry/alarm.py +++ b/src/python/syssentry/alarm.py @@ -76,6 +76,18 @@ def update_alarm_list(alarm_info: Xalarm): finally: alarm_list_lock.release() +def check_alarm_id_if_number(alarm_id): + if isinstance(alarm_id, int): + return True + else: + return False + +def check_alarm_clear_time_if_positive_integer(alarm_clear_time): + if isinstance(alarm_clear_time, int) and alarm_clear_time > 0: + return True + else: + return False + def alarm_register(): logging.debug(f"alarm_register: enter") # 初始化告警ID映射字典、告警老化时间字典 @@ -84,10 +96,16 @@ def alarm_register(): logging.info(f"alarm_register: {task_name} is registered") task = TasksMap.tasks_dict[task_type][task_name] alarm_id = task.alarm_id + if not check_alarm_id_if_number(alarm_id): + logging.warnning(f"Invalid alarm_id {alarm_id}: ignore {task_name} alarm") + continue if alarm_id < MIN_ALARM_ID or alarm_id > MAX_ALARM_ID: logging.warnning(f"Invalid alarm_id {alarm_id}: ignore {task_name} alarm") continue alarm_clear_time = task.alarm_clear_time + if not check_alarm_clear_time_if_positive_integer(alarm_clear_time): + logging.warnning(f"Invalid alarm_clear_time {alarm_clear_time}: ignore {task_name} alarm") + continue try: alarm_clear_time = int(alarm_clear_time) if alarm_clear_time <= 0: @@ -119,6 +137,9 @@ def get_alarm_result(task_name: str, time_range: int, detailed: bool) -> List[Di logging.debug("task_name does not exist") return [] alarm_id = task_alarm_id_dict[task_name] + clear_time = alarm_id_clear_time_dict[alarm_id] + if clear_time < int(time_range): + return [] if alarm_id not in alarm_list_dict: logging.debug("alarm_id does not exist") return [] @@ -126,10 +147,10 @@ def get_alarm_result(task_name: str, time_range: int, detailed: bool) -> List[Di logging.debug(f"get_alarm_result: alarm_list of {alarm_id} has {len(alarm_list)} elements") # clear alarm_info older than clear time threshold stop_index = -1 - timestamp = int(datetime.now().timestamp()) + timestamp = datetime.now().timestamp() for i in range(len(alarm_list)): logging.debug(f"timestamp, alarm_list[{i}].timestamp: {timestamp}, {xalarm_gettime(alarm_list[i])}") - if timestamp - (xalarm_gettime(alarm_list[i])) / MILLISECONDS_UNIT_SECONDS > int(time_range): + if timestamp - (xalarm_gettime(alarm_list[i])) / MILLISECONDS_UNIT_SECONDS > time_range: stop_index = i break if stop_index >= 0: diff --git a/src/python/syssentry/load_mods.py b/src/python/syssentry/load_mods.py index 7daf17d..f74f165 100644 --- a/src/python/syssentry/load_mods.py +++ b/src/python/syssentry/load_mods.py @@ -203,7 +203,8 @@ def parse_mod_conf(mod_name, mod_conf): if not (MIN_ALARM_ID <= task.alarm_id <= MAX_ALARM_ID): raise ValueError("Invalid alarm_id") except ValueError: - logging.warning("Invalid alarm_id") + task.alarm_id = mod_conf.get(CONF_TASK, CONF_ALARM_ID) + task.alarm_clear_time = mod_conf.get(CONF_TASK, CONF_ALARM_CLEAR_TIME) except configparser.NoOptionError: logging.warning("Unset alarm_clear_time, use 15s as default") -- 2.27.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2