diff --git a/lgsm/config-default/config-lgsm/jc2server/_default.cfg b/lgsm/config-default/config-lgsm/jc2server/_default.cfg index a7b45a24a..122da30dd 100644 --- a/lgsm/config-default/config-lgsm/jc2server/_default.cfg +++ b/lgsm/config-default/config-lgsm/jc2server/_default.cfg @@ -67,6 +67,13 @@ rocketchatalert="off" rocketchatwebhook="webhook" rocketchattoken="" +# Sendgrid Email Alerts | https://docs.linuxgsm.com/alerts/sendgrid +sendgridalert="off" +sendgridtoken="accesstoken" +sendgriddomain="example.com" +sendgridemailfrom="alert@example.com" +sendgridemail="email@myemail.com" + # Slack Alerts | https://docs.linuxgsm.com/alerts/slack slackalert="off" slackwebhook="webhook" diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index 484c0c1e2..0c3779e46 100755 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -188,6 +188,17 @@ elif [ -z "${pushovertoken}" ]&&[ "${commandname}" == "TEST-ALERT" ]; then fn_script_error "Pushover token not set" fi +if [ "${sendgridalert}" == "on" ]&&[ -n "${sendgridalert}" ]; then + alert_sendgrid.sh +elif [ "${sendgridalert}" != "on" ]&&[ "${commandname}" == "TEST-ALERT" ]; then + fn_print_warn_nl "SendGrid alerts not enabled" + fn_script_log_warn "SendGrid alerts not enabled" +elif [ -z "${sendgridtoken}" ]&&[ "${commandname}" == "TEST-ALERT" ]; then + fn_print_error_nl "SendGrid token not set" + echo -e "* https://docs.linuxgsm.com/alerts/sendgrid" + fn_script_error "SendGrid token not set" +fi + if [ "${telegramalert}" == "on" ]&&[ -n "${telegramtoken}" ]; then alert_telegram.sh elif [ "${telegramalert}" != "on" ]&&[ "${commandname}" == "TEST-ALERT" ]; then diff --git a/lgsm/functions/alert_sendgrid.sh b/lgsm/functions/alert_sendgrid.sh new file mode 100644 index 000000000..a8590ccdf --- /dev/null +++ b/lgsm/functions/alert_sendgrid.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# LinuxGSM alert_sendgrid.sh function +# Author: Daniel Gibbs +# Website: https://linuxgsm.com +# Description: Sends SendGrid Email alert. + +functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" + +fn_print_dots "Sending Email alert: SendGrid: ${email}" + +sendgridsend=$(curl -s --request POST \ + --url https://api.sendgrid.com/v3/mail/send \ + --header "Authorization: Bearer ${sendgridtoken}" \ + --header 'Content-Type: application/json' \ + --data '{"personalizations": [{"to": [{"email": ${sendgridemail}"}]}],"from": {"email": "${sendgridemailfrom}"},"subject": "${alertemoji} ${alertsubject} ${alertemoji}","content": [{"type": "text/plain", "value": "$(cat "${alertlog}")"}]}') + +if [ -z "${sendgridsend}" ]; then + fn_print_fail_nl "Sending Email alert: SendGrid: ${email}" + fn_script_log_fatal "Sending Email alert: SendGrid: ${email}" +else + fn_print_ok_nl "Sending Email alert: SendGrid: ${email}" + fn_script_log_pass "Sending Email alert: SendGrid: ${email}" +fi diff --git a/lgsm/functions/alert_slack.sh b/lgsm/functions/alert_slack.sh index c3a82d529..ede065730 100755 --- a/lgsm/functions/alert_slack.sh +++ b/lgsm/functions/alert_slack.sh @@ -13,54 +13,59 @@ fi json=$(cat <