#!/usr/bin/env bash
set -u

echo "NICE Monitoring status"
echo "======================"
if [[ -r /etc/nice-monitoring-release ]]; then
    cat /etc/nice-monitoring-release
fi
echo

for svc in postgresql16 php-fpm nginx zabbix-server zabbix-agent2 zabbix-web-service; do
    printf '%-24s ' "${svc}.service"
    systemctl is-active "${svc}.service" 2>/dev/null || true
done

echo
if command -v /usr/pgsql/16/bin/pg_isready >/dev/null 2>&1; then
    /usr/pgsql/16/bin/pg_isready -h 127.0.0.1 -p 5432 || true
fi

echo
echo -n "Zabbix API: "
curl -ksS --max-time 3 https://127.0.0.1/api_jsonrpc.php \
    -H 'Content-Type: application/json-rpc' \
    --data '{"jsonrpc":"2.0","method":"apiinfo.version","params":{},"id":1}' \
    2>/dev/null || echo "unavailable"
echo

if command -v zabbix_get >/dev/null 2>&1; then
    echo -n "Local Agent2 ping: "
    zabbix_get -s 127.0.0.1 -k agent.ping 2>/dev/null || echo "unavailable"
fi
