alert_sendgrid.sh 992 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. # LinuxGSM alert_sendgrid.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Sends SendGrid Email alert.
  6. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. fn_print_dots "Sending Email alert: SendGrid: ${email}"
  8. sendgridsend=$(curl -s --request POST \
  9. --url https://api.sendgrid.com/v3/mail/send \
  10. --header "Authorization: Bearer ${sendgridtoken}" \
  11. --header 'Content-Type: application/json' \
  12. --data '{"personalizations": [{"to": [{"email": ${sendgridemail}"}]}],"from": {"email": "${sendgridemailfrom}"},"subject": "${alertemoji} ${alertsubject} ${alertemoji}","content": [{"type": "text/plain", "value": "$(cat "${alertlog}")"}]}')
  13. if [ -z "${sendgridsend}" ]; then
  14. fn_print_fail_nl "Sending Email alert: SendGrid: ${email}"
  15. fn_script_log_fatal "Sending Email alert: SendGrid: ${email}"
  16. else
  17. fn_print_ok_nl "Sending Email alert: SendGrid: ${email}"
  18. fn_script_log_pass "Sending Email alert: SendGrid: ${email}"
  19. fi