Update dsmon.sh

This commit is contained in:
2023-01-02 10:27:32 -06:00
parent 28078d77ad
commit 974bda37c8

View File

@@ -111,72 +111,65 @@ CHECK(){
checkhost=$(CHECK_HOST ${host_ip[$hostid]})
if [ "${checkhost}" != "false" ]; then
DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|shm|mmcblk|overlay|-volume|Music|media-data|Software' | awk '{ print $1 " " $2 " " $4 }')
for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done
echo
# IFS=$'\n' DRIVEINFO=($(sort <<<"${DRIVEINFO[*]}")); unset IFS
# for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done
# echo
DRIVEINFO=(${DRIVEINFO})
NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
declare -A DRIVE_INFO
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
ii=$((${i}*3))
dname=${DRIVEINFO[${ii}]}
dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100))
dname=${dname//\/dev\/mapper\//}
dname=${dname//\/dev\//}
if [ "${ia}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
if [ "${dname}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
elif [ "${dname}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
elif [ "${dname}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
elif [ "${dname}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
elif [ "${ia}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
elif [ "${dname}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
systempartition=true
else
systempartition=false
fi
if [ $systempartition = false ]; then
if (( $(bc <<<"$dfreeper <= 15") )); then
fs_status='error'
fs_status_color='Red'
#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
elif (( $(bc <<<"$dfreeper <= 25") )); then
fs_status='warn'
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 Warning: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi
else
fs_status=''
fs_status_color='Green'
fi
c=0; cw=40; spcA=''
spc1=`expr ${cw} - ${#dname}`
until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
c=0; cw=12; spcB=''
spc2=`expr ${cw} - ${#dfree}`
until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
echo -e "${idsCL[$fs_status_color]} ${dname}${spcA}: ${dfree} GB Free${spcB}${dfreeper}%${idsCL[Default]}"
dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100))
DRIVE_INFO[$dname][dtot]=$dtot
DRIVE_INFO[$dname][dfree]=$dfree
DRIVE_INFO[$dfreeper][dtot]=$dfreeper
fi
done
for x in "${!DRIVE_INFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVE_INFO[$x]}" ; done
# if (( $(bc <<<"$dfreeper <= 15") )); then
# fs_status='error'
# fs_status_color='Red'
# #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
#
# elif (( $(bc <<<"$dfreeper <= 25") )); then
# fs_status='warn'
# 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 Warning: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi
#
# else
# fs_status=''
# fs_status_color='Green'
# fi
#
# c=0; cw=40; spcA=''
# spc1=`expr ${cw} - ${#dname}`
# until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
#
# c=0; cw=12; spcB=''
# spc2=`expr ${cw} - ${#dfree}`
# until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
#
# echo -e "${idsCL[$fs_status_color]} ${dname}${spcA}: ${dfree} GB Free${spcB}${dfreeper}%${idsCL[Default]}"
else
echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}"
fi