Update dsmon.sh

This commit is contained in:
2023-01-02 09:12:58 -06:00
parent 5d7e0d6249
commit 7bffae4848

View File

@@ -95,53 +95,57 @@ CHECK(){
fi fi
done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts") done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts")
for hostid in "${!host_ip[@]}"; do
echo -e "${idsST[Bold]}"; DIVIDER for x in "${!host_name[@]}"; do printf "[%s]=%s\n" "$x" "${host_name[$x]}" ; done
echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}"
DIVIDER; echo -e "${idsST[Reset]}"
# for hostid in "${!host_ip[@]}"; do
checkhost=$(CHECK_HOST ${host_ip[$hostid]}) # echo -e "${idsST[Bold]}"; DIVIDER
if [ "${checkhost}" != "false" ]; then # echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}"
DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|sda|sdb|shm|mmcblk|overlay|-volume|Music|media-data|Software' | awk '{ print $1 " " $2 " " $4 }') # DIVIDER; echo -e "${idsST[Reset]}"
DRIVEINFO=(${DRIVEINFO}) #
NUMDRIVES=$((${#DRIVEINFO[@]} / 3)) # checkhost=$(CHECK_HOST ${host_ip[$hostid]})
# if [ "${checkhost}" != "false" ]; then
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do # DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|sda|sdb|shm|mmcblk|overlay|-volume|Music|media-data|Software' | awk '{ print $1 " " $2 " " $4 }')
ii=$((${i}*3)) # DRIVEINFO=(${DRIVEINFO})
dname=${DRIVEINFO[${ii}]} # NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10") #
dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10") # for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100)) # ii=$((${i}*3))
dname=${dname//\/dev\/mapper\//} # dname=${DRIVEINFO[${ii}]}
dname=${dname//\/dev\//} # dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
# dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
if (( $(bc <<<"$dfreeper <= 15") )); then # dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100))
fs_status='error' # dname=${dname//\/dev\/mapper\//}
fs_status_color='Red' # dname=${dname//\/dev\//}
if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${dname} : ${dfree} GB free\t$(date)" | mail -s "Free Space Critical: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi #
# if (( $(bc <<<"$dfreeper <= 15") )); then
elif (( $(bc <<<"$dfreeper <= 25") )); then # fs_status='error'
fs_status='warn' # fs_status_color='Red'
fs_status_color='Yellow' # if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${dname} : ${dfree} GB free\t$(date)" | mail -s "Free Space Critical: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi
if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${dname} : ${dfree} GB free\t$(date)" | mail -s "Free Space Warning: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi #
# elif (( $(bc <<<"$dfreeper <= 25") )); then
else # fs_status='warn'
fs_status='' # fs_status_color='Yellow'
fs_status_color='Green' # if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${dname} : ${dfree} GB free\t$(date)" | mail -s "Free Space Warning: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi
fi #
# else
c=0; cw=30; spc='' # fs_status=''
spc1=`expr ${cw} - ${#dname}` # fs_status_color='Green'
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done # fi
echo -e "${idsCL[$fs_status_color]} ${dname}${spc}: ${dfree}GB Free - ${dfreeper}%${idsCL[Default]}" #
# c=0; cw=30; spc=''
done # spc1=`expr ${cw} - ${#dname}`
# until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
else # echo -e "${idsCL[$fs_status_color]} ${dname}${spc}: ${dfree}GB Free - ${dfreeper}%${idsCL[Default]}"
echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}" #
fi # done
#
done # else
# echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}"
# fi
#
# done
} }
SETUPSSH(){ SETUPSSH(){