alert_discord.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Alert",
  11. "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  12. "content": "",
  13. "embeds": [
  14. {
  15. "author": {
  16. "name": "LinuxGSM",
  17. "url": "",
  18. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  19. },
  20. "title": "${servername}",
  21. "url": "",
  22. "description": "${alertemoji} ${alertsubject}",
  23. "color": 15258703,
  24. "fields": [
  25. {
  26. "name": "Game",
  27. "value": "${gamename}",
  28. "inline": true
  29. },
  30. {
  31. "name": "Players",
  32. "value": "${alertplayers}",
  33. "inline": true
  34. },
  35. {
  36. "name": "Map",
  37. "value": "${alertmap}",
  38. "inline": true
  39. },
  40. {
  41. "name": "Server IP",
  42. "value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})",
  43. "inline": true
  44. },
  45. {
  46. "name": "Hostname",
  47. "value": "${HOSTNAME}",
  48. "inline": true
  49. },
  50. {
  51. "name": "Information",
  52. "value": "${alertbody} \n More info: ${alerturl}"
  53. }
  54. ],
  55. "thumbnail": {
  56. "url": "${alerticon}"
  57. },
  58. "image": {
  59. "url": "${alertimage}"
  60. },
  61. "footer": {
  62. "text": "Powered by LinuxGSM",
  63. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  64. }
  65. }
  66. ]
  67. }
  68. EOF
  69. )
  70. fn_print_dots "Sending Discord alert"
  71. discordsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  72. if [ -n "${discordsend}" ]; then
  73. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  74. fn_script_log_fatal "Sending Discord alert: ${discordsend}"
  75. else
  76. fn_print_ok_nl "Sending Discord alert"
  77. fn_script_log_pass "Sending Discord alert"
  78. fi