Files
Misc-Scripts/install-dsmon.sh

77 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Wrapper script for install, for easier execution via URL.
source /dev/stdin <<< "$(curl -sL http://scity.xyz/colorsinc)"
source /dev/stdin <<< "$(curl -sL http://scity.xyz/defaultinc)"
echo ""
echo -e "${idsCL[LightGreen]}DiskSpace-Monitor Installation Script${idsCL[Default]}"
do_with_root $APTFUNC -y install wget curl git mailutils
do_with_root set -eu
do_with_root git clone https://git.schroedercity.com/voltron/dsmon.git /opt/idssys/dsmon
do_with_root ln -s /opt/idssys/dsmon/run.sh /usr/local/bin/dsmon
if [ ! -d "/opt/idssys/defaults" ]; then
do_with_root set -eu
do_with_root git clone https://git.schroedercity.com/voltron/iDS-Defaults.git /opt/idssys/defaults
fi
if [ ! -d "/opt/idssys/settings" ]; then
do_with_root mkdir /opt/idssys/settings
fi
TOTALSPACE=$(df / | grep / | awk '{ print $2}')
TOTALSPACE=$(bc <<< "scale=2; $TOTALSPACE/1024/1024")
THRESHOLDSPACE=$(bc <<< "scale=2; $TOTALSPACE*.8")
echo -e "${idsCL[LightCyan]}Root drive size: ${idsCL[LightGreen]}"$TOTALSPACE"GB${idsCL[Default]}"
echo -e "${idsCL[LightCyan]}Default thresholf of 80%: ${idsCL[LightGreen]}"$THRESHOLDSPACE"GB${idsCL[Default]}"
echo -e -n "${idsCL[LightCyan]}What threshold should we set? Default=80: ${idsCL[Default]}"
read SET_THRESHOLD
echo ""
echo -e -n "${idsCL[LightCyan]}Email address to receive alerts: ${idsCL[Default]}"
read SET_ALERTEMAIL
echo ""
echo -e -n "${idsCL[LightCyan]}Server Monitor ID (optional): ${idsCL[Default]}"
read SET_SERVERMONID
echo ""
if [ "${SET_THRESHOLD}" = "" ]; then
SET_THRESHOLD=80
fi
echo -e "${idsCL[Yellow]}Sending test Alert... ${idsCL[Default]}"
echo "Test Alert" | mail -r DSMon_$(hostname -s)@scity.us -s "Test" $SET_ALERTEMAIL
echo -e "${idsCL[Yellow]}Adding task to crontab... ${idsCL[Default]}"
(crontab -l ; echo "0 */3 * * * /usr/local/bin/dsmon")| crontab -
echo -e "THRESHOLD=${SET_THRESHOLD}
ALERT_EMAIL=${SET_ALERTEMAIL}
SERVERMON_ID=${SET_SERVERMONID}
" > /opt/idssys/dsmon/config.settings.inc
echo -e "
mail -r DSMon-\$(hostname -s)@scity.us -s 'Disk Space Alert' \$ALERT_EMAIL << EOF
Your root partition remaining free space is running low. Used: \$CURRENT%
EOF
echo \"** Low Disk Space Alert Sent **\" >> /opt/idssys/dsmon/diskspace.log
#Add any additionl system specific actions that should occur when a low disk space alert has been triggered
" > /opt/idssys/dsmon/config.actions.inc
echo ""
echo -e "${idsCL[Yellow]}DiskSpace-Monitor has been Installed. Please make sure this system can send emails using the mail command.${idsCL[Default]}"
echo ""
exit 0