alert_discord.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. jsoninfo=$(
  9. cat << EOF
  10. {
  11. "username": "LinuxGSM",
  12. "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  13. "file": "content",
  14. "embeds": [
  15. {
  16. "author": {
  17. "name": "LinuxGSM Alert",
  18. "url": "",
  19. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  20. },
  21. "title": "${alerttitle}",
  22. "url": "",
  23. "description": "",
  24. "color": "${alertcolourdec}",
  25. "type": "content",
  26. "thumbnail": {
  27. "url": "${alerticon}"
  28. },
  29. "fields": [
  30. {
  31. "name": "Server Name",
  32. "value": "${servername}"
  33. },
  34. {
  35. "name": "Information",
  36. "value": "${alertmessage}"
  37. },
  38. {
  39. "name": "Game",
  40. "value": "${gamename}",
  41. "inline": true
  42. },
  43. {
  44. "name": "Server IP",
  45. "value": "\`${alertip}:${port}\`",
  46. "inline": true
  47. },
  48. {
  49. "name": "Hostname",
  50. "value": "${HOSTNAME}",
  51. "inline": true
  52. },
  53. {
  54. "name": "Is my Game Server Online?",
  55. "value": "https://ismygameserver.online/${querytype}/${alertip}:${queryport}",
  56. "inline": true
  57. },
  58. {
  59. "name": "More info",
  60. "value": "${alerturl}",
  61. "inline": true
  62. },
  63. {
  64. "name": "Server Time",
  65. "value": "$(date)",
  66. "inline": true
  67. }
  68. ],
  69. "footer": {
  70. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  71. "text": "Sent by LinuxGSM ${version}"
  72. }
  73. }
  74. ]
  75. }
  76. EOF
  77. )
  78. jsonnoinfo=$(
  79. cat << EOF
  80. {
  81. "username": "LinuxGSM",
  82. "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  83. "file": "content",
  84. "embeds": [
  85. {
  86. "author": {
  87. "name": "LinuxGSM Alert",
  88. "url": "",
  89. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  90. },
  91. "title": "${alerttitle}",
  92. "url": "",
  93. "description": "",
  94. "color": "${alertcolourdec}",
  95. "type": "content",
  96. "thumbnail": {
  97. "url": "${alerticon}"
  98. },
  99. "fields": [
  100. {
  101. "name": "Server Name",
  102. "value": "${servername}"
  103. },
  104. {
  105. "name": "Information",
  106. "value": "${alertmessage}"
  107. },
  108. {
  109. "name": "Game",
  110. "value": "${gamename}",
  111. "inline": true
  112. },
  113. {
  114. "name": "Server IP",
  115. "value": "\`${alertip}:${port}\`",
  116. "inline": true
  117. },
  118. {
  119. "name": "Hostname",
  120. "value": "${HOSTNAME}",
  121. "inline": true
  122. },
  123. {
  124. "name": "Is my Game Server Online?",
  125. "value": "https://ismygameserver.online/${querytype}/${alertip}:${queryport}",
  126. "inline": true
  127. },
  128. {
  129. "name": "Server Time",
  130. "value": "$(date)",
  131. "inline": true
  132. }
  133. ],
  134. "footer": {
  135. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  136. "text": "Sent by LinuxGSM ${version}"
  137. }
  138. }
  139. ]
  140. }
  141. EOF
  142. )
  143. fn_print_dots "Sending Discord alert"
  144. if [ -z "${alerturl}" ]; then
  145. json="${jsonnoinfo}"
  146. else
  147. json="${jsoninfo}"
  148. fi
  149. discordsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  150. if [ -n "${discordsend}" ]; then
  151. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  152. fn_script_log_fail "Sending Discord alert: ${discordsend}"
  153. else
  154. fn_print_ok_nl "Sending Discord alert"
  155. fn_script_log_pass "Sending Discord alert"
  156. fi