Update dsmon.sh

This commit is contained in:
2023-01-02 09:25:15 -06:00
parent ef3da3f3dd
commit c3689a5847

106
dsmon.sh
View File

@@ -84,7 +84,7 @@ CHECK(){
declare -A host_ip declare -A host_ip
declare -A host_name declare -A host_name
declare -A host_limits declare -A host_limits
declare -A hostnames declare -A host_ids
declare -a hostnames_sort declare -a hostnames_sort
while read hostid hostname hostip hostlimits; do while read hostid hostname hostip hostlimits; do
@@ -94,65 +94,63 @@ CHECK(){
host_ip[${hostid}]=$hostip host_ip[${hostid}]=$hostip
host_name[${hostid}]=$hostname host_name[${hostid}]=$hostname
host_limits[${hostid}]=$hostlimits host_limits[${hostid}]=$hostlimits
hostnames[$hostname]=$hostid; hostnames_sort+=("$hostname") host_ids[$hostname]=$hostid
hostnames_sort+=("$hostname")
fi fi
done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts") done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts")
IFS=$'\n' hostnames_sort=($(sort <<<"${hostnames_sort[*]}")) IFS=$'\n' hostnames_sort=($(sort <<<"${hostnames_sort[*]}"))
unset IFS unset IFS
for x in "${!hostnames[@]}"; do printf "[%s]=%s\n" "$x" "${hostnames[$x]}" ; done #for hostid in "${!host_ip[@]}"; do
echo for hostname in "${hostnames_sort[@]}"; do
for x in "${!hostnames_sort[@]}"; do printf "[%s]=%s\n" "$x" "${hostnames_sort[$x]}" ; done hostid=${host_ids[$hostname]}
echo -e "${idsST[Bold]}"; DIVIDER
echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}"
# for hostid in "${!host_ip[@]}"; do DIVIDER; echo -e "${idsST[Reset]}"
# echo -e "${idsST[Bold]}"; DIVIDER
# echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}" # checkhost=$(CHECK_HOST ${host_ip[$hostid]})
# DIVIDER; echo -e "${idsST[Reset]}" # if [ "${checkhost}" != "false" ]; then
# # DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|sda|sdb|shm|mmcblk|overlay|-volume|Music|media-data|Software' | awk '{ print $1 " " $2 " " $4 }')
# checkhost=$(CHECK_HOST ${host_ip[$hostid]}) # DRIVEINFO=(${DRIVEINFO})
# if [ "${checkhost}" != "false" ]; then # NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
# DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|sda|sdb|shm|mmcblk|overlay|-volume|Music|media-data|Software' | awk '{ print $1 " " $2 " " $4 }') #
# DRIVEINFO=(${DRIVEINFO}) # for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
# NUMDRIVES=$((${#DRIVEINFO[@]} / 3)) # ii=$((${i}*3))
# # dname=${DRIVEINFO[${ii}]}
# for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do # dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
# ii=$((${i}*3)) # dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
# dname=${DRIVEINFO[${ii}]} # dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100))
# dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10") # dname=${dname//\/dev\/mapper\//}
# dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10") # dname=${dname//\/dev\//}
# dfreeper=$(printf "%0.2f" $(jq -n ${dfree}/${dtot}*100)) #
# dname=${dname//\/dev\/mapper\//} # if (( $(bc <<<"$dfreeper <= 15") )); then
# dname=${dname//\/dev\//} # fs_status='error'
# # fs_status_color='Red'
# if (( $(bc <<<"$dfreeper <= 15") )); then # 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
# fs_status='error' #
# fs_status_color='Red' # elif (( $(bc <<<"$dfreeper <= 25") )); then
# 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 # fs_status='warn'
# # fs_status_color='Yellow'
# elif (( $(bc <<<"$dfreeper <= 25") )); then # 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
# fs_status='warn' #
# fs_status_color='Yellow' # else
# 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 # fs_status=''
# # fs_status_color='Green'
# else # fi
# fs_status='' #
# fs_status_color='Green' # c=0; cw=30; spc=''
# fi # spc1=`expr ${cw} - ${#dname}`
# # until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
# c=0; cw=30; spc='' # echo -e "${idsCL[$fs_status_color]} ${dname}${spc}: ${dfree}GB Free - ${dfreeper}%${idsCL[Default]}"
# spc1=`expr ${cw} - ${#dname}` #
# until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done # done
# echo -e "${idsCL[$fs_status_color]} ${dname}${spc}: ${dfree}GB Free - ${dfreeper}%${idsCL[Default]}" #
# # else
# done # echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}"
# # fi
# else
# echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}" done
# fi
#
# done
} }
SETUPSSH(){ SETUPSSH(){