
#!/bin/sh
# File	: chk_filer_con_sup.sh
# By	: Maarten.deBoer@AtosOrigin.com, 091208, 091214
# Subject	: Check filer connections (ping, hostname, ROOTVOL mount) & autosupport.enabled (from ${ETC})
#(0.2)	: At FSOD; Added ping to RLM/BMC/console (<filername>-rlm)
#(0.3) 	: If no -rlm configured
#(0.4)	: Added; check autosupport, Check ${SSH} & S{PING}
#set -x
PGM="`basename $0|cut -d\. -f1`"
VERSION="0.4"
TMP="/tmp/${PGM}.$$"
ERR="/tmp/${PGM}.$$.err"
LOG="${HOME}/log/${PGM}.log"
FILERS="${HOME}/etc/filers"
MAILTO="gmnl-msscentral@atosorigin.com maarten.deboer@atosorigin.com"

SSH="`type ssh | awk '{print $3}'`"
PING="`type ping | awk '{print $3}'`"
if [ "${SSH}" = "found" ] || [ "${PING}" = "found" ] ; then
  echo "No SSH or PING found. Exiting ..."
  exit 1
fi

touch ${LOG} ${TMP} ${ERR}
for FILER in `cat ${FILERS} | grep -v \^#`
do
  echo "${FILER} ..." 
  # PINGable?
  ${PING} -c 1 ${FILER} 1> /dev/null 2>&1
  EC=$?
  if [ ${EC} -gt 0 ]; then
    echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}: Ping-Error to ${FILER} "|tee -a ${LOG}|tee -a ${ERR}
  fi
  # Is RML/BMC pingable?
  ${PING} -c 1 ${FILER}-rlm 1> /dev/null 2>&1
  EC=$?
  if [ ${EC} -gt 0 ]; then
    echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}: Ping-Error to ${FILER}-rlm (RLM/BMC/console) "|tee -a ${LOG}|tee -a ${ERR}
  fi
  # Check if hostname is same
  HOSTNAME="`${SSH} -n ${FILER} hostname`"
  if [ "${FILER}" != "${HOSTNAME}" ]; then
    echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}: Filername (${FILER}) <> hostname (${HOSTNAME})"|tee -a ${LOG}|tee -a ${ERR}
  fi
  # Check if ROOTVOL can be mounted
  ROOTVOL="`${SSH} -n ${FILER} vol status|grep ' root'|awk '{print $1}'`" 
  ETCDIR="/filers/${FILER}/${ROOTVOL}/etc/" 
# Test is DIR exsists. Otherwise (if not) script will stop
  if [ -d ${ETCDIR} ]; then
    cd ${ETCDIR} 2> /dev/null
    EC=$?
    if [ ${EC} -gt 0 ]; then
      echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}: Error at ${FILER} changing to ${ETCDIR}"|tee -a ${LOG}|tee -a ${ERR}
    fi
  else
    echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}: Warning for ${FILER} no dir ${ETCDIR} found"|tee -a ${LOG}
  fi
# Check autosupport is ON
  ASUP="`${SSH} -n ${FILER} options autosupport.enable|awk '{print $2}'`" 
  if [ "${ASUP}" = "off" ]; then
    echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}: Error at ${FILER} autosupport.enable is OFF"|tee -a ${LOG}|tee -a ${ERR}
  fi

done

# If ${ERR} (error msg), then mail
if [ -s ${ERR} ]; then
  cat ${ERR} | mailx -s ":`hostname`: Check filer connections & autosupport [${PGM} v${VERSION}]" ${MAILTO}
  echo "Mailed to ${MAILTO}"
fi
rm ${TMP} ${ERR}
exit

