diff --git a/main.py b/disable_host_by_trigger.py similarity index 96% rename from main.py rename to disable_host_by_trigger.py index 3963df8..eb8749f 100644 --- a/main.py +++ b/disable_host_by_trigger.py @@ -4,7 +4,7 @@ import logging from zabbix_utils import ZabbixAPI 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) handlers = [stdout_handler] @@ -113,7 +113,7 @@ if __name__ == "__main__": enabled_hosts = get_enabled_hosts_with_triggers() 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 = [] trigger_to_host = {} @@ -137,19 +137,23 @@ if __name__ == "__main__": # trigger_to_host[trigger["triggerid"]]["name"] = host["name"] # print(hosts_objects) + logging.info(f"Found {len(all_trigger_ids)} triggers") hosts_with_problem = [] if all_trigger_ids: # if hosts_objects: logger.info( 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) logging.info(f"Current Open Problems ({len(current_problems)})") + current_time = datetime.now() time_threshold = current_time - timedelta(TRIGGER_DAY) 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: logger.debug( 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.info(f"Found {len(hosts_with_problem)} hosts with problem") - # print(hosts_with_problem) disable_hosts(hosts_with_problem) else: