From 382c68e39573b9850efecf19e997af47257e6762 Mon Sep 17 00:00:00 2001 From: RandomUser345 Date: Thu, 1 Sep 2022 13:17:18 +0200 Subject: [PATCH] introduce webhook to be posted to when fatal error happens --- README.md | 1 + root/scripts/audio.sh | 14 +++++++++++++- root/scripts/video.sh | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b094f1a..28df7d3 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ Container images are configured using parameters passed at runtime (such as thos | `-e plexUrl=http://x.x.x.x:32400` | ONLY used if PlexNotify.bash is used...| | `-e plexToken=` | ONLY used if PlexNotify.bash is used... | | `-e youtubeSubtitleLanguage=en` | Desired Language Code :: For guidence, please see yt-dlp documentation. +| `-e webHook=https://myhook.mydomain.com` | POST's to this URL on error events which prevent the script from working. Content is JSON `{"event":"eventtype", "message":"eventmessage"}` ## Usage diff --git a/root/scripts/audio.sh b/root/scripts/audio.sh index f3db08e..9b63101 100644 --- a/root/scripts/audio.sh +++ b/root/scripts/audio.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -scriptVersion="1.0.240" +scriptVersion="1.0.241" if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" if [ "$lidarrUrlBase" = "null" ]; then @@ -161,6 +161,7 @@ DownloadFormat () { log "ERROR :: Invalid audioFormat and audioBitrate options set..." log "ERROR :: Change audioBitrate to a low, high, or lossless..." log "ERROR :: Exiting..." + NotifyWebhook "Error" "Invalid audioFormat and audioBitrate options set" exit fi else @@ -168,6 +169,7 @@ DownloadFormat () { log "ERROR :: Invalid audioFormat and audioBitrate options set..." log "ERROR :: Change audioBitrate to a desired bitrate number, example: 192..." log "ERROR :: Exiting..." + NotifyWebhook "Error" "Invalid audioFormat and audioBitrate options set" exit else tidal-dl -q HiFi @@ -374,6 +376,7 @@ TidalClientTest () { log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..." log "TIDAL :: ERROR :: Exiting..." rm -rf $downloadPath/incomplete/* + NotifyWebhook "Error" "TIDAL not authenticated but configured" exit else rm -rf $downloadPath/incomplete/* @@ -803,6 +806,7 @@ DeezerClientTest () { log "DEEZER :: ERROR :: Try updating your ARL Token to possibly resolve the issue..." log "DEEZER :: ERROR :: Exiting..." rm -rf $downloadPath/incomplete/* + NotifyWebhook "Error" "DEEZER not authenticated but configured" exit else rm -rf $downloadPath/incomplete/* @@ -870,6 +874,7 @@ LidarrRootFolderCheck () { log "ERROR :: No root folder found" log "ERROR :: Configure root folder in Lidarr to continue..." log "ERROR :: Exiting..." + NotifyWebhook "Error" "No root folder found" exit fi } @@ -1892,6 +1897,13 @@ audioFlacVerification () { verifiedFlacFile=$(flac --totally-silent -t "$1"; echo $?) } +NotifyWebhook () { + if [ "$webHook" ] + then + curl -X POST "{$webHook}" -H 'Content-Type: application/json' -d '{"event":"'"$1"'", "message":"'"$2"'"}' + fi +} + Configuration if [ "$configureLidarrWithOptimalSettings" = "true" ]; then diff --git a/root/scripts/video.sh b/root/scripts/video.sh index 38c104e..0fc7adc 100644 --- a/root/scripts/video.sh +++ b/root/scripts/video.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -scriptVersion="1.0.037" +scriptVersion="1.0.038" if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" @@ -199,6 +199,7 @@ TidalClientTest () { log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..." log "TIDAL :: ERROR :: Exiting..." rm -rf $downloadPath/incomplete/* + NotifyWebhook "Error" "TIDAL not authenticated but configured" exit else rm -rf $downloadPath/incomplete/* @@ -550,6 +551,13 @@ AddFeaturedVideoArtists () { } +NotifyWebhook () { + if [ "$webHook" ] + then + curl -X POST "{$webHook}" -H 'Content-Type: application/json' -d '{"event":"'"$1"'", "message":"'"$2"'"}' + fi +} + Configuration TidalClientSetup AddFeaturedVideoArtists