Update install-dsmon.sh

This commit is contained in:
2022-03-18 23:21:41 -05:00
parent b16977141a
commit 045ab5a5af

View File

@@ -7,6 +7,16 @@ source /dev/stdin <<< "$(curl -sL http://scity.xyz/defaultinc)"
echo ""
echo -e "${idsCL[LightGreen]}DiskSpace-Monitor Installation Script${idsCL[Default]}"
echo ""
if [ -d "/opt/idssys/dsmon" ]; then
echo -en "${idsCL[Red]}DiskSpace-Monitor is already installed, would you like to re-install (y/n)?${idsCL[Default]}"
read -n 1 reinstall
case $reinstall in
[Yy]) `bash <(curl -sL https://scity.xyz/uninstall-dsmon)`;;
*) EXIT1;;
esac
fi
do_with_root $APTFUNC install wget curl git mailutils mariadb-client bc
@@ -19,20 +29,49 @@ if [ ! -d "/opt/idssys/defaults" ]; then
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
#touch /opt/idssys/dsmon/config.settings.inc
echo -e "declare -A THRESHOLD" > /opt/idssys/dsmon/config.settings.inc
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]}"
DRIVEINFO=`df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev' | awk '{ print $1 " " $2 " " $4 }' | sed 's/M//g'`
DRIVEINFO=(${DRIVEINFO})
NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
echo -e -n "${idsCL[LightCyan]}What threshold should we set? Default=80: ${idsCL[Default]}"
read SET_THRESHOLD
echo ""
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
ii=$((${i}*3))
ia=${DRIVEINFO[${ii}]}
ib=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024")
ic=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024")
ia=${ia//\/dev\/mapper\//}
ia=${ia//\/dev\//}
if [ "${ia}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]} -lt 1024 ]; then
systempartition=true
else
#echo "${ia};${ib};${ic}"
THRESHOLDSPACE=$(bc <<< "scale=2; $TOTALSPACE*.8")
echo -e "${idsCL[LightCyan]}(${ia}) total size: ${idsCL[LightGreen]}${ib}GB${idsCL[Default]}"
echo -e "${idsCL[LightCyan]}Using the default threshold of 80% would alert at: ${idsCL[LightGreen]}${THRESHOLDSPACE}GB${idsCL[Default]}"
echo -e -n "${idsCL[LightCyan]}What threshold should we set for this drive? Default=80: ${idsCL[Default]}"
read SET_THRESHOLD
echo ""
if [ "${SET_THRESHOLD}" = "" ]; then
SET_THRESHOLD=80
fi
echo -e "THRESHOLD['${ia}']=${SET_THRESHOLD}" >> /opt/idssys/dsmon/config.settings.inc
fi
done
echo -e -n "${idsCL[LightCyan]}Email address to receive alerts: ${idsCL[Default]}"
read SET_ALERTEMAIL
@@ -72,9 +111,6 @@ if [ "${SET_SERVERMONID}" = "new" ]; then
fi
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
@@ -82,7 +118,7 @@ echo "Test Alert" | mail -r DSMon_$(hostname -s)@scity.us -s "Test" $SET_ALERTEM
echo -e "${idsCL[Yellow]}Adding task to crontab... ${idsCL[Default]}"
(crontab -l ; echo "$(($RANDOM % 15)) */1 * * * /usr/local/bin/dsmon")| crontab -
echo -e "THRESHOLD=${SET_THRESHOLD}
echo -e "
ALERT_EMAIL=${SET_ALERTEMAIL}
SERVERMON_ID=${SET_SERVERMONID//id
/}