alert_rocketchat.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. # LinuxGSM alert_rocketchat.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Rocketchat alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. jsoninfo=$(
  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. jsonnoinfo=$(
  65. cat << EOF
  66. {
  67. "alias": "LinuxGSM",
  68. "text": "*${alerttitle}*",
  69. "attachments": [
  70. {
  71. "title": "",
  72. "color": "${alertcolourhex}",
  73. "author_name": "LinuxGSM Alert",
  74. "author_link": "https://linuxgsm.com",
  75. "author_icon": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  76. "thumb_url": "${alerticon}",
  77. "text": "",
  78. "fields": [
  79. {
  80. "short": false,
  81. "title": "Server Name",
  82. "value": "${servername}"
  83. },
  84. {
  85. "short": false,
  86. "title": "Information",
  87. "value": "${alertmessage}"
  88. },
  89. {
  90. "short": false,
  91. "title": "Game",
  92. "value": "${gamename}"
  93. },
  94. {
  95. "short": false,
  96. "title": "Server IP",
  97. "value": "${alertip}:${port}"
  98. },
  99. {
  100. "short": false,
  101. "title": "Hostname",
  102. "value": "${HOSTNAME}"
  103. },
  104. {
  105. "short": false,
  106. "title": "Server Time",
  107. "value": "$(date)"
  108. }
  109. ]
  110. }
  111. ]
  112. }
  113. EOF
  114. )
  115. if [ -z "${alerturl}" ]; then
  116. json="${jsonnoinfo}"
  117. else
  118. json="${jsoninfo}"
  119. fi
  120. fn_print_dots "Sending Rocketchat alert"
  121. rocketchatsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}")
  122. if [ -n "${rocketchatsend}" ]; then
  123. fn_print_ok_nl "Sending Rocketchat alert"
  124. fn_script_log_pass "Sending Rocketchat alert"
  125. else
  126. fn_print_fail_nl "Sending Rocketchat alert: ${rocketchatsend}"
  127. fn_script_log_fail "Sending Rocketchat alert: ${rocketchatsend}"
  128. fi