From bad0123c6764dd0d5bad477e5eb842a312aab253 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 2 Jan 2023 11:05:29 -0600 Subject: [PATCH] Update dsmon.sh --- dsmon.sh | 154 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 74 deletions(-) diff --git a/dsmon.sh b/dsmon.sh index 42194c5..bdbecfd 100755 --- a/dsmon.sh +++ b/dsmon.sh @@ -111,82 +111,88 @@ 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 }') - DRIVEINFO=(${DRIVEINFO}) - # for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done + echo ${host_limits[${hostid}]} - 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 + # + # + # + # 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