alert_rocketchat.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # LinuxGSM alert_rocketchat.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Rocketchat alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(
  9. cat << EOF
  10. {
  11. "alias": "LinuxGSM",
  12. "text": "*${alerttitle}*",
  13. "attachments": [
  14. {
  15. "title": "",
  16. "color": "${alertcolourhex}",
  17. "author_name": "LinuxGSM Alert",
  18. "author_link": "https://linuxgsm.com",
  19. "author_icon": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  20. "thumb_url": "${alerticon}",
  21. "text": "",
  22. "fields": [
  23. {
  24. "short": false,
  25. "title": "Server Name",
  26. "value": "${servername}"
  27. },
  28. {
  29. "short": false,
  30. "title": "Information",
  31. "value": "${alertmessage}"
  32. },
  33. {
  34. "short": false,
  35. "title": "Game",
  36. "value": "${gamename}"
  37. },
  38. {
  39. "short": false,
  40. "title": "Server IP",
  41. "value": "${alertip}:${port}"
  42. },
  43. {
  44. "short": false,
  45. "title": "Hostname",
  46. "value": "${HOSTNAME}"
  47. },
  48. {
  49. "short": false,
  50. "title": "More info",
  51. "value": "${alerturl}"
  52. },
  53. {
  54. "short": false,
  55. "title": "Server Time",
  56. "value": "$(date)"
  57. }
  58. ]
  59. }
  60. ]
  61. }
  62. EOF
  63. )
  64. if [ -n "${querytype}" ]; then
  65. json+=$(
  66. cat << EOF
  67. {
  68. "short": false,
  69. "title": "Is my Game Server Online?",
  70. "value": "<https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}|Check here>"
  71. },
  72. EOF
  73. )
  74. fi
  75. if [ -n "${alerturl}" ]; then
  76. json+=$(
  77. cat << EOF
  78. {
  79. "short": false,
  80. "title": "More info",
  81. "value": "${alerturl}"
  82. },
  83. EOF
  84. )
  85. fi
  86. json+=$(
  87. cat << EOF
  88. {
  89. "alias": "LinuxGSM",
  90. "text": "*${alerttitle}*",
  91. "attachments": [
  92. {
  93. "title": "",
  94. "color": "${alertcolourhex}",
  95. "author_name": "LinuxGSM Alert",
  96. "author_link": "https://linuxgsm.com",
  97. "author_icon": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  98. "thumb_url": "${alerticon}",
  99. "text": "",
  100. "fields": [
  101. {
  102. "short": false,
  103. "title": "Server Name",
  104. "value": "${servername}"
  105. },
  106. {
  107. "short": false,
  108. "title": "Information",
  109. "value": "${alertmessage}"
  110. },
  111. {
  112. "short": false,
  113. "title": "Game",
  114. "value": "${gamename}"
  115. },
  116. {
  117. "short": false,
  118. "title": "Server IP",
  119. "value": "${alertip}:${port}"
  120. },
  121. {
  122. "short": false,
  123. "title": "Hostname",
  124. "value": "${HOSTNAME}"
  125. },
  126. {
  127. "short": false,
  128. "title": "Server Time",
  129. "value": "$(date)"
  130. }
  131. ]
  132. }
  133. ]
  134. }
  135. EOF
  136. )
  137. fn_print_dots "Sending Rocketchat alert"
  138. rocketchatsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}")
  139. if [ -n "${rocketchatsend}" ]; then
  140. fn_print_ok_nl "Sending Rocketchat alert"
  141. fn_script_log_pass "Sending Rocketchat alert"
  142. else
  143. fn_print_fail_nl "Sending Rocketchat alert: ${rocketchatsend}"
  144. fn_script_log_fail "Sending Rocketchat alert: ${rocketchatsend}"
  145. fi