This commit is contained in:
2025-12-24 14:21:30 +07:00
parent e4a0134e78
commit 8930b894cb
+8 -5
View File
@@ -4,7 +4,7 @@ import logging
from zabbix_utils import ZabbixAPI from zabbix_utils import ZabbixAPI
from datetime import datetime, timedelta from datetime import datetime, timedelta
file_handler = logging.FileHandler(filename="tmp.log") # file_handler = logging.FileHandler(filename="tmp.log")
stdout_handler = logging.StreamHandler(stream=sys.stdout) stdout_handler = logging.StreamHandler(stream=sys.stdout)
handlers = [stdout_handler] handlers = [stdout_handler]
@@ -113,7 +113,7 @@ if __name__ == "__main__":
enabled_hosts = get_enabled_hosts_with_triggers() enabled_hosts = get_enabled_hosts_with_triggers()
if enabled_hosts: if enabled_hosts:
logging.info(f"Found {len(enabled_hosts)} enabled hosts with triggers:") logging.info(f"Found {len(enabled_hosts)} enabled hosts with triggers")
all_trigger_ids = [] all_trigger_ids = []
trigger_to_host = {} trigger_to_host = {}
@@ -137,19 +137,23 @@ if __name__ == "__main__":
# trigger_to_host[trigger["triggerid"]]["name"] = host["name"] # trigger_to_host[trigger["triggerid"]]["name"] = host["name"]
# print(hosts_objects) # print(hosts_objects)
logging.info(f"Found {len(all_trigger_ids)} triggers")
hosts_with_problem = [] hosts_with_problem = []
if all_trigger_ids: if all_trigger_ids:
# if hosts_objects: # if hosts_objects:
logger.info( logger.info(
f"Fetching current open problems for {len(all_trigger_ids)} enabled triggers..." f"Fetching current open problems for {len(all_trigger_ids)} enabled triggers..."
) )
# current_problems = get_current_problems_by_triggers_new(hosts_objects)
current_problems = get_current_problems_by_triggers(all_trigger_ids) current_problems = get_current_problems_by_triggers(all_trigger_ids)
logging.info(f"Current Open Problems ({len(current_problems)})") logging.info(f"Current Open Problems ({len(current_problems)})")
current_time = datetime.now() current_time = datetime.now()
time_threshold = current_time - timedelta(TRIGGER_DAY) time_threshold = current_time - timedelta(TRIGGER_DAY)
timestamp_threshold = int(time_threshold.timestamp()) timestamp_threshold = int(time_threshold.timestamp())
logging.info(f"Time Threshold: {timestamp_threshold}") logging.info(
f"Threshold: {time_threshold}, Timestamp: {timestamp_threshold}"
)
for problem in current_problems: for problem in current_problems:
logger.debug( logger.debug(
f"* {trigger_to_host[problem["objectid"]]['name']} PROBLEM: {problem['name']} (Severity: {problem['severity']}, Time: {problem['clock']})" f"* {trigger_to_host[problem["objectid"]]['name']} PROBLEM: {problem['name']} (Severity: {problem['severity']}, Time: {problem['clock']})"
@@ -163,7 +167,6 @@ if __name__ == "__main__":
logging.debug(f"Host with Problem: {hosts_with_problem}") logging.debug(f"Host with Problem: {hosts_with_problem}")
logging.info(f"Found {len(hosts_with_problem)} hosts with problem") logging.info(f"Found {len(hosts_with_problem)} hosts with problem")
# print(hosts_with_problem)
disable_hosts(hosts_with_problem) disable_hosts(hosts_with_problem)
else: else: