Delete install-dsmon-nosql.sh

This commit is contained in:
2025-06-01 21:31:02 -05:00
parent f0ea6186e6
commit 6a71b855c3

View File

@@ -1,204 +0,0 @@
#!/usr/bin/env bash
if [ -d /opt/idssys/defaults ]; then
source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
else
source /dev/stdin <<< "$(curl -sL http://go.scity.us/colorsinc)"
source /dev/stdin <<< "$(curl -sL http://go.scity.us/defaultinc)"
fi
echo ""
echo -e "${idsCL[LightGreen]}DiskSpace-Monitor Installation Script${idsCL[Default]}"
echo ""
if [ -d "/opt/idssys/dsmon" ]; then
echo -en "${idsCL[Yellow]}DiskSpace-Monitor is already installed, would you like to re-install (y/N)? ${idsCL[Default]}"
read reinstall
case $reinstall in
[Yy])
rm -f /usr/local/bin/dsmon
rm -Rf /opt/idssys/dsmon
;;
*) EXIT1;;
esac
fi
do_with_root $APTFUNC install wget curl git mailutils bc
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
#touch /opt/idssys/dsmon/config.settings.inc
echo -e "declare -A THRESHOLD" > /opt/idssys/dsmon/config.settings.inc
echo ""
DRIVEINFO=$(df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|localhost|shm|overlay|-volume|Music|Software|//|AFS' | awk '{ print $1 " " $2 " " $4 }')
DRIVEINFO=(${DRIVEINFO})
NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
ii=$((${i}*3))
ia=${DRIVEINFO[${ii}]}
ib=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]//M/}/1024")
ic=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]//M/}/1024")
ia=${ia//\/dev\/mapper\//}
ia=${ia//\/dev\//}
if [[ "${ia}" = *"sda"* ]] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [[ "${ia}" = *"nvme"* ]] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [[ "${ia}" = *"mmcblk"* ]] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" != "overlay" ]; then
#echo "${ia};${ib};${ic}"
THRESHOLDSPACE=$(bc <<< "scale=2; ${ib}*.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
echo ""
fi
done
echo -e -n "${idsCL[LightCyan]}Email address to receive alerts: ${idsCL[Default]}"
read SET_ALERTEMAIL
echo ""
if [ "${SET_ALERTEMAIL}" = "push" ]; then
SET_ALERTEMAIL='b3upzaom7a@pomail.net'
elif [ "${SET_ALERTEMAIL}" = "kyle" ]; then
SET_ALERTEMAIL='qk7y2gwrjn@pomail.net'
fi
echo -e -n "${idsCL[LightCyan]}Server Monitor ID (optional, or type 'new'): ${idsCL[Default]}"
read SET_SERVERMONID
echo ""
if [ "${SET_ALERTEMAIL}" != "" ]; then
echo -e "${idsCL[Yellow]}Sending test Alert... ${idsCL[Default]}"
echo "Test Alert" | mail -r DSMon_$(hostname -s)@scity.us -s "Test" ${SET_ALERTEMAIL}
fi
echo -e "${idsCL[Yellow]}Adding task to crontab... ${idsCL[Default]}"
crontab -l | grep -v 'dsmon hdd' | crontab -
crontab -l | grep -v 'dsmon sys' | crontab -
sleep 1s
(crontab -l ; echo "$(($RANDOM % 59)) */1 * * * /usr/local/bin/dsmon run hdd >/dev/null 2>&1")| crontab -
# sleep 1s
# (crontab -l ; echo "*/5+$(($RANDOM % 4)) * * * * /usr/local/bin/dsmon run sys >/dev/null 2>&1")| crontab -
if [ "${SET_SERVERMONID}" = "new" ]; then
hostname=`hostname`
echo -e -n "${idsCL[LightCyan]}Server Name (Default = \"${hostname}\"): ${idsCL[Default]}"
read ADD_SERVERNAME
echo ""
if [ "${ADD_SERVERNAME}" = "" ]; then
ADD_SERVERNAME=${hostname}
fi
source /opt/idssys/dsmon/config.settings.inc
ADD_SERVERHOSTNAME=(`hostname`)
ADD_SERVERIP=(`hostname -I`)
ADD_SERVERIPS=''
for nip in "${ADD_SERVERIP[@]}"; do
if [[ "${nip}" == *"."* ]] && [[ "${nip}" != *"172"* ]]; then
if [ "${ADD_SERVERIPS}" = "" ]; then
SERVERIPS=${nip}
else
SERVERIPS=${ADD_SERVERIPS}";"${nip}
fi
fi
done
thresholdlog=()
for KEY in "${!THRESHOLD[@]}"; do
thresholdlog+=("${KEY}:${THRESHOLD[$KEY]}")
done
if [ "$(CHECK_HOST 10.10.1.50)" != "false" ]; then
mysqlip=10.10.1.50
elif [ "$(CHECK_HOST 100.100.2.2)" != "false" ]; then
mysqlip=100.100.2.2
elif [ "$(CHECK_HOST 10.6.1.5)" != "false" ]; then
mysqlip=10.6.1.5
else
mysqlip=
fi
if [ "${mysqlip}" != "" ]; then
QRY="USE servermonitor; INSERT INTO hosts (\`host\`,\`hostname\`,\`ip\`,\`limits\`) VALUES ('${ADD_SERVERNAME}','${ADD_SERVERHOSTNAME}','${SERVERIPS// /}','${thresholdlog[@]}');"
mariadb --skip-ssl -h ${mysqlip} -u sysmoninsert -psysmoninsert -e "${QRY}"
QRY="USE servermonitor; SELECT id FROM hosts WHERE host='${ADD_SERVERNAME}';"
SET_SERVERMONID=`mariadb --skip-ssl -h ${mysqlip} -u sysmoninsert -psysmoninsert -e "${QRY}"`
else
echo -e "${idsCL[Red]}Could not connect to MySQL${idsCL[Default]}"
fi
echo -en "${idsCL[LightGreen]}Server successfully added, it was given ID# "
echo -e ${SET_SERVERMONID//id
}${idsCL[Default]}
echo ""
fi
echo -e "
#(optional)" >> /opt/idssys/dsmon/config.settings.inc
[ "${SET_ALERTEMAIL}" != "" ] && echo -e "EMAIL_NOTICE=${SET_ALERTEMAIL}" >> /opt/idssys/dsmon/config.settings.inc || echo -e "# EMAIL_NOTICE=email@address.com" >> /opt/idssys/dsmon/config.settings.inc
echo -e "# PUSHOVER_APP_TOKEN=\"atm1fd2fj8b5mopddior57dmrdq8ny\"
# PUSHOVER_USER_TOKEN=\"\"
SERVERMON_ID=${SET_SERVERMONID//id
/}
" >> /opt/idssys/dsmon/config.settings.inc
echo -e "
mail -r DSMon-\$(hostname -s)@scity.us -s 'Disk Space Alert' \${SET_ALERTEMAIL} << 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
/usr/local/bin/dsmon run hdd
# /usr/local/bin/dsmon run sys
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