ses-monitor/scripts/zbx_get.py
Maksim Totmin 8dca7eb46b Initial commit: SES Monitor
Watchdog-демон для непрерывного мониторинга SES.
- Liveness-проверки API, лицензии, списка роботов
- Диалоговые сценарии из YAML с агрегацией в 6 фиксированных Zabbix-метрик
- Доставка: zabbix_sender (push) или UserParameter (poll)
- Hot-reload сценариев без перезапуска
2026-06-19 21:04:05 +07:00

40 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Скрипт для Zabbix UserParameter.
Возвращает JSON со всеми метриками ses-monitor.
Используется как один UserParameter: ses.metrics
Настройка Zabbix агента:
UserParameter=ses.metrics,/opt/ses-monitor/scripts/zbx_get.py
В шаблоне Zabbix создаётся master-элемент ses.metrics (тип: Zabbix агент,
формат: Текст), а все остальные ses.* элементы — зависимые (dependent) с
препроцессингом JSONPath.
"""
import json
import sys
METRICS_FILE = "/var/tmp/ses_monitor/metrics.json"
def main() -> int:
try:
with open(METRICS_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
except FileNotFoundError:
# Файла ещё нет — возвращаем пустой JSON
print("{}")
return 0
except json.JSONDecodeError:
print("{}")
return 0
print(json.dumps(data, ensure_ascii=False))
return 0
if __name__ == "__main__":
sys.exit(main())