Compare commits

..

No commits in common. "d0e91f5259bb50854fd20b9cc77a04a10a5223d9" and "486539dbb3a573bd90044f6f85d813c091bdc1fa" have entirely different histories.

View File

@ -1266,7 +1266,7 @@ def get_zabbix_triggers(group_id):
# Получение активных проблем для этих хостов
problems = zapi.problem.get(
output=["eventid", "name", "severity", "clock", "objectid"],
output=["eventid", "name", "severity", "clock"],
hostids=host_ids,
suppressed=0,
acknowledged=0,
@ -1278,20 +1278,6 @@ def get_zabbix_triggers(group_id):
telebot.logger.info(f"No active problems found for group {group_id}")
return []
# Получение триггеров и их связи с хостами
trigger_ids = [problem["objectid"] for problem in problems]
triggers = zapi.trigger.get(
triggerids=trigger_ids,
output=["triggerid", "description"],
selectHosts=["hostid"]
)
# Создаем карту триггеров к хостам
trigger_to_host_map = {}
for trigger in triggers:
if "hosts" in trigger and trigger["hosts"]:
trigger_to_host_map[trigger["triggerid"]] = trigger["hosts"][0]["hostid"]
# Получение IP-адресов хостов
host_interfaces = zapi.hostinterface.get(
hostids=host_ids,
@ -1299,19 +1285,6 @@ def get_zabbix_triggers(group_id):
)
host_ip_map = {iface["hostid"]: iface["ip"] for iface in host_interfaces}
# print(host_ip_map)
# Получение itemid для триггеров на основе их описания
item_map = {}
for host in active_hosts:
host_id = host["hostid"]
items = zapi.item.get(
hostids=host_id,
output=["itemid", "name"]
)
for item in items:
item_map[(host_id, item["name"])] = item["itemid"]
moscow_tz = timezone('Europe/Moscow')
severity_map = {'4': 'HIGH', '5': 'DISASTER'}
priority_map = {'4': '⚠️', '5': '⛔️'}
@ -1326,16 +1299,12 @@ def get_zabbix_triggers(group_id):
priority = priority_map.get(problem['severity'], '')
description = problem.get('name', 'Нет описания')
# Получаем hostid через триггер
trigger_id = problem.get("objectid")
host_id = trigger_to_host_map.get(trigger_id, "Неизвестный хост")
host_ip = host_ip_map.get(host_id, "Неизвестный IP")
# Получаем хост из описания (или по-другому, если известно)
host = extract_host_from_name(description)
description = escape_telegram_chars(description)
host_ip = host_ip_map.get(problem.get("hostid"), "Неизвестный IP")
message = (f"{priority} {host} ({host_ip})\n"
message = (f"<b>{priority} Host</b>: {host}\n"
f"<b>IP</b>: {host_ip}\n"
f"<b>Описание</b>: {description}\n"
f"<b>Критичность</b>: {severity}\n"
f"<b>Время создания</b>: {event_time_formatted}")