Files

30 lines
767 B
Bash

#!/bin/bash
# Publish a notification to local ntfy (https://ntfy.nomadro.com).
# Usage: notify-ntfy.sh "title" "message" [priority] [tags] [topic]
set -euo pipefail
CONF="${NOMADRO_NTFY_CONF:-/etc/nomadro/ntfy.env}"
# shellcheck disable=SC1090
[[ -f "$CONF" ]] && source "$CONF"
TITLE="${1:-Alert}"
MESSAGE="${2:-}"
PRIORITY="${3:-default}"
TAGS="${4:-warning}"
TOPIC="${5:-${NTFY_TOPIC:-server-alerts}}"
BASE_URL="${NTFY_BASE_URL:-https://ntfy.nomadro.com}"
TOKEN="${NTFY_TOKEN:-}"
if [[ -z "$TOKEN" ]]; then
echo "notify-ntfy: NTFY_TOKEN missing in $CONF" >&2
exit 1
fi
curl -fsS \
-H "Authorization: Bearer ${TOKEN}" \
-H "Title: ${TITLE}" \
-H "Priority: ${PRIORITY}" \
-H "Tags: ${TAGS}" \
-d "$MESSAGE" \
"${BASE_URL%/}/${TOPIC}" >/dev/null