alert_discord.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # LinuxGSM alert_discord.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Discord alert.
  7. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. if ! command -v jq > /dev/null; then
  9. fn_print_fail_nl "Sending Discord alert: jq is missing."
  10. fn_script_log_fatal "Sending Discord alert: jq is missing."
  11. fi
  12. json=$(cat <<EOF
  13. {
  14. "username":"LinuxGSM",
  15. "avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png",
  16. "file":"content",
  17. "embeds": [{
  18. "color": "2067276",
  19. "author": {
  20. "name": "${alertemoji} ${alertsubject} ${alertemoji}",
  21. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"
  22. },
  23. "title": "${servername}",
  24. "description": "${alertbody} \n More info: ${alerturl}",
  25. "url": "",
  26. "type": "content",
  27. "thumbnail": {},
  28. "fields": [
  29. {
  30. "name": "Game",
  31. "value": "${gamename}",
  32. "inline": true
  33. },
  34. {
  35. "name": "Server IP",
  36. "value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})",
  37. "inline": true
  38. },
  39. {
  40. "name": "Hostname",
  41. "value": "${HOSTNAME}",
  42. "inline": true
  43. }
  44. ]
  45. }]
  46. }
  47. EOF
  48. )
  49. fn_print_dots "Sending Discord alert"
  50. discordsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${discordwebhook}")
  51. if [ -n "${discordsend}" ]; then
  52. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  53. fn_script_log_fatal "Sending Discord alert: ${discordsend}"
  54. else
  55. fn_print_ok_nl "Sending Discord alert"
  56. fn_script_log_pass "Sending Discord alert"
  57. fi