Update dsmon.sh

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

164
dsmon.sh
View File

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