alert_discord.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # LinuxGSM alert_discord.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: faflfama
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Discord alert.
  7. json=$(cat <<EOF
  8. {
  9. "username":"LinuxGSM",
  10. "avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/data/alert_discord_logo.png",
  11. "file":"content",
  12. "embeds": [{
  13. "color": "2067276",
  14. "author": {"name": "${alertemoji} ${alertsubject} ${alertemoji}", "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"},
  15. "title": "",
  16. "description": "",
  17. "url": "",
  18. "type": "content",
  19. "thumbnail": {"url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"},
  20. "footer": {"text": "LinuxGSM", "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"},
  21. "fields": [
  22. {
  23. "name": "Alert Message",
  24. "value": "${alertbody}"
  25. },
  26. {
  27. "name": "Game",
  28. "value": "${gamename}"
  29. },
  30. {
  31. "name": "Server name",
  32. "value": "${servername}"
  33. },
  34. {
  35. "name": "Hostname",
  36. "value": "${HOSTNAME}"
  37. },
  38. {
  39. "name": "Server IP",
  40. "value": "[${extip:-$ip}:${port}](https://www.gametracker.com/server_info/${extip:-$ip}:${port})"
  41. },
  42. {
  43. "name": "More info",
  44. "value": "${alerturl}"
  45. }
  46. ]
  47. }]
  48. }
  49. EOF
  50. )
  51. fn_print_dots "Sending Discord alert"
  52. sleep 0.5
  53. discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "${discordwebhook}")
  54. if [ -n "${discordsend}" ]; then
  55. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  56. fn_script_log_fatal "Sending Discord alert: ${discordsend}"
  57. else
  58. fn_print_ok_nl "Sending Discord alert"
  59. fn_script_log_pass "Sending Discord alert"
  60. fi