alert_ifttt.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # LinuxGSM alert_ifttt.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends IFTTT alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(
  9. cat << EOF
  10. {
  11. "value1": "${selfname}",
  12. "value2": "${alerttitle}",
  13. "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n
  14. EOF
  15. )
  16. if [ -n "${querytype}" ]; then
  17. json+=$(
  18. cat << EOF
  19. Is my Game Server Online?\nhttps://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}\n\n
  20. EOF
  21. )
  22. fi
  23. if [ -n "${alerturl}" ]; then
  24. json+=$(
  25. cat << EOF
  26. More info\n${alerturl}\n\n
  27. EOF
  28. )
  29. fi
  30. json+=$(
  31. cat << EOF
  32. Server Time\n$(date)"
  33. }
  34. EOF
  35. )
  36. fn_print_dots "Sending IFTTT alert"
  37. iftttsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://maker.ifttt.com/trigger/${iftttevent}/with/key/${ifttttoken}" | grep "Bad Request")
  38. if [ -n "${iftttsend}" ]; then
  39. fn_print_fail_nl "Sending IFTTT alert: ${pushbulletsend}"
  40. fn_script_log_fail "Sending IFTTT alert: ${pushbulletsend}"
  41. else
  42. fn_print_ok_nl "Sending IFTTT alert"
  43. fn_script_log_pass "Sent IFTTT alert"
  44. fi