alert_rocketchat.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # LinuxGSM alert_rocketchat.sh function
  3. # Author: Alasdair Haig
  4. # Website: https://linuxgsm.com
  5. # Description: Sends Rocketchat alert.
  6. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. if ! command -v jq > /dev/null; then
  8. fn_print_fail_nl "Sending Rocketchat alert: jq is missing."
  9. fn_script_log_fatal "Sending Rocketchat alert: jq is missing."
  10. fi
  11. json=$(cat <<EOF
  12. {
  13. "alias": "LinuxGSM",
  14. "text": "*${alertemoji} ${alertsubject} ${alertemoji}* + \n ${escaped_alertbody}",
  15. "attachments": [
  16. {
  17. "title": "Linuxgsm Alert",
  18. "text": "Hostname: ${HOSTNAME}",
  19. "color": "#36a64f",
  20. "fields": [
  21. {
  22. "short": true,
  23. "title": "Game:",
  24. "value": "${gamename}"
  25. },
  26. {
  27. "short": true,
  28. "title": "Server IP:",
  29. "value": "${alertip}:${port}"
  30. },
  31. {
  32. "short": true,
  33. "title": "Server Name:",
  34. "value": "${escaped_servername}"
  35. }
  36. ]
  37. }
  38. ]
  39. }
  40. EOF
  41. )
  42. fn_print_dots "Sending Rocketchat alert"
  43. rocketlaunch=$(curl -sSL -H "Content-Type:application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${rocketchatwebhook}")
  44. if [ "${rocketlaunch}" == "ok" ]; then
  45. fn_print_ok_nl "Sending Rocketchat alert"
  46. fn_script_log_pass "Sending Rocketchat alert"
  47. else
  48. fn_print_fail_nl "Sending Rocketchat alert: ${rocketlaunch}"
  49. fn_script_log_fatal "Sending Rocketchat alert: ${rocketlaunch}"
  50. fi