Update dsmon.sh

This commit is contained in:
2023-01-02 11:20:25 -06:00
parent 4327d2b2e1
commit 29f04e27cb

162
dsmon.sh
View File

@@ -119,88 +119,88 @@ CHECK(){
host_limits_tmp[$hlname]=$hllim host_limits_tmp[$hlname]=$hllim
done done
echo 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 "${!host_limits_tmp[@]}"; do printf "[%s]=%s\n" "$x" "${host_limits_tmp[$x]}" ; done DRIVEINFO=(${DRIVEINFO})
# 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
# DRIVEINFO=(${DRIVEINFO})
# NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
# # for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done declare -A DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER
# declare -a DRIVES
# NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
# declare -A DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
# declare -a DRIVES ii=$((${i}*3))
# dname=${DRIVEINFO[${ii}]}
# for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do dname=${dname//\/dev\/mapper\//}
# ii=$((${i}*3)) dname=${dname//\/dev\//}
# dname=${DRIVEINFO[${ii}]}
# dname=${dname//\/dev\/mapper\//} if [ "${dname}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
# dname=${dname//\/dev\//} systempartition=true
# elif [ "${dname}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
# if [ "${dname}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then systempartition=true
# systempartition=true elif [ "${dname}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
# elif [ "${dname}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then systempartition=true
# systempartition=true elif [ "${dname}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
# elif [ "${dname}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then systempartition=true
# systempartition=true elif [ "${dname}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
# elif [ "${dname}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then systempartition=true
# systempartition=true else
# elif [ "${dname}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
# systempartition=true dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
# else dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100))
# dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
# dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10") DRIVEINFO_TOT[$dname]=$dtot
# dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100)) DRIVEINFO_FREE[$dname]=$dfree
# DRIVEINFO_FREEPER[$dname]=$dfreeper
# DRIVEINFO_TOT[$dname]=$dtot DRIVES+=("$dname")
# DRIVEINFO_FREE[$dname]=$dfree fi
# DRIVEINFO_FREEPER[$dname]=$dfreeper done
# DRIVES+=("$dname")
# fi IFS=$'\n' DRIVES=($(sort <<<"${DRIVES[*]}")); unset IFS
# done
# # for x in "${!DRIVEINFO_TOT[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_TOT[$x]}" ; done
# IFS=$'\n' DRIVES=($(sort <<<"${DRIVES[*]}")); unset IFS # echo
# # for x in "${!DRIVEINFO_FREE[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREE[$x]}" ; done
# # for x in "${!DRIVEINFO_TOT[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_TOT[$x]}" ; done # echo
# # echo # for x in "${!DRIVEINFO_FREEPER[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREEPER[$x]}" ; done
# # for x in "${!DRIVEINFO_FREE[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREE[$x]}" ; done # echo
# # echo
# # for x in "${!DRIVEINFO_FREEPER[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREEPER[$x]}" ; done for DRIVE in "${DRIVES[@]}"; do
# # echo
# WARNING_LEVEL=$(expr 100 - ${host_limits_tmp[$DRIVE]})
# for DRIVE in "${DRIVES[@]}"; do CRITICAL_LEVEL=$(printf "%0.2f" $(jq -n $WARNING_LEVEL-($WARNING_LEVEL/2)))
#
# echo "warn=$WARNING_LEVEL - crit=$CRITICAL_LEVEL"
#
# if (( $(bc <<<"${DRIVEINFO_FREEPER[$DRIVE]} <= 15") )); then if (( $(bc <<<"${DRIVEINFO_FREEPER[$DRIVE]} <= 15") )); then
# fs_status='error' fs_status='error'
# fs_status_color='Red' fs_status_color='Red'
# #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 #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
#
# elif (( $(bc <<<"$dfreeper <= 25") )); then elif (( $(bc <<<"$dfreeper <= 25") )); then
# fs_status='warn' fs_status='warn'
# fs_status_color='Yellow' 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 [ "${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
#
# else else
# fs_status='' fs_status=''
# fs_status_color='Green' fs_status_color='Green'
# fi fi
#
# c=0; cw=40; spcA='' c=0; cw=40; spcA=''
# spc1=`expr ${cw} - ${#DRIVE}` spc1=`expr ${cw} - ${#DRIVE}`
# until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
#
# c=0; cw=10; spcB='' c=0; cw=10; spcB=''
# spc2=`expr ${cw} - ${#DRIVEINFO_FREE[$DRIVE]}` spc2=`expr ${cw} - ${#DRIVEINFO_FREE[$DRIVE]}`
# until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
#
# c=0; cw=8; spcC='' c=0; cw=8; spcC=''
# spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}` spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}`
# until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done 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]}" 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 done
unset DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER DRIVES DRIVEINFO host_limits_tmp unset DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER DRIVES DRIVEINFO host_limits_tmp