Update dsmon.sh

This commit is contained in:
2023-01-02 11:05:29 -06:00
parent c6e515bc2f
commit bad0123c67

154
dsmon.sh
View File

@@ -111,82 +111,88 @@ CHECK(){
checkhost=$(CHECK_HOST ${host_ip[$hostid]}) checkhost=$(CHECK_HOST ${host_ip[$hostid]})
if [ "${checkhost}" != "false" ]; then 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 }')
DRIVEINFO=(${DRIVEINFO})
# for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done echo ${host_limits[${hostid}]}
NUMDRIVES=$((${#DRIVEINFO[@]} / 3)) # 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 }')
declare -A DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER # DRIVEINFO=(${DRIVEINFO})
declare -a DRIVES #
# # for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do #
ii=$((${i}*3)) # NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
dname=${DRIVEINFO[${ii}]} # declare -A DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER
dname=${dname//\/dev\/mapper\//} # declare -a DRIVES
dname=${dname//\/dev\//} #
# for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
if [ "${dname}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then # ii=$((${i}*3))
systempartition=true # dname=${DRIVEINFO[${ii}]}
elif [ "${dname}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then # dname=${dname//\/dev\/mapper\//}
systempartition=true # dname=${dname//\/dev\//}
elif [ "${dname}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then #
systempartition=true # if [ "${dname}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
elif [ "${dname}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then # systempartition=true
systempartition=true # elif [ "${dname}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
elif [ "${dname}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then # systempartition=true
systempartition=true # elif [ "${dname}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
else # systempartition=true
dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10") # elif [ "${dname}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10") # systempartition=true
dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100)) # elif [ "${dname}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
# systempartition=true
DRIVEINFO_TOT[$dname]=$dtot # else
DRIVEINFO_FREE[$dname]=$dfree # dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
DRIVEINFO_FREEPER[$dname]=$dfreeper # dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
DRIVES+=("$dname") # dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100))
fi #
done # DRIVEINFO_TOT[$dname]=$dtot
# DRIVEINFO_FREE[$dname]=$dfree
IFS=$'\n' DRIVES=($(sort <<<"${DRIVES[*]}")); unset IFS # DRIVEINFO_FREEPER[$dname]=$dfreeper
# DRIVES+=("$dname")
# for x in "${!DRIVEINFO_TOT[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_TOT[$x]}" ; done # fi
# echo # done
# for x in "${!DRIVEINFO_FREE[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREE[$x]}" ; done #
# echo # IFS=$'\n' DRIVES=($(sort <<<"${DRIVES[*]}")); unset IFS
# for x in "${!DRIVEINFO_FREEPER[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREEPER[$x]}" ; done #
# echo # # for x in "${!DRIVEINFO_TOT[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_TOT[$x]}" ; done
# # echo
for DRIVE in "${DRIVES[@]}"; do # # for x in "${!DRIVEINFO_FREE[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREE[$x]}" ; done
if (( $(bc <<<"${DRIVEINFO_FREEPER[$DRIVE]} <= 15") )); then # # echo
fs_status='error' # # for x in "${!DRIVEINFO_FREEPER[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREEPER[$x]}" ; done
fs_status_color='Red' # # echo
#if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]} GB free\t$(date)" | mail -s "Free Space Critical: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi #
# for DRIVE in "${DRIVES[@]}"; do
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${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]} GB free\t$(date)" | mail -s "Free Space Warning: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi # if (( $(bc <<<"${DRIVEINFO_FREEPER[$DRIVE]} <= 15") )); then
# fs_status='error'
else # fs_status_color='Red'
fs_status='' # #if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]} GB free\t$(date)" | mail -s "Free Space Critical: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi
fs_status_color='Green' #
fi # elif (( $(bc <<<"$dfreeper <= 25") )); then
# fs_status='warn'
c=0; cw=40; spcA='' # fs_status_color='Yellow'
spc1=`expr ${cw} - ${#DRIVE}` # #if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]} GB free\t$(date)" | mail -s "Free Space Warning: '${host_name[$hostid]}'" ${ALERT_EMAIL}; fi
until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done #
# else
c=0; cw=10; spcB='' # fs_status=''
spc2=`expr ${cw} - ${#DRIVEINFO_FREE[$DRIVE]}` # fs_status_color='Green'
until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done # fi
#
c=0; cw=8; spcC='' # c=0; cw=40; spcA=''
spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}` # spc1=`expr ${cw} - ${#DRIVE}`
until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done # until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
#
echo -e "${idsCL[Cyan]} ${DRIVE}${spcA}:${idsCL[$fs_status_color]} ${DRIVEINFO_FREE[$DRIVE]} GB Free${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}(${DRIVEINFO_TOT[$DRIVE]} GB Total)${idsCL[Default]}" # c=0; cw=10; spcB=''
done # spc2=`expr ${cw} - ${#DRIVEINFO_FREE[$DRIVE]}`
# until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
#
# c=0; cw=8; spcC=''
# spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}`
# until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done
#
# echo -e "${idsCL[Cyan]} ${DRIVE}${spcA}:${idsCL[$fs_status_color]} ${DRIVEINFO_FREE[$DRIVE]} GB Free${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}(${DRIVEINFO_TOT[$DRIVE]} GB Total)${idsCL[Default]}"
# done
unset DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER DRIVES DRIVEINFO unset DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER DRIVES DRIVEINFO