From 65eec0b5d722b86fac54ca8b48b02f41d769b7fb Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 25 Nov 2023 16:48:19 -0600 Subject: [PATCH] update --- defaults.inc | 26 +++++++++++++++++------ dsmon.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/defaults.inc b/defaults.inc index 1fd7aea..cee1474 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,18 +1,32 @@ #!/usr/bin/env bash -VERS=2.2.36-11012023 +VERS=2.2.105-11252023 DS_FOLDER=/opt/idssys/dsmon DS_CRONTAB_FOLDER=/opt/idssys/nodemgmt/crontabs -if [ "${TAILSCALE}" != "true" ] && [ "$(CHECK_HOST 10.10.10.50)" != "false" ]; then - nmip=10.10.10.50 - mysqlip=10.10.1.50 -elif [ "${TAILSCALE}" == "true" ] || [ "$(CHECK_HOST 100.100.55.1)" != "false" ]; then - nmip=100.100.55.1 +noheader=( ) + + +if [ "${NM_NODEMANAGER}" != "" ]; then + def_nmip=${NM_NODEMANAGER} + def_mysqlip=${NM_SINGLESRVR_IP['MYSQL']} +else + def_nmip=10.10.10.50 + def_mysqlip=10.10.1.50 +fi + +[ "$(CHECK_HOST ${NM_NODEMANAGER})" == "false" ] && def_mysqlip='' + +if [ "${TAILSCALE}" != "true" ] && [ "$(CHECK_HOST ${def_nmip})" != "false" ]; then + nmip=${def_nmip} + mysqlip=${def_mysqlip} +elif [ "${TAILSCALE}" == "true" ] || [ "$(CHECK_HOST ${NM_NODEMANAGER_TS})" != "false" ]; then + nmip=${NM_NODEMANAGER_TS} mysqlip=100.100.5.2 else nmip= + mysqlip= fi SENDNOTICE(){ diff --git a/dsmon.sh b/dsmon.sh index e9dd611..4460833 100755 --- a/dsmon.sh +++ b/dsmon.sh @@ -2,17 +2,21 @@ # DSMon - Disk and Basic System Monitor Script source /opt/idssys/defaults/colors.inc -source /opt/idssys/dsmon/config.settings.inc source /opt/idssys/defaults/default.inc + +source /opt/idssys/dsmon/config.settings.inc source /opt/idssys/dsmon/defaults.inc -action="$1" +[ -d /opt/idssys/nodemgmt ] && source /opt/idssys/nodemgmt/defaults.inc + + +ACTION="${1}" RUN(){ if [ "${SERVERMON_ID}" != "" ]; then if [ "${1}" = "hdd" ]; then - DRIVEINFO=$(df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|shm|mmcblk|overlay|-volume|Music|Software' | awk '{ print $1 " " $2 " " $4 }') + DRIVEINFO=$(df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|shm|mmcblk|overlay|-volume|Music|Software' | awk '{ print ${1} " " ${2} " " ${4} }') DRIVEINFO=(${DRIVEINFO}) NUMDRIVES=$((${#DRIVEINFO[@]} / 3)) @@ -57,7 +61,7 @@ RUN(){ elif [ "${1}" = "sys" ]; then - MEMORY=$(free -m | awk 'NR==2{printf "%.2f\t\t", $3*100/$2 }') + MEMORY=$(free -m | awk 'NR==2{printf "%.2f\t\t", ${3}*100/${2} }') CPU=$(top -bn1 | grep load | awk '{printf "%.2f\t\t\n", $(NF-2)}') QRY="USE servermonitor; INSERT INTO sysinfo (\`host\`, \`entry\`, \`value\`) VALUES ('${SERVERMON_ID}','sys','${CPU// /};${MEMORY}');" @@ -139,7 +143,7 @@ CHECK(){ host_limits_tmp[$hlname]=$hllim 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|Software' | awk '{ print $1 " " $2 " " $4 }') + DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|shm|mmcblk|overlay|-volume|Music|Software' | awk '{ print ${1} " " ${2} " " ${4} }') DRIVEINFO=(${DRIVEINFO}) # for x in "${!DRIVEINFO[@]}"; do printf "[%s]=%s\n" "$x" "${DRIVEINFO[$x]}" ; done @@ -350,7 +354,7 @@ GETTSIP(){ GETTSIP_NODE(){ TSI=$(/sbin/ip link | grep tailscale0) if [ ${#TSI} != 0 ]; then - TSIP=$(/sbin/ip -o -4 addr list tailscale0 | awk '{print $4}' | cut -d/ -f1) + TSIP=$(/sbin/ip -o -4 addr list tailscale0 | awk '{print ${4}}' | cut -d/ -f1) hostname=$(hostname -f); hostname=${hostname,,} ([ "${hostname}" == "" ] || [[ "${hostname}" != *".scity"* ]]) && hostname=$(hostname) && hostname="${hostname,,}.ts.scity.us" || hostname=${hostname/.scity/.ts.scity} echo "Tailscale running, TSIP: ${TSIP}" @@ -430,7 +434,29 @@ FIXCRONTAB(){ crontab -l | grep "dsmon" } -case $action in +# case ${ACTION} in +# check) CHECK ${2};; +# setupssh) SETUPSSH;; +# get-crontabs) GETCRONTABS ${2};; +# get-crontab) GETCRONTAB ${2};; +# fix-crontab) FIXCRONTAB;; +# gettsip) GETTSIP;; +# gettsip-node) GETTSIP_NODE;; +# run) RUN ${2};; +# runcmd) RUNCMD ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11};; +# update);; +# *) RUN ${ACTION};; +# esac + +if [[ "${noheader}" != *" ${1} "* ]] && [[ "${noheader}" != *" ${2} "* ]]; then + echo + DIVIDER . lightGreen 70 + msg="| Disk Space Monitor (DSMon) ${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})" + c=0; spc=''; spc1=`expr 81 - ${#msg}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done + echo -e "${idsCL[LightGreen]}${msg}${spc}${idsCL[LightGreen]}|${idsCL[Default]}" + DIVIDER . lightGreen 70 +fi +case ${ACTION} in check) CHECK ${2};; setupssh) SETUPSSH;; get-crontabs) GETCRONTABS ${2};; @@ -441,7 +467,24 @@ case $action in run) RUN ${2};; runcmd) RUNCMD ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11};; update);; - *) RUN ${action};; + *) + if [ "${ACTION}" == "hdd" ] || [ "${ACTION}" == "hdd" ]; then + RUN ${ACTION} + else + echo -e "${idsCL[White]} Usage: ${idsCL[LightCyan]}dsmon {option}" + echo + echo -e " ${idsCL[Yellow]}check ${idsCL[Default]}--> Run a Disk Space check for all hosts" + echo -e " ${idsCL[Yellow]}setupssh ${idsCL[Default]}--> Configure direct SSH access to all hosts" + echo -e " ${idsCL[Yellow]}get-crontabs ${idsCL[Default]}--> Get root crontabs from all hosts" + echo -e " ${idsCL[Yellow]}gettsip ${idsCL[Default]}--> Check Sensors" + echo -e " ${idsCL[Yellow]}gettsip-node ${idsCL[Default]}--> Check Sensors" + echo -e " ${idsCL[Yellow]}run {type} ${idsCL[Default]}--> Monitor Check to run" + echo -e " ${idsCL[LightYellow]} type = { hdd / sys } ${idsCL[Default]}--> Disk Space or System Resources" + echo -e " ${idsCL[Yellow]}runcmd ${idsCL[Default]}--> Run command on all hosts" + echo -e " ${idsCL[Yellow]}update ${idsCL[Default]}--> Update DSMon" + echo + fi + ;; esac exit 0