diff --git a/dsmon.sh b/dsmon.sh index 97c3696..f104679 100755 --- a/dsmon.sh +++ b/dsmon.sh @@ -80,7 +80,7 @@ RUN(){ } CHECK(){ - start=`date +%s` + [ "${1}" != "report" ] && start=`date +%s` declare -A host_ip declare -A host_name @@ -105,9 +105,11 @@ CHECK(){ #for hostid in "${!host_ip[@]}"; do for hostname in "${hostnames_sort[@]}"; do hostid=${host_ids[$hostname]} - echo -e "${idsST[Bold]}"; DIVIDER false lightCyan 100 - echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}" - DIVIDER false lightCyan 100 + if [ "${1}" != "report" ]; then + echo -e "${idsST[Bold]}"; DIVIDER false lightCyan 100 + echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}" + DIVIDER false lightCyan 100 + fi checkhost=$(CHECK_HOST ${host_ip[$hostid]}) if [ "${checkhost}" != "false" ]; then @@ -165,19 +167,21 @@ CHECK(){ # for x in "${!DRIVEINFO_FREEPER[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO_FREEPER[$x]}" ; done # echo - c=0; cw=40; spcA='' - spc1=`expr ${cw} - 5` - 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=12; 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]}" + if [ "${1}" != "report" ]; then + c=0; cw=40; spcA='' + spc1=`expr ${cw} - 5` + 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=12; 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]}" + fi for DRIVE in "${DRIVES[@]}"; do @@ -188,32 +192,34 @@ CHECK(){ WARNING_LEVEL=$(printf "%0.2f" $(jq -n 100-${host_limits_tmp[$DRIVE]})) CRITICAL_LEVEL=$(printf "%0.2f" $(jq -n $WARNING_LEVEL-$WARNING_LEVEL/2)) - c=0; cw=40; spcA='' - spc1=`expr ${cw} - ${#DRIVE}` - until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done + if [ "${1}" != "report" ]; then + 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=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=10; spcC='' + spc3=`expr ${cw} - ${#DRIVEINFO_FREEPER[$DRIVE]}` + until [ $c = ${spc3} ]; do spcC="${spcC} "; c=`expr $c + 1`; done - c=0; cw=12; spcD='' - spc4=`expr ${cw} - ${#DRIVEINFO_TOT[$DRIVE]}` - until [ $c = ${spc4} ]; do spcD="${spcD} "; c=`expr $c + 1`; done + c=0; cw=12; spcD='' + spc4=`expr ${cw} - ${#DRIVEINFO_TOT[$DRIVE]}` + until [ $c = ${spc4} ]; do spcD="${spcD} "; c=`expr $c + 1`; done + fi if (( $(bc <<<"${DRIVEINFO_FREEPER[$DRIVE]} <= ${CRITICAL_LEVEL}") )); then fs_status='error' fs_status_color='Red' - echo -e "${idsCL[Cyan]} ${DRIVE}${spcA}:${idsCL[RedBold]} ${DRIVEINFO_FREE[$DRIVE]} GB${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}${DRIVEINFO_TOT[$DRIVE]} GB${idsST[Reset]}${spcD}${idsCL[Cyan]}( ${idsCL[Yellow]}${WARNING_LEVEL}%${idsCL[Cyan]} / ${idsCL[Red]}${CRITICAL_LEVEL}%${idsCL[Cyan]} )${idsCL[Default]}" + [ "${1}" != "report" ] && echo -e "${idsCL[Cyan]} ${DRIVE}${spcA}:${idsCL[RedBold]} ${DRIVEINFO_FREE[$DRIVE]} GB${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}${DRIVEINFO_TOT[$DRIVE]} GB${idsST[Reset]}${spcD}${idsCL[Cyan]}( ${idsCL[Yellow]}${WARNING_LEVEL}%${idsCL[Cyan]} / ${idsCL[Red]}${CRITICAL_LEVEL}%${idsCL[Cyan]} )${idsCL[Default]}" 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 <= ${WARNING_LEVEL}") )); then fs_status='warn' fs_status_color='Yellow' - echo -e "${idsCL[Cyan]} ${DRIVE}${spcA}:${idsCL[$fs_status_color]} ${DRIVEINFO_FREE[$DRIVE]} GB${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}${DRIVEINFO_TOT[$DRIVE]} GB${spcD}${idsCL[Cyan]}( ${idsCL[Yellow]}${WARNING_LEVEL}%${idsCL[Cyan]} / ${idsCL[Red]}${CRITICAL_LEVEL}%${idsCL[Cyan]} )${idsCL[Default]}" + [ "${1}" != "report" ] && echo -e "${idsCL[Cyan]} ${DRIVE}${spcA}:${idsCL[$fs_status_color]} ${DRIVEINFO_FREE[$DRIVE]} GB${spcB}${DRIVEINFO_FREEPER[$DRIVE]}%${spcC}${DRIVEINFO_TOT[$DRIVE]} GB${spcD}${idsCL[Cyan]}( ${idsCL[Yellow]}${WARNING_LEVEL}%${idsCL[Cyan]} / ${idsCL[Red]}${CRITICAL_LEVEL}%${idsCL[Cyan]} )${idsCL[Default]}" 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 @@ -227,15 +233,17 @@ CHECK(){ unset DRIVEINFO_TOT DRIVEINFO_FREE DRIVEINFO_FREEPER DRIVES DRIVEINFO host_limits_tmp else - echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}" + [ "${1}" != "report" ] && echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}" fi done - end=`date +%s` - runtime=$((end-start)) - echo - echo "runtime: ${runtime}" + if [ "${1}" != "report" ]; then + end=`date +%s` + runtime=$((end-start)) + echo + echo "runtime: ${runtime}" + fi } SETUPSSH(){ @@ -257,7 +265,7 @@ SETUPSSH(){ case $action in - check) CHECK;; + check) CHECK ${2};; setupssh) SETUPSSH;; run) RUN ${2};; update);;