ses-monitor/scripts/zbx_get.py
Maksim Totmin 7394b14b52 Initial commit: ses-monitor watchdog for SES
Универсальный watchdog-мониторинг Service Engine Server (SES):
- Liveness-проверки (API, лицензия, роботы)
- Диалоговые сценарии из YAML с агрегацией в 6 фиксированных Zabbix-метрик
- Доставка: zabbix_sender (active push) или UserParameter (пассивный опрос)
- Поддержка Python 3.7+, Zabbix 5.0
2026-06-19 20:26:26 +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())