mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-17 18:24:14 +02:00
🚀 lidarr postgresql
This commit is contained in:
106
kubernetes/apps/default/lidarr/app/scripts/pushover-notify.sh
Executable file
106
kubernetes/apps/default/lidarr/app/scripts/pushover-notify.sh
Executable file
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PUSHOVER_DEBUG="${PUSHOVER_DEBUG:-"true"}"
|
||||
# kubectl port-forward service/lidarr -n default 7878:7878
|
||||
# export PUSHOVER_STARR_INSTANCE_NAME=Lidarr;
|
||||
# export PUSHOVER_APP_URL="";
|
||||
# export PUSHOVER_API_TOKEN="";
|
||||
# export PUSHOVER_USER_KEY="";
|
||||
# export lidarr_eventtype=Download;
|
||||
# ./notify.sh
|
||||
|
||||
CONFIG_FILE="/config/config.xml" && [[ "${PUSHOVER_DEBUG}" == "true" ]] && CONFIG_FILE="config.xml"
|
||||
ERRORS=()
|
||||
|
||||
#
|
||||
# Discoverable variables
|
||||
#
|
||||
# shellcheck disable=SC2086
|
||||
PUSHOVER_STARR_PORT="$(xmlstarlet sel -t -v "//Port" -nl ${CONFIG_FILE})" && [[ -z "${PUSHOVER_STARR_PORT}" ]] && ERRORS+=("PUSHOVER_STARR_PORT not defined")
|
||||
PUSHOVER_STARR_APIKEY="$(xmlstarlet sel -t -v "//ApiKey" -nl ${CONFIG_FILE})" && [[ -z "${PUSHOVER_STARR_APIKEY}" ]] && ERRORS+=("PUSHOVER_STARR_APIKEY not defined")
|
||||
PUSHOVER_STARR_INSTANCE_NAME="$(xmlstarlet sel -t -v "//InstanceName" -nl ${CONFIG_FILE})" && [[ -z "${PUSHOVER_STARR_INSTANCE_NAME}" ]] && ERRORS+=("PUSHOVER_STARR_INSTANCE_NAME not defined")
|
||||
|
||||
#
|
||||
# Configurable variables
|
||||
#
|
||||
# Required
|
||||
PUSHOVER_APP_URL="${PUSHOVER_APP_URL:-}" && [[ -z "${PUSHOVER_APP_URL}" ]] && ERRORS+=("PUSHOVER_APP_URL not defined")
|
||||
PUSHOVER_USER_KEY="${PUSHOVER_USER_KEY:-}" && [[ -z "${PUSHOVER_USER_KEY}" ]] && ERRORS+=("PUSHOVER_USER_KEY not defined")
|
||||
PUSHOVER_API_TOKEN="${PUSHOVER_API_TOKEN:-}" && [[ -z "${PUSHOVER_API_TOKEN}" ]] && ERRORS+=("PUSHOVER_API_TOKEN not defined")
|
||||
# Optional
|
||||
PUSHOVER_DEVICE="${PUSHOVER_DEVICE:-}"
|
||||
PUSHOVER_PRIORITY="${PUSHOVER_PRIORITY:-"-2"}"
|
||||
PUSHOVER_SOUND="${PUSHOVER_SOUND:-}"
|
||||
|
||||
#
|
||||
# Print defined variables
|
||||
#
|
||||
for pushover_vars in ${!PUSHOVER_*}
|
||||
do
|
||||
declare -n var="${pushover_vars}"
|
||||
[[ -n "${var}" && "${PUSHOVER_DEBUG}" = "true" ]] && printf "%s - %s=%s\n" "$(date)" "${!var}" "${var}"
|
||||
done
|
||||
|
||||
#
|
||||
# Validate required variables are set
|
||||
#
|
||||
if [ ${#ERRORS[@]} -gt 0 ]; then
|
||||
for err in "${ERRORS[@]}"; do printf "%s - Undefined variable %s\n" "$(date)" "${err}" >&2; done
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Send Notification on Test
|
||||
#
|
||||
if [[ "${lidarr_eventtype:-}" == "Test" ]]; then
|
||||
PUSHOVER_TITLE="Test Notification"
|
||||
PUSHOVER_MESSAGE="Howdy this is a test notification from ${PUSHOVER_STARR_INSTANCE_NAME}"
|
||||
fi
|
||||
|
||||
#
|
||||
# Send notification on Download or Upgrade
|
||||
#
|
||||
if [[ "${lidarr_eventtype:-}" == "Download" ]]; then
|
||||
printf -v PUSHOVER_TITLE "%s (%s) [%s]" \
|
||||
"${lidarr_artist_name:-"Michael Jackson"}" \
|
||||
"${lidarr_album_releasedate:-"1982"}" \
|
||||
"${lidarr_album_title:-"Thriller"}"
|
||||
# "${lidarr_trackfile_quality:-""}"
|
||||
printf -v PUSHOVER_MESSAGE "%s" \
|
||||
"$(curl --silent --header "X-Api-Key:${PUSHOVER_STARR_APIKEY}" "http://localhost:${PUSHOVER_STARR_PORT}/api/v1/album/${lidarr_album_id:-"2619"}" \
|
||||
| jq -r ".overview")"
|
||||
printf -v PUSHOVER_URL "https://%s/album/%s" \
|
||||
"${PUSHOVER_APP_URL}" \
|
||||
"${lidarr_artist_mbid:-"122"}"
|
||||
printf -v PUSHOVER_URL_TITLE "View album in %s" \
|
||||
"${PUSHOVER_STARR_INSTANCE_NAME}"
|
||||
fi
|
||||
|
||||
notification=$(jq -n \
|
||||
--arg token "${PUSHOVER_API_TOKEN}" \
|
||||
--arg user "${PUSHOVER_USER_KEY}" \
|
||||
--arg title "${PUSHOVER_TITLE}" \
|
||||
--arg message "${PUSHOVER_MESSAGE:-"Unable to obtain album details"}" \
|
||||
--arg url "${PUSHOVER_URL}" \
|
||||
--arg url_title "${PUSHOVER_URL_TITLE}" \
|
||||
--arg priority "${PUSHOVER_PRIORITY}" \
|
||||
--arg sound "${PUSHOVER_SOUND}" \
|
||||
--arg device "${PUSHOVER_DEVICE}" \
|
||||
'{token: $token, user: $user, title: $title, message: $message, url: $url, url_title: $url_title, priority: $priority, sound: $sound, device: $device}' \
|
||||
)
|
||||
|
||||
status_code=$(curl \
|
||||
--write-out "%{http_code}" \
|
||||
--silent \
|
||||
--output /dev/null \
|
||||
--header "Content-Type: application/json" \
|
||||
--data-binary "${notification}" \
|
||||
--request POST "https://api.pushover.net/1/messages.json" \
|
||||
)
|
||||
|
||||
if [[ "${status_code}" -ne 200 ]] ; then
|
||||
printf "%s - Unable to send notification with status code %s and payload: %s\n" "$(date)" "${status_code}" "$(echo "${notification}" | jq -c)" >&2
|
||||
exit 1
|
||||
else
|
||||
printf "%s - Sent notification with status code %s and payload: %s\n" "$(date)" "${status_code}" "$(echo "${notification}" | jq -c)"
|
||||
fi
|
Reference in New Issue
Block a user