Browse Source

Merge remote-tracking branch 'origin/feature/alerts-refactor' into feature/alerts-refactor

feature/alerts-refactor
Daniel Gibbs 4 years ago
parent
commit
8c7eabb0af
  1. 27
      lgsm/functions/alert.sh
  2. 4
      lgsm/functions/alert_discord.sh
  3. 4
      lgsm/functions/alert_email.sh
  4. 3
      lgsm/functions/alert_gotify.sh
  5. 2
      lgsm/functions/alert_ifttt.sh
  6. 4
      lgsm/functions/alert_pushbullet.sh
  7. 2
      lgsm/functions/alert_pushover.sh
  8. 3
      lgsm/functions/alert_rocketchat.sh
  9. 3
      lgsm/functions/alert_slack.sh
  10. 2
      lgsm/functions/alert_telegram.sh
  11. 21
      lgsm/functions/info_messages.sh

27
lgsm/functions/alert.sh

@ -21,6 +21,11 @@ fn_alert_log(){
fn_info_message_server_resource
fn_info_message_gameserver_resource
fn_info_message_gameserver
fn_info_message_script
fn_info_message_backup
fn_info_message_commandlineparms
fn_info_message_ports_edit
fn_info_message_ports
fn_info_logs
} | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${alertlog}" > /dev/null 2>&1
}
@ -31,7 +36,7 @@ fn_alert_test(){
alertemoji="🚧"
alertsound="1"
alerturl="not enabled"
alertmessage="Testing LinuxGSM Alert. No action to be taken."
alerttriggermessage="Testing LinuxGSM Alert. No action to be taken."
# Green
alertcolourhex="#cdcd00"
alertcolourdec="13487360"
@ -43,7 +48,7 @@ fn_alert_restart(){
alertemoji="🚨"
alertsound="2"
alerturl="not enabled"
alertmessage="${selfname} is not running. Game Server has been restarted."
alerttriggermessage="${selfname} is not running. Game Server has been restarted."
# Red
alertcolourhex="#cd0000"
alertcolourdec="13434880"
@ -55,7 +60,7 @@ fn_alert_restart_query(){
alertemoji="🚨"
alertsound="2"
alerturl="not enabled"
alertmessage="Unable to query ${selfname}. Game server has been restarted"
alerttriggermessage="Unable to query ${selfname}. Game server has been restarted."
# Red
alertcolourhex="#cd0000"
alertcolourdec="13434880"
@ -64,10 +69,10 @@ fn_alert_restart_query(){
fn_alert_update(){
fn_script_log_info "Sending alert: Updated: ${selfname}"
alerttitle="Alert - ${selfname} - Updated"
alertemoji="🎮"
alertemoji="🎉"
alertsound="1"
alerturl="not enabled"
alertmessage="${selfname} has received an update"
alerttriggermessage="${selfname} has received an update."
# Green
alertcolourhex="#00cd00"
alertcolourdec="52480"
@ -76,10 +81,10 @@ fn_alert_update(){
fn_alert_check_update(){
fn_script_log_info "Sending alert: Update available"
alerttitle="Alert - ${selfname} - Update available"
alertemoji="🎮"
alertemoji="💿"
alertsound="1"
alerturl="not enabled"
alertmessage="Update availablefor ${selfname}"
alerttriggermessage="Update available for ${selfname}."
# Blue
alertcolourhex="#1e90ff"
alertcolourdec="2003199"
@ -91,7 +96,7 @@ fn_alert_permissions(){
alertemoji="❗"
alertsound="2"
alerturl="not enabled"
alertmessage="${selfname} has permissions issues"
alerttriggermessage="${selfname} has permissions issues."
# Red
alertcolourhex="#cd0000"
alertcolourdec="13434880"
@ -103,7 +108,7 @@ fn_alert_config(){
alertemoji="📄"
alertsound="1"
alerturl="not enabled"
alertmessage="${selfname} has received a new _default.cfg. Check file for changes."
alerttriggermessage="${selfname} has received a new _default.cfg. Check file for changes."
# Blue
alertcolourhex="#1e90ff"
alertcolourdec="2003199"
@ -112,10 +117,10 @@ fn_alert_config(){
fn_alert_wipe(){
fn_script_log_info "Sending alert: Wiped: ${selfname} wiped"
alerttitle="Alert - ${selfname} - Wiped"
alertemoji="💿"
alertemoji="🧹"
alertsound="1"
alerturl="not enabled"
alertmessage="${selfname} as been wiped."
alerttriggermessage="${selfname} as been wiped."
# Green
alertcolourhex="#00cd00"
alertcolourdec="52480"

4
lgsm/functions/alert_discord.sh

@ -55,8 +55,8 @@ json=$(cat <<EOF
"inline": true
},
{
"name": "Information",
"value": "${alertmessage} \n More info: ${alerturl}"
"name": "Trigger Message",
"value": "${alerttriggermessage} \n\n More info: ${alerturl}"
}
],
"thumbnail": {

4
lgsm/functions/alert_email.sh

@ -11,9 +11,9 @@ fn_print_dots "Sending Email alert: ${email}"
fn_sleep_time
if [ -n "${emailfrom}" ]; then
mail -s "${alerttitle}" -r "${emailfrom}" "${email}" < "${alertlog}"
mail -s "${alertemoji} ${alerttitle} ${alertemoji}" -r "${emailfrom}" "${email}" < "${alertlog}"
else
mail -s "${alerttitle}" "${email}" < "${alertlog}"
mail -s "${alertemoji} ${alerttitle} ${alertemoji}" "${email}" < "${alertlog}"
fi
exitcode=$?
if [ "${exitcode}" == "0" ]; then

3
lgsm/functions/alert_gotify.sh

@ -10,14 +10,13 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
json=$(cat <<EOF
{
"title": "${alertemoji} ${alerttitle} ${alertemoji}",
"message": "Server name\n${servername}\n\nMessage\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}",
"message": "Server name\n${servername}\n\nTrigger Message\n${alerttriggermessage}\n\nGame\n${gamename}\n\nCurrent Players\n${alertplayers}\n\nMap\n${alertmap}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nVersion\n${alertversion}\n\nMore info\n${alerturl}",
"priority": 5
}
EOF
)
fn_print_dots "Sending Gotify alert"
gotifysend=$(curl --connect-timeout 10 -sSL "${gotifywebhook}/message"?token="${gotifytoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)")
if [ -n "${gotifysend}" ]; then

2
lgsm/functions/alert_ifttt.sh

@ -11,7 +11,7 @@ json=$(cat <<EOF
{
"value1": "${selfname}",
"value2": "${alertemoji} ${alerttitle} ${alertemoji}",
"value3": "Server name<br>${servername}<br><br>Message<br>${alertmessage}<br><br>Game<br>${gamename}<br><br>${alertplayerstitle}<br>${alertplayers}<br><br>Map<br>${alertmap}<br><br>Server IP<br>${alertip}:${port}<br><br>Hostname<br>${HOSTNAME}<br><br>More info<br>${alerturl}"
"value3": "Server name<br>${servername}<br><br>Trigger Message<br>${alerttriggermessage}<br><br>Game<br>${gamename}<br><br>${alertplayerstitle}<br>${alertplayers}<br><br>Map<br>${alertmap}<br><br>Server IP<br>${alertip}:${port}<br><br>Hostname<br>${HOSTNAME}<br><br>More info<br>${alerturl}"
}
EOF
)

4
lgsm/functions/alert_pushbullet.sh

@ -12,13 +12,13 @@ json=$(cat <<EOF
"channel_tag": "${channeltag}",
"type": "note",
"title": "${alertemoji} ${alerttitle} ${alertemoji}",
"body": "Server name\n${servername}\n\nMessage\n${alertmessage}\n\nGame\n${gamename}\n\n${alertplayerstitle}\n${alertplayers}\n\nMap\n${alertmap}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}"
"body": "Server name\n${servername}\n\nTrigger Message\n${alerttriggermessage}\n\nGame\n${gamename}\n\nCurrent Players\n${alertplayers}\n\nMap\n${alertmap}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nVersion\n${alertversion}\n\nMore info\n${alerturl}"
}
EOF
)
fn_print_dots "Sending Pushbullet alert"
pushbulletsend=$(curl --connect-timeout 10 -sSL -u """${pushbullettoken}"":" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
pushbulletsend=$(curl --connect-timeout 10 -sSL -H "Access-Token: ${pushbullettoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
if [ -n "${pushbulletsend}" ]; then
fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"

2
lgsm/functions/alert_pushover.sh

@ -22,7 +22,7 @@ else
alertpriority="0"
fi
pushoversend=$(curl --connect-timeout 10 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alertemoji} ${alerttitle} ${alertemoji}" -F message=" <b>Server name</b><br>${servername}<br><br><b>Message</b><br>${alertmessage}<br><br><b>Game</b><br>${gamename}<br><br><b>${alertplayerstitle}</b><br>${alertplayers}<br><br><b>Map</b><br>${alertmap}<br><br><b>Server IP</b><br><a href='https://www.gametracker.com/server_info/${alertip}:${port}'>${alertip}:${port}</a><br><br><b>Hostname</b><br>${HOSTNAME}<br><br><b>More info</b><br><a href='${alerturl}'>${alerturl}</a>" "https://api.pushover.net/1/messages.json" | grep errors)
pushoversend=$(curl --connect-timeout 10 -sSL -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alertemoji} ${alerttitle} ${alertemoji}" -F message=" <b>Server name</b><br>${servername}<br><br><b>Trigger Message</b><br>${alerttriggermessage}<br><br><b>Game</b><br>${gamename}<br><br><b>Current Players</b><br>${alertplayers}<br><br><b>Map</b><br>${alertmap}<br><br><b>Server IP</b><br>${alertip}:${port}<br><br><b>Hostname</b><br>${HOSTNAME}<br><br><b>Version</b><br>${alertversion}<br><br><b>More info</b><br>${alerturl}" "https://api.pushover.net/1/messages.json" | grep errors)
if [ -n "${pushoversend}" ]; then
fn_print_fail_nl "Sending Pushover alert: ${pushoversend}"

3
lgsm/functions/alert_rocketchat.sh

@ -10,7 +10,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
json=$(cat <<EOF
{
"alias": "LinuxGSM",
"text": "*${alertemoji} ${alerttitle} ${alertemoji}* \n *${servername}* \n ${alertmessage} \n More info: ${alerturl}",
"text": "*${alertemoji} ${alerttitle} ${alertemoji}* \n *${servername}* \n ${alerttriggermessage} \n More info: ${alerturl}",
"attachments": [
{
"fields": [
@ -37,7 +37,6 @@ EOF
)
fn_print_dots "Sending Rocketchat alert"
rocketchatsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}")
if [ -n "${rocketchatsend}" ]; then

3
lgsm/functions/alert_slack.sh

@ -104,7 +104,7 @@ json=$(cat <<EOF
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Message*\n${alertmessage} \n More info: ${alerturl}"
"text": "*Trigger Message*\n${alerttriggermessage} \n More info: ${alerturl}"
}
},
{
@ -131,7 +131,6 @@ EOF
)
fn_print_dots "Sending Slack alert"
slacksend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${slackwebhook}")
if [ "${slacksend}" == "ok" ]; then

2
lgsm/functions/alert_telegram.sh

@ -11,7 +11,7 @@ json=$(cat <<EOF
{
"chat_id": "${telegramchatid}",
"parse_mode": "HTML",
"text": "<b>${alertemoji} ${alertsubject} ${alertemoji}</b>\n\n<b>Server name</b>\n${servername}\n\n<b>Message</b>\n${alertbody}\n\n<b>Game</b>\n${gamename}\n\n<b>Server IP</b>\n<a href='https://www.gametracker.com/server_info/${alertip}:${port}'>${alertip}:${port}</a>\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>More info</b>\n<a href='${alerturl}'>${alerturl}</a>",
"text": "<b>${alertemoji} ${alerttitle} ${alertemoji}</b>\n\n<b>Server name</b>\n${servername}\n\n<b>Trigger Message</b>\n${alerttriggermessage}\n\n<b>Game</b>\n${gamename}\n\n<b>Current Players</b>\n${alertplayers}\n\n<b>Map</b>\n${alertmap}\n\n<b>Server IP</b>\n${alertip}:${port}\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>Version</b>\n${alertversion}\n\n<b>More info</b>\n${alerturl}",
"disable_web_page_preview": "yes"
}
EOF

21
lgsm/functions/info_messages.sh

@ -59,20 +59,29 @@ fn_info_message_head(){
echo -e ""
echo -e "${lightyellow}Alert Summary${default}"
fn_messages_separator
echo -e "Message"
echo -e "${alertmessage}"
echo -e "Server name"
echo -e "${servername}"
echo -e ""
echo -e "Trigger Message"
echo -e "${alerttriggermessage}"
echo -e ""
echo -e "Game"
echo -e "${gamename}"
echo -e ""
echo -e "Server name"
echo -e "${servername}"
echo -e "Current Players"
echo -e "${alertplayers}"
echo -e ""
echo -e "Map"
echo -e "${alertmap}"
echo -e ""
echo -e "Server IP"
echo -e "${alertip}:${port}"
echo -e ""
echo -e "Hostname"
echo -e "${HOSTNAME}"
echo -e ""
echo -e "Server IP"
echo -e "${ip}:${port}"
echo -e "Version"
echo -e "${alertversion}"
}
fn_info_message_distro(){

Loading…
Cancel
Save