
#!/bin/bash
# File	: chk_netapp-harvest-logs.sh
# By	: Maarten.deBoer@Atso.net, 160503
# Subject	: Script to check logfiles if polling is OK
#(0.2),170605	: Added HOSTNAME
#(0.3),170714	: Mod ANSW & check only running pollers.
#(0.4),170714	: Mods | grep RUNNING
PGM="`basename $0|cut -d\. -f1`"
VER="0.4"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
HOSTNAME="`hostname|cut -d\. -f1`"
ANSW=""

MAILTO="maarten.deboer@atos.net"
NHBASE="/opt/netapp-harvest"

DATE="`date +%Y-%m-%d`"

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}
touch ${TMP}

sudo ${NHBASE}/netapp-manager -status|grep RUNNING|cut -d\] -f2|awk '{print $1}'|while read POLLER
do
  ls -1tr ${NHBASE}/log/*${POLLER}*.log|tail -1|while read FILENAME
  do
    ANSW="`tail -1 ${FILENAME}|grep -v ${DATE}`"
    if [ "${ANSW}" != "" ]; then
      echo "${LINE} ${POLLER} ${ANSW}"
      echo "  Restarting poller ${POLLER} (${ANSW}) ..."|tee -a ${LOG} ${TMP}
      sudo ${NHBASE}/netapp-manager -poller ${POLLER} -restart
    fi
  done
done

if [ -s ${TMP} ]; then
  echo "  Some messages were not from today."|tee -a ${TMP}
  cat ${TMP}|mailx -s ":${HOSTNAME}: Check NetApp-Harvest logs [${PGM} v${VER}]" ${MAILTO}
  echo "  Mail send to ${MAILTO}"|tee -a ${LOG}
fi

rm ${TMP}
exit 0

