diff --git a/lgsm/functions/command_email_test.sh b/lgsm/functions/command_comms_check.sh similarity index 54% rename from lgsm/functions/command_email_test.sh rename to lgsm/functions/command_comms_check.sh index 9ef90bae5..6caafe777 100644 --- a/lgsm/functions/command_email_test.sh +++ b/lgsm/functions/command_comms_check.sh @@ -6,16 +6,15 @@ lgsm_version="271215" # Description: Sends a test email notification. -local modulename="Email" +local modulename="Comms Check" function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" check.sh info_config.sh -if [ "${emailnotification}" = "on" ]; then - fn_scriptlog "Sending test notification" - subject="${servicename} Email Test Notification - Testing ${servername}" - failurereason="Testing ${servicename} email notification" - actiontaken="Sent test email...hello is this thing on?" - email.sh +if [ "${emailnotification}" = "on" ]||[ "${pushbulletnotification}" = "on" ]; then + fn_scriptlog "Sending Comms Check" + commssubject="LGSM - Comms Check -${servername}" + commsbody="LGSM testing comms, how you read?" + comms.sh else fn_print_fail_nl "Notifications not enabled" fn_scriptlog "Notifications not enabled" diff --git a/lgsm/functions/command_monitor.sh b/lgsm/functions/command_monitor.sh index 66924d307..cb7c51d25 100644 --- a/lgsm/functions/command_monitor.sh +++ b/lgsm/functions/command_monitor.sh @@ -40,10 +40,9 @@ fn_monitor_msg_checking(){ fn_monitor_email_notification(){ # Email will be sent if enabled if [ "${emailnotification}" = "on" ]; then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process not running" - actiontaken="${servicename} has been restarted" - email.sh + commssubject="LGSM - Restarted - ${servername}" + commsbody="${servicename} process not running" + comms.sh fi } diff --git a/lgsm/functions/comms.sh b/lgsm/functions/comms.sh new file mode 100644 index 000000000..ed1172cea --- /dev/null +++ b/lgsm/functions/comms.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# LGSM comms.sh function +# Author: Daniel Gibbs +# Website: https://gameservermanagers.com +lgsm_version="140516" + +# Description: Overall function for managing notifications. + +if [ "${emailnotification}" == "on" ]; then + comms_email.sh +fi + +if [ "${pushbulletnotification}" == "on" ]; then + comms_pushbullet.sh +fi \ No newline at end of file diff --git a/lgsm/functions/comms_email.sh b/lgsm/functions/comms_email.sh new file mode 100644 index 000000000..30601eb4f --- /dev/null +++ b/lgsm/functions/comms_email.sh @@ -0,0 +1,241 @@ +#!/bin/bash +# LGSM email.sh function +# Author: Daniel Gibbs +# Website: https://gameservermanagers.com +lgsm_version="140516" + +# Description: Sends email notification if monitor picks up a failure. + +local modulename="Email" + + +fn_details_email(){ + # + # Failure reason: Testing bb2-server email notification + # Action Taken: Sent test email...hello is this thing on? + + echo -e "${commsbody}" >> "${emaillog}" +} + + +fn_details_os(){ + # + # Distro Details + # ===================================== + # Distro: Ubuntu 14.04.4 LTS + # Arch: x86_64 + # Kernel: 3.13.0-79-generic + # Hostname: hostname + # tmux: tmux 1.8 + # GLIBC: 2.19 + + { + echo -e "" + echo -e "Distro Details" + echo -e "=================================" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "tmux: ${tmuxv}" + echo -e "GLIBC: ${glibcversion}" + } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" +} + +fn_details_performance(){ + # + # Performance + # ===================================== + # Uptime: 55d, 3h, 38m + # Avg Load: 1.00, 1.01, 0.78 + # + # Mem: total used free + # Physical: 741M 656M 85M + # Swap: 0B 0B 0B + + { + echo -e "" + echo -e "Performance" + echo -e "=================================" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load: ${load}" + echo -e "" + echo -e "Mem: total used free" + echo -e "Physical: ${physmemtotal} ${physmemused} ${physmemfree}" + echo -e "Swap: ${swaptotal} ${swapused} ${swapfree}" + } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" +} + +fn_details_disk(){ + # + # Storage + # ===================================== + # Filesystem: /dev/disk/by-uuid/320c8edd-a2ce-4a23-8c9d-e00a7af2d6ff + # Total: 15G + # Used: 8.4G + # Available: 5.7G + # Serverfiles: 961M + + { + echo -e "" + echo -e "Storage" + echo -e "=================================" + echo -e "Filesystem: ${filesystem}" + echo -e "Total: ${totalspace}" + echo -e "Used: ${usedspace}" + echo -e "Available: ${availspace}" + echo -e "Serverfiles: ${filesdirdu}" + if [ -d "${backupdir}" ]; then + echo -e "Backups: ${backupdirdu}" + fi + } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" +} + + + +fn_details_gameserver(){ + # + # Quake Live Server Details + # ===================================== + # Server name: ql-server + # Server IP: 1.2.3.4:27960 + # RCON password: CHANGE_ME + # Server password: NOT SET + # Slots: 16 + # Status: OFFLINE + + { + echo -e "" + echo -e "${gamename} Server Details" + echo -e "=================================" + # Server name + echo -e "Server name: ${servername}" + + # Server ip + echo -e "Server IP: ${ip}:${port}" + + # Server password + if [ -n "${serverpassword}" ]; then + echo -e "Server password: ********" + fi + + # RCON password + if [ -n "${rconpassword}" ]; then + echo -e "RCON password: ********" + fi + + # Admin password + if [ -n "${adminpassword}" ]; then + echo -e "Admin password: ********" + fi + + # Stats password (Quake Live) + if [ -n "${statspassword}" ]; then + echo -e "Stats password: ********" + fi + + # Slots + if [ -n "${slots}" ]; then + echo -e "Slots: ${slots}" + fi + + # Game mode + if [ -n "${gamemode}" ]; then + echo -e "Game mode: ${gamemode}" + fi + + # Game world + if [ -n "${gameworld}" ]; then + echo -e "Game world: ${gameworld}" + fi + + # Tick rate + if [ -n "${tickrate}" ]; then + echo -e "Tick rate: ${tickrate}" + fi + + # Teamspeak dbplugin + if [ -n "${dbplugin}" ]; then + echo -e "dbplugin: ${dbplugin}" + fi + + # Online status + if [ "${status}" == "0" ]; then + echo -e "Status: OFFLINE" + else + echo -e "Status: ONLINE" + fi + } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" +} + +fn_comms_email_template_logs(){ + { + echo -e "" + echo -e "${servicename} Logs" + echo -e "=================================" + + if [ -n "${scriptlog}" ]; then + echo -e "\nScript log\n===================" + if [ ! "$(ls -A ${scriptlogdir})" ]; then + echo "${scriptlogdir} (NO LOG FILES)" + elif [ ! -s "${scriptlog}" ]; then + echo "${scriptlog} (LOG FILE IS EMPTY)" + else + echo "${scriptlog}" + tail -25 "${scriptlog}" + fi + echo "" + fi + + if [ -n "${consolelog}" ]; then + echo -e "\nConsole log\n====================" + if [ ! "$(ls -A ${consolelogdir})" ]; then + echo "${consolelogdir} (NO LOG FILES)" + elif [ ! -s "${consolelog}" ]; then + echo "${consolelog} (LOG FILE IS EMPTY)" + else + echo "${consolelog}" + tail -25 "${consolelog}" | awk '{ sub("\r$", ""); print }' + fi + echo "" + fi + + if [ -n "${gamelogdir}" ]; then + echo -e "\nServer log\n===================" + if [ ! "$(ls -A ${gamelogdir})" ]; then + echo "${gamelogdir} (NO LOG FILES)" + else + echo "${gamelogdir}" + tail "${gamelogdir}"/* | grep -v "==>" | sed '/^$/d' | tail -25 + fi + echo "" + fi + + } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${emaillog}" +} + +fn_print_dots "Sending notification to ${email}" +info_distro.sh +info_config.sh +info_glibc.sh +check_ip.sh + +emaillog="${emaillog}" +if [ -f "${emaillog}" ]; then + rm "${emaillog}" +fi +fn_details_email +fn_details_os +fn_details_performance +fn_details_disk +fn_details_gameserver +fn_comms_email_template_logs +mail -s "${commssubject}" "${email}" < "${emaillog}" +exitcode=$? +if [ "${exitcode}" == "0" ]; then + fn_print_ok_nl "Sending notification to ${email}" + fn_scriptlog "Success! Sending notification to ${email}" +else + fn_print_fail_nl "Sending notification to ${email}" + fn_scriptlog "Failure! Sending notification to ${email}" +fi \ No newline at end of file diff --git a/lgsm/functions/comms_pushbullet.sh b/lgsm/functions/comms_pushbullet.sh new file mode 100644 index 000000000..3ff45e55d --- /dev/null +++ b/lgsm/functions/comms_pushbullet.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# LGSM comms_pushbullet.sh function +# Author: Daniel Gibbs +# Website: https://gameservermanagers.com +lgsm_version="140516" + +# Description: Notifications using pushbullet. + +fn_comms_pushbullet() { + PUSHBULLET_TOKEN="userTokenHere"; + curl -u """$pushbullettoken"":" -d type="note" -d body="${commsbody}" -d title="${commstitle}" 'https://api.pushbullet.com/v2/pushes' >/dev/null 2>&1 + echo "Message send to pushbullet."; +} + +pushbulletnotification="on" +pushbullettoken="" +commsbody="${servicename} process not running" +fn_comms_pushbullet \ No newline at end of file diff --git a/lgsm/functions/core_functions.sh b/lgsm/functions/core_functions.sh index 1598157b5..e46fe897f 100644 --- a/lgsm/functions/core_functions.sh +++ b/lgsm/functions/core_functions.sh @@ -2,7 +2,7 @@ # LGSM core_functions.sh function # Author: Daniel Gibbs # Website: https://gameservermanagers.com -lgsm_version="060516" +lgsm_version="140516" # Description: Defines all functions to allow download and execution of functions using fn_fetch_function. # This function is called first before any other function. Without this file other functions would not load. @@ -19,6 +19,7 @@ functionfile="${FUNCNAME}" fn_fetch_function } + # fn_fetch_core_dl also placed here to allow legecy servers to still download core functions if [ -z "${lgsmdir}" ]; then lgsmdir="${rootdir}/lgsm" @@ -92,6 +93,7 @@ functionfile="${FUNCNAME}" fn_fetch_core_dl } + # Command command_console.sh(){ @@ -109,7 +111,7 @@ functionfile="${FUNCNAME}" fn_fetch_function } -command_email_test.sh(){ +command_comms_check.sh(){ functionfile="${FUNCNAME}" fn_fetch_function } @@ -329,9 +331,20 @@ functionfile="${FUNCNAME}" fn_fetch_function } -# Email -email.sh(){ +# Comms + +comms.sh(){ +functionfile="${FUNCNAME}" +fn_fetch_function +} + +comms_email.sh(){ +functionfile="${FUNCNAME}" +fn_fetch_function +} + +comms_pushbullet.sh(){ functionfile="${FUNCNAME}" fn_fetch_function } @@ -351,6 +364,7 @@ functionfile="${FUNCNAME}" fn_fetch_function } + # Update update_check.sh(){ @@ -462,6 +476,7 @@ functionfile="${FUNCNAME}" fn_fetch_function } + # Calls on-screen messages core_messages.sh diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index 0d115ffaa..f4bb7e9a6 100644 --- a/lgsm/functions/core_getopt.sh +++ b/lgsm/functions/core_getopt.sh @@ -25,8 +25,8 @@ case "$getopt" in command_validate.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; dt|details) command_details.sh;; b|backup) @@ -58,7 +58,7 @@ case "$getopt" in echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mvalidate\t\e[0mv |Validate server files with SteamCMD." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mdetails\t\e[0mdt |Displays useful infomation about the server." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." echo -e "\e[34mconsole\t\e[0mc |Console allows you to access the live view of a server." @@ -84,8 +84,8 @@ case "$getopt" in command_update_functions.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; dt|details) command_details.sh;; b|backup) @@ -113,7 +113,7 @@ case "$getopt" in echo -e "\e[34mupdate\t\e[0mu |Checks and applies updates from SteamCMD." echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mdetails\t\e[0mdt |Displays useful infomation about the server." echo -e "\e[34mchange-password\t\e[0mpw |Changes TS3 serveradmin password." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." @@ -136,8 +136,8 @@ case "$getopt" in command_update_functions.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; b|backup) command_backup.sh;; dev|dev-debug) @@ -160,7 +160,7 @@ case "$getopt" in echo -e "\e[34mrestart\t\e[0mr |Restart the server." echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." echo -e "\e[34mconsole\t\e[0mc |Console allows you to access the live view of a server." echo -e "\e[34mdebug\t\e[0md |See the output of the server directly to your terminal." @@ -188,8 +188,8 @@ case "$getopt" in command_validate.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; dt|details) command_details.sh;; b|backup) @@ -223,7 +223,7 @@ case "$getopt" in echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mvalidate\t\e[0mv |Validate server files with SteamCMD." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mdetails\t\e[0mdt |Displays useful infomation about the server." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." echo -e "\e[34mconsole\t\e[0mc |Console allows you to access the live view of a server." @@ -248,8 +248,8 @@ case "$getopt" in command_update_functions.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; dt|details) command_details.sh;; b|backup) @@ -280,7 +280,7 @@ case "$getopt" in echo -e "\e[34mrestart\t\e[0mr |Restart the server." echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mdetails\t\e[0mdt |Displays useful infomation about the server." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." echo -e "\e[34mconsole\t\e[0mc |Console allows you to access the live view of a server." @@ -313,8 +313,8 @@ case "$getopt" in command_validate.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; dt|details) command_details.sh;; b|backup) @@ -348,7 +348,7 @@ case "$getopt" in echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mvalidate\t\e[0mv |Validate server files with SteamCMD." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mdetails\t\e[0mdt |Displays useful infomation about the server." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." echo -e "\e[34mconsole\t\e[0mc |Console allows you to access the live view of a server." @@ -374,8 +374,8 @@ case "$getopt" in command_update_functions.sh;; m|monitor) command_monitor.sh;; - et|email-test) - command_email_test.sh;; + et|comms-check) + command_comms_check.sh;; dt|details) command_details.sh;; b|backup) @@ -408,7 +408,7 @@ case "$getopt" in echo -e "\e[34mrestart\t\e[0mr |Restart the server." echo -e "\e[34mupdate-functions\t\e[0muf |Removes all functions so latest can be downloaded." echo -e "\e[34mmonitor\t\e[0mm |Checks that the server is running." - echo -e "\e[34memail-test\t\e[0met |Sends test monitor email." + echo -e "\e[34mcomms-check\t\e[0met |Sends test notification." echo -e "\e[34mdetails\t\e[0mdt |Displays useful infomation about the server." echo -e "\e[34mbackup\t\e[0mb |Create archive of the server." echo -e "\e[34mconsole\t\e[0mc |Console allows you to access the live view of a server." diff --git a/lgsm/functions/email.sh b/lgsm/functions/email.sh deleted file mode 100644 index b1585a242..000000000 --- a/lgsm/functions/email.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash -# LGSM email.sh function -# Author: Daniel Gibbs -# Website: https://gameservermanagers.com -lgsm_version="240416" - -# Description: Sends email notification if monitor picks up a failure. - -local modulename="Email" -fn_print_dots "Sending notification to ${email}" -info_distro.sh -info_config.sh -check_ip.sh -if [ $(type -t fn_parms;echo $?) == 0 ]; then - fn_parms -fi -{ - echo -e "========================================\n${servicename} details\n========================================" - echo -e "Service name: ${servicename}" - echo -e "Server name: ${servername}" - echo -e "Game name: ${gamename}" - echo -e "Server IP: ${ip}:${port}" - echo -e "Failure reason: ${failurereason}" - echo -e "Action Taken: ${actiontaken}\n" - echo -e "" - echo -e "========================================\nDistro Details\n========================================" - echo -e "Date: $(date)" - echo -e "Distro: ${os}" - echo -e "Arch: ${arch}" - echo -e "Kernel: ${kernel}" - echo -e "Hostname: $HOSTNAME" - echo -e "tmux: ${tmuxv}" - echo -e "GLIBC: ${glibcversion}" - echo -e "" - echo -e "========================================\nPerformance\n========================================" - echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" - echo -e "Avg Load: ${load}" - echo -e "" - echo -e "Mem: total used free" - echo -e "Physical: ${physmemtotal} ${physmemused} ${physmemfree}" - echo -e "Swap: ${swaptotal}${swapused} ${swapfree}" - echo -e "" - echo -e "========================================\nStorage\n========================================" - echo -e "\e[34mFilesystem:\t\e[0m${filesystem}" - echo -e "\e[34mTotal:\t\e[0m${totalspace}" - echo -e "\e[34mUsed:\t\e[0m${usedspace}" - echo -e "\e[34mAvailable:\t\e[0m${availspace}" - echo -e "\e[34mServerfiles:\t\e[0m${filesdirdu}" - if [ -d "${backupdir}" ]; then - echo -e "\e[34mBackups:\t\e[0m${backupdirdu}" - fi - echo -e "" - echo -e "========================================\nLogs\n========================================" -}| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 -echo -e "\n\n Script log\n===================" >> "${emaillog}" -tail -25 "${scriptlog}" >> "${emaillog}" -if [ -n "${consolelog}" ]; then - echo -e "\n\n Console log\n====================" >> "${emaillog}" - tail -25 "${consolelog}" | awk '{ sub("\r$", ""); print }' >> "${emaillog}" -fi -if [ -n "${gamelogdir}" ]; then - echo -e "\n\n Server log\n====================" >> "${emaillog}" - tail "${gamelogdir}"/* | grep -v "==>" | sed '/^$/d' | tail -25 >> "${emaillog}" -fi -mail -s "${subject}" ${email} < "${emaillog}" -fn_print_ok_nl "Sending notification to ${email}" -fn_scriptlog "Sent notification to ${email}" \ No newline at end of file diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh index 60fa071c4..e1e7ee5d7 100644 --- a/lgsm/functions/install_config.sh +++ b/lgsm/functions/install_config.sh @@ -33,7 +33,7 @@ fn_userinputconfig(){ sleep 1 } - fn_arma3config(){ +fn_arma3config(){ fn_defaultconfig echo "creating ${networkcfg} config file." cp -v "${networkcfgdefault}" "${networkcfgfullpath}" diff --git a/lgsm/functions/monitor_gsquery.sh b/lgsm/functions/monitor_gsquery.sh index 621afe998..aae83f782 100644 --- a/lgsm/functions/monitor_gsquery.sh +++ b/lgsm/functions/monitor_gsquery.sh @@ -68,12 +68,12 @@ if [ "${gsquery}" == "yes" ]; then fn_scriptlog "Querying port: ${ip}:${port} : ${queryattempt} : FAIL" sleep 1 - # Send email notification if enabled + # Send notification if enabled if [ "${emailnotification}" == "on" ]; then subject="${servicename} Monitor - Starting ${servername}" failurereason="Failed to query ${servicename}: ${gsquerycmd}" actiontaken="restarted ${servicename}" - email.sh + comms.sh fi fn_restart break