#!/usr/bin/env bash set -euo pipefail # Daily LubeLogger reminder digest -> ntfy 'garage' topic. # Reads per-vehicle reminder urgency counts from LubeLogger's API and posts a # summary ONLY when something is due/overdue (PastDue + VeryUrgent + Urgent). # Runs on ansible-control (.190) via lubelogger-reminders.timer. # Shape mirrors the gluetun vpn-tunnel-probe (oneshot + timer, set -euo pipefail). source /etc/lubelogger-reminders.env # LUBELOGGER_URL LUBELOGGER_USER LUBELOGGER_PASS NTFY_URL if ! resp=$(curl -sf --max-time 20 -u "${LUBELOGGER_USER}:${LUBELOGGER_PASS}" "${LUBELOGGER_URL}/api/vehicle/info"); then logger -t lubelogger-reminders "ERROR: LubeLogger API query failed" curl -sf --max-time 15 -H "Priority: high" -H "Tags: warning" \ -H "Title: LubeLogger reminder probe failed" \ -d "Could not query ${LUBELOGGER_URL}/api/vehicle/info" "$NTFY_URL" || true exit 1 fi total=$(printf '%s' "$resp" | jq '[.[] | (.PastDueReminderCount + .VeryUrgentReminderCount + .UrgentReminderCount)] | add // 0') if [ "${total:-0}" -gt 0 ]; then body=$(printf '%s' "$resp" | jq -r ' .[] | (.PastDueReminderCount + .VeryUrgentReminderCount + .UrgentReminderCount) as $due | select($due > 0) | "• \(.VehicleData.Year) \(.VehicleData.Make) \(.VehicleData.Model): " + "\(.PastDueReminderCount) past-due, \(.VeryUrgentReminderCount) very-urgent, \(.UrgentReminderCount) urgent"') curl -sf --max-time 15 \ -H "Title: Vehicle maintenance due (${total})" \ -H "Tags: wrench" -H "Priority: default" \ -d "$body" "$NTFY_URL" || true logger -t lubelogger-reminders "posted ${total} due reminder(s) to ntfy garage" else logger -t lubelogger-reminders "no due/overdue reminders" fi