From 131b8ef6ba4c5ce9debe1182213bbe3763a9182b Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 22 Aug 2017 20:46:24 +0100 Subject: [PATCH] Added mailgun --- lgsm/functions/alert.sh | 77 +++++++++++++++++++-------------- lgsm/functions/alert_mailgun.sh | 22 ++++++++++ 2 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 lgsm/functions/alert_mailgun.sh diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index ca8beed12..2709043e7 100644 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -64,6 +64,17 @@ elif [ "${alert}" == "update" ]; then fn_alert_update fi +if [ "${discordalert}" == "on" ]&&[ -n "${discordalert}" ]; then + alert_discord.sh +elif [ "${discordalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_warn_nl "Discord alerts not enabled" + fn_script_log_warn "Discord alerts not enabled" +elif [ -z "${discordtoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "Discord token not set" + echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Discord" + fn_script_error_warn "Discord token not set" +fi + if [ "${emailalert}" == "on" ]&&[ -n "${email}" ]; then alert_email.sh elif [ "${emailalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then @@ -74,6 +85,28 @@ elif [ -z "${email}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; t fn_script_log_error "Email not set" fi +if [ "${iftttalert}" == "on" ]&&[ -n "${iftttalert}" ]; then + alert_ifttt.sh +elif [ "${iftttalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_warn_nl "IFTTT alerts not enabled" + fn_script_log_warn "IFTTT alerts not enabled" +elif [ -z "${ifttttoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "IFTTT token not set" + echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/IFTTT" + fn_script_error_warn "IFTTT token not set" +fi + +if [ "${mailgunalert}" == "on" ]&&[ -n "${mailgunalert}" ]; then + alert_mailgun.sh +elif [ "${mailgunalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_warn_nl "Mailgun alerts not enabled" + fn_script_log_warn "Mailgun alerts not enabled" +elif [ -z "${mailguntoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "Mailgun token not set" + echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Mailgun" + fn_script_error_warn "Mailgun token not set" +fi + if [ "${pushbulletalert}" == "on" ]&&[ -n "${pushbullettoken}" ]; then alert_pushbullet.sh elif [ "${pushbulletalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then @@ -85,6 +118,17 @@ elif [ -z "${pushbullettoken}" ]&&[ "${function_selfname}" == "command_test_aler fn_script_error_warn "Pushbullet token not set" fi +if [ "${pushoveralert}" == "on" ]&&[ -n "${pushoveralert}" ]; then + alert_pushover.sh +elif [ "${pushoveralert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_warn_nl "Pushover alerts not enabled" + fn_script_log_warn "Pushover alerts not enabled" +elif [ -z "${pushovertoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "Pushover token not set" + echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Pushover" + fn_script_error_warn "Pushover token not set" +fi + if [ "${telegramalert}" == "on" ]&&[ -n "${telegramtoken}" ]; then alert_telegram.sh elif [ "${telegramalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then @@ -98,37 +142,4 @@ elif [ -z "${telegramchatid}" ]&&[ "${function_selfname}" == "command_test_alert fn_print_error_nl "Telegram chat id not set." echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Telegram" fn_script_error_warn "Telegram chat id not set." -fi - -if [ "${discordalert}" == "on" ]&&[ -n "${discordalert}" ]; then - alert_discord.sh -elif [ "${discordalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then - fn_print_warn_nl "Discord alerts not enabled" - fn_script_log_warn "Discord alerts not enabled" -elif [ -z "${discordtoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then - fn_print_error_nl "Discord token not set" - echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Discord" - fn_script_error_warn "Discord token not set" -fi - -if [ "${pushoveralert}" == "on" ]&&[ -n "${pushoveralert}" ]; then - alert_pushover.sh -elif [ "${pushoveralert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then - fn_print_warn_nl "Pushover alerts not enabled" - fn_script_log_warn "Pushover alerts not enabled" -elif [ -z "${pushovertoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then - fn_print_error_nl "Pushover token not set" - echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Pushover" - fn_script_error_warn "Pushover token not set" -fi - -if [ "${iftttalert}" == "on" ]&&[ -n "${iftttalert}" ]; then - alert_ifttt.sh -elif [ "${iftttalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then - fn_print_warn_nl "IFTTT alerts not enabled" - fn_script_log_warn "IFTTT alerts not enabled" -elif [ -z "${ifttttoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then - fn_print_error_nl "IFTTT token not set" - echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/IFTTT" - fn_script_error_warn "IFTTT token not set" fi \ No newline at end of file diff --git a/lgsm/functions/alert_mailgun.sh b/lgsm/functions/alert_mailgun.sh new file mode 100644 index 000000000..2d01b1523 --- /dev/null +++ b/lgsm/functions/alert_mailgun.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# LinuxGSM alert_mailgun.sh function +# Author: Daniel Gibbs +# Website: https://gameservermanagers.com +# Description: Sends Mailgun Email alert. + +local commandname="ALERT" +local commandaction="Alert" +local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" + +fn_print_dots "Sending Email (Mailgun) alert" +sleep 0.5 +mailgunsend=$(curl -s --user "api:${mailguntoken}" -F from="LinuxGSM <${mailgundomain}>" -F to="${servicename} Admin <${mailgunemail}>" -F subject="${alertemoji} ${alertsubject} ${alertemoji}" --form-string html="

Message
${alertbody}

Game
${gamename}

Server name
${servername}

Hostname
${HOSTNAME}

Server IP
${ip}:${port}

More info
${alerturl}" https://api.mailgun.net/v3/sandbox10b3f208bfe541aca8a0c97f33a6c3fe.mailgun.org/messages) + +if [ -z "${mailgunsend}" ]; then + fn_print_fail_nl "Sending Email (Mailgun) alert" + fn_script_log_fatal "Sending Email (Mailgun) alert" +else + fn_print_ok_nl "Sending Email (Mailgun) alert" + fn_script_log_pass "Sent Email (Mailgun) alert" +fi +