alert_discord.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. json=$(cat <<EOF
  9. {
  10. "username":"LinuxGSM",
  11. "avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  12. "file":"content",
  13. "embeds": [{
  14. "color": "2067276",
  15. "author": {
  16. "name": "${alertemoji} ${alertsubject} ${alertemoji}",
  17. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  18. },
  19. "title": "${servername}",
  20. "description": "${alertbody} \n More info: ${alerturl}",
  21. "url": "",
  22. "type": "content",
  23. "thumbnail": {},
  24. "fields": [
  25. {
  26. "name": "Game",
  27. "value": "${gamename}",
  28. "inline": true
  29. },
  30. {
  31. "name": "Server IP",
  32. "value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})",
  33. "inline": true
  34. },
  35. {
  36. "name": "Hostname",
  37. "value": "${HOSTNAME}",
  38. "inline": true
  39. }
  40. ]
  41. }]
  42. }
  43. EOF
  44. )
  45. fn_print_dots "Sending Discord alert"
  46. discordsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  47. if [ -n "${discordsend}" ]; then
  48. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  49. fn_script_log_fatal "Sending Discord alert: ${discordsend}"
  50. else
  51. fn_print_ok_nl "Sending Discord alert"
  52. fn_script_log_pass "Sending Discord alert"
  53. fi