alert_rocketchat.sh 1.2 KB

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