
#!/bin/ksh
# File	: fsod_migratie_meter.ksh
# By	: Maarten.deBoer@atos.net, 111026
# Subject	: Script om de FSOD-migratie in cijfers (voor mngt) te volgen
# Op basis van klantcode, omdat er ook (nieuwe) klanten op de nieuwe omgeving komen die niet in de rapportage mee hoeven.
# Zoals OMI. DSM wel, want die zat/zit ook op de oude omgeving
#(0.2)	: Removed nlnaf08
#
PGM="`basename $0|cut -d\. -f1`"
VERSION="0.2"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
SSH="/usr/bin/ssh -n"
HOSTNAME="`hostname`"
MAILTO="richard.loos@atos.net tom.cornelissen@atos.net harold.kuijpers@atos.net maarten.deboer@atos.net"

OLDFILERS="hwnaf01 nlnaf02 nlnaf03 nlnaf04 hwnaf05 hwnaf06 nlnaf07 nlnaf09 nlnaf10 nlnaf11 nlnaf12 nlnaf25 nlnaf26"
NEWFILERS="nlnaf55 nlnaf56 nlnaf57 nlnaf58 nlnaf59 nlnaf60 nlnaf61 nlnaf62 nlnaf63 nlnaf64"
CUSTOMERS="aa ab acc acr aib aip akd alm bbi crp cvt dsm eri ias nfl nss nxp san scc sit slb svb vwt"

echo "`date` start ${PGM} @ ${HOSTNAME}" | tee -a ${LOG}
echo "# Filername ; ; ; `date +%Y-%m-%d` ; " |tee -a ${TMP}
echo "# Filername ; Custom-code ; GB ;" |tee -a ${TMP}.cust
VOL_GRANDTOTAL=0
for FILER in ${OLDFILERS}
do
  echo "${FILER} ..."
  VOL_TOTAL=0
  for CUST in ${CUSTOMERS}
  do
    VOL_SUBTOTAL=0
    ${SSH} ${FILER} df -g|grep ${CUST}|grep -v snapshot|grep -v 'snap reserve'|grep -v Filesystem|awk '{print $2}'|sed -e's/GB//g'|while read VAL
    do
      let "VOL_SUBTOTAL=${VOL_SUBTOTAL}+${VAL}"
    done

    let "VOL_TOTAL=${VOL_TOTAL}+${VOL_SUBTOTAL}"
    if [ ${VOL_SUBTOTAL} -gt 0 ]; then
      echo "${FILER} ; ${CUST} ; ${VOL_SUBTOTAL} ; " |tee -a ${TMP}.cust
    fi
  done
  let "VOL_GRANDTOTAL=${VOL_GRANDTOTAL}+${VOL_TOTAL}"
  echo "${FILER} ; Vol Total ; ; ${VOL_TOTAL} ; " |tee -a ${TMP}|tee -a ${TMP}.cust

#  AGGR_USED=0
#  ${SSH} ${FILER} df -gA|grep -v snapshot|grep -v 'snap reserve'|grep -v Aggregate|awk '{print $3}'|sed -e's/GB//g'|while read VAL
#  do
#    let "AGGR_USED=${AGGR_USED}+${VAL}"
#  done
#  echo "${FILER} ; Aggr Used ; ; ${AGGR_USED} ; " |tee -a ${TMP}

done
echo "OLD ; Grand total ; ; ; ${VOL_GRANDTOTAL} ; " |tee -a ${TMP}|tee -a ${TMP}.cust

echo " ; ; ; ; ; " |tee -a ${TMP}

VOL_GRANDTOTAL=0
for FILER in ${NEWFILERS}
do
  echo "${FILER} ..."
  VOL_TOTAL=0
  for CUST in ${CUSTOMERS}
  do
    VOL_SUBTOTAL=0
    ${SSH} ${FILER} df -g | grep ${CUST}|grep -v snapshot|grep -v 'snap reserve'|grep -v Filesystem|awk '{print $2}'|sed -e's/GB//g'|while read VAL
    do
      let "VOL_SUBTOTAL=${VOL_SUBTOTAL}+${VAL}"
    done

    let "VOL_TOTAL=${VOL_TOTAL}+${VOL_SUBTOTAL}"
    if [ ${VOL_SUBTOTAL} -gt 0 ]; then
      echo "${FILER} ; ${CUST} ; ${VOL_SUBTOTAL} ; " |tee -a ${TMP}.cust
    fi
  done
  let "VOL_GRANDTOTAL=${VOL_GRANDTOTAL}+${VOL_TOTAL}"
  echo "${FILER} ; Vol Total ; ; ${VOL_TOTAL} ; " |tee -a ${TMP}|tee -a ${TMP}.cust

#  AGGR_USED=0
#  ${SSH} ${FILER} df -gA|grep -v snapshot|grep -v 'snap reserve'|grep -v Aggregate|awk '{print $3}'|sed -e's/GB//g'|while
#read VAL
#  do
#    let "AGGR_USED=${AGGR_USED}+${VAL}"
#  done
#  echo "${FILER} ; Aggr Used ; ; ${AGGR_USED} ; " |tee -a ${TMP}

done
echo "NEW ; Grand total ; ; ; ${VOL_GRANDTOTAL} ; " |tee -a ${TMP}|tee -a ${TMP}.cust

cat ${TMP}|uuencode ${PGM}.csv|mailx -s "FSOD migratie meter (filers only) [${PGM} v${VERSION}]" ${MAILTO}
cat ${TMP}.cust|uuencode ${PGM}_cust.csv|mailx -s "FSOD migratie meter + customers [${PGM} v${VERSION}]" ${MAILTO}
echo "Mailed to ${MAILTO}" | tee -a ${LOG}

rm ${TMP}  ${TMP}.cust
echo "`date` end ${PGM}" | tee -a ${LOG}
exit 0

