diff --git a/gotify.sh b/gotify.sh new file mode 100644 index 0000000..ff9baa3 --- /dev/null +++ b/gotify.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +token_gotify= + +dotenv () { + set -a + # shellcheck disable=SC1091 + [ -f ".env" ] && . ".env" || echo -e "${red}\nNo .env file found ! No token for gotify.${reset}" + set +a +} + +send_gotify_notification() { + now=$(date +"%d-%m-%Y %T") + gotify_server="https://gotify.maboiteverte.fr" + TITLE="IP has changed on $host" + MESSAGE="**L'IP externe a changé:**\n\n - ancienne IP: $old_ip_externe\n - **nouvelle IP: $ip_externe**\n\n [^]: $now\n" + PRIORITY=8 + URL="$gotify_server/message?token=$token_gotify&?format=markdown" + + echo -e "Sending notification to $gotify_server ..." + + curl -L -S -s --data '{"message": "'"${MESSAGE}"'", "title": "'"${TITLE}"'", "priority":'"${PRIORITY}"', "extras": {"client::display": {"contentType": "text/markdown"}}}' -H 'Content-Type: application/json' "$URL" > /dev/null + + [ $? -eq 0 ] && echo -e "${greenbold}Gotify notification sent successfully !${reset}" || echo -e "${redbold}error sending Gotify notification !${reset}" +} + +dotenv + +send_gotify_notification \ No newline at end of file