alert_rocketchat.sh 1.3 KB

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