4
0

alert_rocketchat.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. EOF
  44. )
  45. if [ -n "${querytype}" ]; then
  46. json+=$(
  47. cat << EOF
  48. ,
  49. {
  50. "short": false,
  51. "title": "Is my Game Server Online?",
  52. "value": "<https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}|Check here>"
  53. }
  54. EOF
  55. )
  56. fi
  57. if [ -n "${alerturl}" ]; then
  58. json+=$(
  59. cat << EOF
  60. ,
  61. {
  62. "short": false,
  63. "title": "More info",
  64. "value": "${alerturl}"
  65. }
  66. EOF
  67. )
  68. fi
  69. json+=$(
  70. cat << EOF
  71. ,
  72. {
  73. "short": false,
  74. "title": "Server Time",
  75. "value": "$(date)"
  76. }
  77. ]
  78. }
  79. ]
  80. }
  81. EOF
  82. )
  83. fn_print_dots "Sending Rocketchat alert"
  84. rocketchatsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}")
  85. if [ -n "${rocketchatsend}" ]; then
  86. fn_print_ok_nl "Sending Rocketchat alert"
  87. fn_script_log_pass "Sending Rocketchat alert"
  88. else
  89. fn_print_fail_nl "Sending Rocketchat alert: ${rocketchatsend}"
  90. fn_script_log_fail "Sending Rocketchat alert: ${rocketchatsend}"
  91. fi