alert_rocketchat.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(cat <<EOF
  9. {
  10. "alias": "LinuxGSM",
  11. "text": "*${servername}*\n${alertemoji} ${alerttitle} ${alertemoji}\n\n*Trigger Message*\n${alerttriggermessage}\n\n*More info*\n${alertmoreinfourl}\n\n*Game*\n${gamename}",
  12. "attachments": [
  13. {
  14. "fields": [
  15. {
  16. "short": true,
  17. "title": "Map",
  18. "value": "${alertmap}"
  19. },
  20. {
  21. "short": true,
  22. "title": "${alertplayerstitle}",
  23. "value": "${alertplayers}"
  24. },
  25. {
  26. "short": true,
  27. "title": "Version",
  28. "value": "${alertversion}"
  29. },
  30. {
  31. "short": true,
  32. "title": "Country",
  33. "value": "${country}"
  34. },
  35. {
  36. "short": true,
  37. "title": "Server IP",
  38. "value": "${alertip}:${port}"
  39. },
  40. {
  41. "short": true,
  42. "title": "Hostname",
  43. "value": "${HOSTNAME}"
  44. }
  45. ]
  46. }
  47. ]
  48. }
  49. EOF
  50. )
  51. fn_print_dots "Sending Rocketchat alert"
  52. rocketchatsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}")
  53. if [ -n "${rocketchatsend}" ]; then
  54. fn_print_ok_nl "Sending Rocketchat alert"
  55. fn_script_log_pass "Sending Rocketchat alert"
  56. else
  57. fn_print_fail_nl "Sending Rocketchat alert: ${rocketchatsend}"
  58. fn_script_log_fatal "Sending Rocketchat alert: ${rocketchatsend}"
  59. fi