auanasgheps / snapraid-aio-script

The definitive all-in-one SnapRAID script on Linux. Diff, sync, scrub are things of the past. Manage SnapRAID and much, much more!
GNU General Public License v3.0
220 stars 34 forks source link

[ENHANCEMENT]: call URL only if everything is ok (for Uptime Kuma) #98

Open andreapx opened 2 months ago

andreapx commented 2 months ago

I use Uptime Kuma that alerts me only if anything is wrong (a service is down, a backup fails, and so on). What about integrate Uptime Kuma in the script (or just call an URL only when there are no errors/workings)? Thanks!

auanasgheps commented 2 months ago

I could definitely integrate Uptime Kuma. Seems to be a popular service. (I don't know or use it, for this I use Healthchecks.io)

In the meantime, you can use the "hook notification" feature. It will do the job just fine.

https://github.com/auanasgheps/snapraid-aio-script/blob/e2377893e4923703325764cc5d759aa81cf11830/script-config.sh#L46C1-L55C21

andreapx commented 2 months ago

I could definitely integrate Uptime Kuma. Seems to be a popular service. (I don't know or use it, for this I use Healthchecks.io)

In the meantime, you can use the "hook notification" feature. It will do the job just fine.

https://github.com/auanasgheps/snapraid-aio-script/blob/e2377893e4923703325764cc5d759aa81cf11830/script-config.sh#L46C1-L55C21

I've tried with the hook notification putting there the URL, but it doesn't work. I've tried to create a bash script that by itself work, but when called from this script it fails saying that the URL is not valid. I'm not a developer and I'm not very familiar with scripts either, this has been created by Proximity AI.

#!/bin/bash

# Check if the required number of arguments is provided
if [ $# -ne 2 ]; then
  echo "Usage: $0 <param1> <param2>"
  exit 1
fi

# Store the command line arguments in variables
param1=$1
echo $param1
echo "**************************************************************************"
param2=$2
echo $param2

# URL encode the parameter values
encoded_param1=$(echo "$param1" | sed 's/ /%20/g' | sed 's/!/%21/g' | sed 's/"/%22/g' | sed 's/#/%23/g' | sed 's/\$/%24/g' | sed 's/\&/%26/g' | sed "s/'/%27/g" | sed 's/(/%28/g' | sed 's/)/%29/g' | sed 's/:/%3A/g' | sed 's/;/%3B/g' | sed 's/</%3C/g' | sed 's/=/%3D/g' | sed 's/>/%3E/g' | sed 's/?/%3F/g' | sed 's/@/%40/g' | sed 's/\[/%5B/g' | sed 's/\\/%5C/g' | sed 's/\]/%5D/g' | sed 's/\^/%5E/g' | sed 's/_/%5F/g' | sed 's/`/%60/g' | sed 's/{/%7B/g' | sed 's/|/%7C/g' | sed 's/}/%7D/g' | sed 's/~/%7E/g')
encoded_param2=$(echo "$param2" | sed 's/ /%20/g' | sed 's/!/%21/g' | sed 's/"/%22/g' | sed 's/#/%23/g' | sed 's/\$/%24/g' | sed 's/\&/%26/g' | sed "s/'/%27/g" | sed 's/(/%28/g' | sed 's/)/%29/g' | sed 's/:/%3A/g' | sed 's/;/%3B/g' | sed 's/</%3C/g' | sed 's/=/%3D/g' | sed 's/>/%3E/g' | sed 's/?/%3F/g' | sed 's/@/%40/g' | sed 's/\[/%5B/g' | sed 's/\\/%5C/g' | sed 's/\]/%5D/g' | sed 's/\^/%5E/g' | sed 's/_/%5F/g' | sed 's/`/%60/g' | sed 's/{/%7B/g' | sed 's/|/%7C/g' | sed 's/}/%7D/g' | sed 's/~/%7E/g')

encoded_param1=$(echo -n "$param1" | jq -sRr @uri)
encoded_param2=$(echo -n "$param2" | jq -sRr @uri)

echo " "
echo encoded_param1
echo "------------------------------"
echo encoded_param2
# Construct the URL with the encoded parameters
url="https://xxxxxxxxx.com/webhook-SnapRAID-script_bf2f4u9-1842FQ=gbu3&b3c8r136ifb683?param1=$encoded_param1&param2=$encoded_param2"

# Send the GET request using curl
response=$(curl -s -X GET "$url")

# Print the response
echo "Response: $response"