alert_discord.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # LinuxGSM alert_discord.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Discord alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(
  9. cat << EOF
  10. {
  11. "username":"LinuxGSM",
  12. "avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg",
  13. "file":"content",
  14. "embeds": [{
  15. "color": "2067276",
  16. "author": {
  17. "name": "${alertemoji} ${alertsubject} ${alertemoji}",
  18. "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg"
  19. },
  20. "title": "${servername}",
  21. "description": "${alertbody} \n More info: ${alerturl}",
  22. "url": "",
  23. "type": "content",
  24. "thumbnail": {},
  25. "fields": [
  26. {
  27. "name": "Game",
  28. "value": "${gamename}",
  29. "inline": true
  30. },
  31. {
  32. "name": "Server IP",
  33. "value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})",
  34. "inline": true
  35. },
  36. {
  37. "name": "Hostname",
  38. "value": "${HOSTNAME}",
  39. "inline": true
  40. }
  41. ]
  42. }]
  43. }
  44. EOF
  45. )
  46. fn_print_dots "Sending Discord alert"
  47. discordsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}")
  48. if [ -n "${discordsend}" ]; then
  49. fn_print_fail_nl "Sending Discord alert: ${discordsend}"
  50. fn_script_log_fatal "Sending Discord alert: ${discordsend}"
  51. else
  52. fn_print_ok_nl "Sending Discord alert"
  53. fn_script_log_pass "Sending Discord alert"
  54. fi