From 974bda37c81f7a391c6d3abddd93d76b31d9d2ee Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 2 Jan 2023 10:27:32 -0600 Subject: [PATCH] Update dsmon.sh --- dsmon.sh | 89 ++++++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/dsmon.sh b/dsmon.sh index 7a03b6e..44e3c7c 100755 --- a/dsmon.sh +++ b/dsmon.sh @@ -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