diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 271039d5..b0530d35 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -133,15 +133,15 @@ STATUS(){ if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${nip}"* ]]; then NCMD=''; LH='- localhost' else NCMD="ssh root@${nip}"; LH='' fi - if [ "${ST_ACTION}" != "check" ]; then - uptime=`${NCMD} uptime -p` - echo -e " ${idsST[Bold]}${idsCL[LightCyan]}${NM_NODETYPES[$NTYPE]}-Node${nid} (${nip})${idsST[Reset]}${idsCL[LightCyan]} - ${uptime} ${idsCL[LightYello]}${LH}${idsCL[Default]}" - DIVIDER false green - fi if [ "${NCMD}" != "" ]; then checkhost=$(CHECK_HOST ${nip}) fi if [ "${checkhost}" != "false" ]; then + if [ "${ST_ACTION}" != "check" ]; then + uptime=`${NCMD} uptime -p` + echo -e " ${idsST[Bold]}${idsCL[LightCyan]}${NM_NODETYPES[$NTYPE]}-Node${nid} (${nip})${idsST[Reset]}${idsCL[LightCyan]} - ${uptime} ${idsCL[LightYello]}${LH}${idsCL[Default]}" + DIVIDER false green + fi if [ -f ${FOLDER}/${nip}.down ]; then if [ -f ${FOLDER}/${nip}.errtime ]; then toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}.errtime) @@ -228,21 +228,17 @@ STATUS(){ else if [ ! -f ${FOLDER}/${nip}.down ]; then touch ${FOLDER}/${nip}.down + if [ ! -f ${FOLDER}/${nip}.errtime ]; then + touch ${FOLDER}/${nip}.errtime + fi + fi + if [ "${ST_ACTION}" != "check" ]; then + toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}.errtime) + echo -e " ${idsST[Bold]}${idsCL[LightCyan]}${NM_NODETYPES[$NTYPE]}-Node${nid} (${nip})${idsST[Reset]}${idsCL[LightCyan]} - Node has been down for $(SHOW_TIME ${toterrtime}) ${idsCL[LightYello]}${LH}${idsCL[Default]}" fi errtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}.down) - if [ $errtime -gt ${RENOTIFY} ]; then - if [ ! -f ${FOLDER}/${nip}.errtime ]; then - mv ${FOLDER}/${nip}.down ${FOLDER}/${nip}.errtime - fi - toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}.errtime) - if [ "${ST_ACTION}" != "check" ]; then - echo -e "${idsCL[Red]}Node has been down for $(SHOW_TIME ${toterrtime})${idsCL[Default]}" - fi - if [ "${STATUS_CHECK_EMAIL}" != "" ]; then echo "${NM_NODETYPES[$NTYPE]}-Node${nid} has been down for $(SHOW_TIME ${toterrtime})" | mail -s "${NM_NODETYPES[$NTYPE]}-Node${nid}-${nip}" ${STATUS_CHECK_EMAIL}; fi - else - if [ "${ST_ACTION}" != "check" ]; then - echo -e "${idsCL[Red]}Node is Down!${idsCL[Default]}" - fi + if [ $errtime -gt ${RENOTIFY} ] && [ "${STATUS_CHECK_EMAIL}" != "" ]; then + echo "${NM_NODETYPES[$NTYPE]}-Node${nid} has been down for $(SHOW_TIME ${toterrtime})" | mail -s "${NM_NODETYPES[$NTYPE]}-Node${nid}-${nip}" ${STATUS_CHECK_EMAIL} fi fi if [ "${ST_ACTION}" != "check" ]; then echo; fi