alert_rocketchat.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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": "*${alertemoji} ${alertsubject} ${alertemoji}* \n *${servername}* \n ${alertbody} \n More info: ${alerturl}",
  12. "attachments": [
  13. {
  14. "fields": [
  15. {
  16. "short": true,
  17. "title": "Game:",
  18. "value": "${gamename}"
  19. },
  20. {
  21. "short": true,
  22. "title": "Server IP:",
  23. "value": "${alertip}:${port}"
  24. },
  25. {
  26. "short": true,
  27. "title": "Hostname:",
  28. "value": "${HOSTNAME}"
  29. }
  30. ]
  31. }
  32. ]
  33. }
  34. EOF
  35. )
  36. fn_print_dots "Sending Rocketchat alert"
  37. rocketchatsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}")
  38. if [ -n "${rocketchatsend}" ]; then
  39. fn_print_ok_nl "Sending Rocketchat alert"
  40. fn_script_log_pass "Sending Rocketchat alert"
  41. else
  42. fn_print_fail_nl "Sending Rocketchat alert: ${rocketchatsend}"
  43. fn_script_log_fatal "Sending Rocketchat alert: ${rocketchatsend}"
  44. fi