Update dsmon.sh

This commit is contained in:
2025-06-14 10:56:25 -05:00
parent 74c4af039d
commit d9ca2358de

View File

@@ -147,7 +147,9 @@ CHECK(){
NTS=$(grep -oP '(?<=dscheck\.).*?(?=\.done)' <<< "${host}")
if [ -n "$NTS" ]; then
# echo "'$host' = '$NTS'"
cat -v /tmp/dscheck.${NTS}.results
while IFS= read -r line; do
printf "%s\n" "$line"
done < /tmp/dscheck.${NTS}.results
# printf "%s\n" "$(cat /tmp/dscheck.${NTS}.results)"
cp -f /tmp/dscheck.${NTS}.results /tmp/${NTS}.result
rm -f /tmp/dscheck.${NTS}.* >/dev/null 2>&1
@@ -171,22 +173,14 @@ CHECK(){
echo
}
RUN_CHECK() {
touch /tmp/dscheck.${hostname}.running
echo "Line 1"
echo "Line 2"
echo "Line 3"
mv /tmp/dscheck.${hostname}.running /tmp/dscheck.${hostname}.done
}
RUN_CHECK2(){
RUN_CHECK(){
hostname=${1}
touch /tmp/dscheck.${hostname}.running
hostid=${host_ids[$hostname]}
# if [ "${1}" != "report" ]; then
echo -e "${idsST[Bold]}"; DIVIDER false lightCyan 85
echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}"
DIVIDER false lightCyan 85
# fi
echo -e "${idsST[Bold]}"; DIVIDER false lightCyan 85
echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}"
DIVIDER false lightCyan 85
checkhost=$(CHECK_HOST ${host_ip[$hostid]})
if [ "${checkhost}" != "false" ]; then
@@ -201,8 +195,6 @@ RUN_CHECK2(){
DRIVEINFO=$(${SSHCMD} root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|localhost|shm|overlay|-volume|Music|Software|//|AFS|PlexData_VG' | 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 DRIVEINFO_SHORTNAME
declare -a DRIVES
@@ -242,23 +234,12 @@ RUN_CHECK2(){
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
# if [ "${1}" != "report" ]; then
c=0; cw=18; spcA=''; spc1=`expr ${cw} - 7`; until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
c=0; cw=10; spcB=''; spc2=`expr ${cw} - 4`; until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
c=0; cw=10; spcC=''; spc3=`expr ${cw} - 5`; until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done
c=0; cw=14; spcD=''; spc4=`expr ${cw} - 3`; until [ $c = ${spc4} ]; do spcD="${spcD} "; c=`expr $c + 1`; done
echo -e "${idsST[Reset]}${idsCL[White]} DRIVE${spcA} FREE GB${spcB}FREE %${spcC}TOTAL GB${spcD}WARN % / CRIT %${idsCL[Default]}"
# pf="%-20s %10s %10s %12s %50s\n"
# printf "${pf}" "${idsCL[White]}DRIVE" "FREE GB" "FREE %" "TOTAL GB" "WARN % / CRIT %${idsCL[Default]}"
# fi
c=0; cw=18; spcA=''; spc1=`expr ${cw} - 7`; until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
c=0; cw=10; spcB=''; spc2=`expr ${cw} - 4`; until [ $c = ${spc2} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
c=0; cw=10; spcC=''; spc3=`expr ${cw} - 5`; until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done
c=0; cw=14; spcD=''; spc4=`expr ${cw} - 3`; until [ $c = ${spc4} ]; do spcD="${spcD} "; c=`expr $c + 1`; done
echo -e "${idsST[Reset]}${idsCL[White]} DRIVE${spcA} FREE GB${spcB}FREE %${spcC}TOTAL GB${spcD}WARN % / CRIT %${idsCL[Default]}"
for DRIVE in "${DRIVES[@]}"; do
@@ -267,12 +248,10 @@ RUN_CHECK2(){
WARNING_LEVEL=$(printf "%0.2f" $(jq -n 100-${host_limits_tmp[$DRIVE]}))
CRITICAL_LEVEL=$(printf "%0.2f" $(jq -n $WARNING_LEVEL-$WARNING_LEVEL/2))
# if [ "${1}" != "report" ]; then
c=0; cw=18; spcA=''; spc1=`expr ${cw} - ${#DRIVEINFO_SHORTNAME[$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=10; spcC=''; spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}`; until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done
c=0; cw=14; spcD=''; spc4=`expr ${cw} - ${#DRIVEINFO_TOT[$DRIVE]}`; until [ $c = ${spc4} ]; do spcD="${spcD} "; c=`expr $c + 1`; done
# fi
c=0; cw=18; spcA=''; spc1=`expr ${cw} - ${#DRIVEINFO_SHORTNAME[$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=10; spcC=''; spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}`; until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done
c=0; cw=14; spcD=''; spc4=`expr ${cw} - ${#DRIVEINFO_TOT[$DRIVE]}`; until [ $c = ${spc4} ]; do spcD="${spcD} "; c=`expr $c + 1`; done
if (( $(bc <<<"${DRIVEINFO_FREEPER[$DRIVE]} <= ${CRITICAL_LEVEL}") )); then
fs_status='CRITICAL'
@@ -296,16 +275,13 @@ RUN_CHECK2(){
D_WARNING_LEVEL=$(printf "%0.2f" $(jq -n 100-${WARNING_LEVEL}))
D_CRITICAL_LEVEL=$(printf "%0.2f" $(jq -n 100-${CRITICAL_LEVEL}))
# [ "${1}" != "report" ] &&
echo -e "${idsCL[Cyan]} ${DRIVEINFO_SHORTNAME[$DRIVE]}${spcA}${idsCL[$fs_status_color]}${DRIVEINFO_FREE[$DRIVE]} GB${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}${DRIVEINFO_TOT[$DRIVE]} GB${idsST[Reset]}${spcD}${idsCL[Cyan]}( ${idsCL[Yellow]}${D_WARNING_LEVEL}%${idsCL[Cyan]} / ${idsCL[RedBold]}${D_CRITICAL_LEVEL}%${idsST[Reset]}${idsCL[Cyan]} )${idsCL[Default]}"
# [ "${1}" != "report" ] && printf "${pf}" "${idsCL[Cyan]}${DRIVEINFO_SHORTNAME[$DRIVE]}" "${idsCL[$fs_status_color]}${DRIVEINFO_FREE[$DRIVE]} GB" "${DRIVEINFO_FREEPER[$DRIVE]}%" "${DRIVEINFO_TOT[$DRIVE]} GB" "${idsCL[Cyan]}(${idsCL[Default]}${D_WARNING_LEVEL}%${idsCL[Cyan]}/${idsCL[Default]}${D_CRITICAL_LEVEL}%${idsCL[Cyan]})(${idsCL[Yellow]}${D_WARNING_LEVEL}%${idsCL[Cyan]}/${idsCL[Red]}${D_CRITICAL_LEVEL}%${idsCL[Cyan]})${idsCL[Default]}"
if [ "${fs_status}" != "Normal" ] && [ "${1}" == "report" ]; then
# echo -e "${host_name[$hostid]} - (${host_ip[$hostid]})\n\n${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]}GB out of ${DRIVEINFO_TOT[$DRIVE]}GB Free (${DRIVEINFO_FREEPER[$DRIVE]}%)\n\n$(date)" | mail -s "Free Space ${fs_status}: '${host_name[$hostid]}'" ${ALERT_EMAIL}
SENDNOTICE "Free Space ${fs_status}: '${host_name[$hostid]}'" "${host_name[$hostid]} - (${host_ip[$hostid]})
${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]}GB out of ${DRIVEINFO_TOT[$DRIVE]}GB Free (${DRIVEINFO_FREEPER[$DRIVE]})percent" ${fs_priority}
${DRIVE} : ${DRIVEINFO_FREE[$DRIVE]}GB out of ${DRIVEINFO_TOT[$DRIVE]}GB Free (${DRIVEINFO_FREEPER[$DRIVE]})percent" ${fs_priority}
fi
done
@@ -323,7 +299,6 @@ RUN_CHECK2(){
fi
else
# [ "${1}" != "report" ] &&
echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}"; echo
fi
mv /tmp/dscheck.${hostname}.running /tmp/dscheck.${hostname}.done