
#!/bin/sh
# File	:  dfm-rpt-view.sh
# By	 Maarten.deBoer@Atos.net, 120611
# Subject	: Script for reporting (from DFM report view) of Aggr-IOPS & Vol-IOPS into one CSV-file (v2)
PGM="`basename $0|cut -d\. -f1`"
LOG="${HOME}/log/${PGM}.log"
DAY="`date +%Y-%m-%d`"
OUT="$HOME/data/${PGM}_${DAY}.out"
VERSION="0.2"
MAILTO="maarten.deboer@atos.net"

# Getting list:
# dfm report view [-q] aggregates-performance-summary
# Object ID Aggregate Controller/Cluster Total Ops/Sec Perf Threshold Violation Count Perf Threshold Violation Period (Sec)
# --------- --------- ------------------ ------------- ------------------------------ -------------------------------------
# 25713     aggr601   nlnaf60                  2406.72

# dfm report view [-q] volumes-performance-summary
# Object ID Volume              Type     Aggregate Storage Server Total Ops/Sec Latency (millisec) Data Throughput (B/Sec) Perf Threshold Violation Count Perf Threshold Violation Period (Sec)
# --------- ------------------- -------- --------- ------------------------------- ------- ------------- ------------------ ----------------------- ------------------------------ -------------------------------------
# 63671     bc_omi10_vol001     Flexible aggr601   nlnafvomi10.org.om.local                     2349.77               0.66             19449796.27               
ls -1 $HOME/etc/${PGM}*.conf | while read LINE
do
  ETCFILE=${LINE}
  CUST="`echo ${LINE}|cut -d\. -f1|cut -d\_ -f2`"
  OUT="$HOME/data/${PGM}_${CUST}_${DAY}.out"
  CSV="${PGM}_${CUST}_${DAY}.csv"
  echo ${LINE} ${CUST} ${OUT}

  echo -n "`date +%Y'-'%m'-'%d';'%H':'%M';'`"|tee -a ${OUT}
  cat ${ETCFILE}|grep -v \# |grep 'aggr '|awk '{print $2}'|while read ID
  do
    DFMRPT="`/usr/bin/dfm report view -q aggregates-performance-summary ${ID}|awk '{print $3"-"$2";"$4}'|sed 's/\./,/g'`"
    echo -n "${DFMRPT} ;"|tee -a ${OUT}
  done

  cat ${ETCFILE}|grep -v \# |grep 'vol '|awk '{print $2}'|while read ID
  do
    DFMRPT="`/usr/bin/dfm report view -q volumes-performance-summary ${ID}|awk '{print $2";"$6";"$7";"$8}'|sed 's/\./,/g'`"
    echo -n "${DFMRPT} ;"|tee -a ${OUT}
  done
  echo " "|tee -a ${OUT}

  HR="`date +%H`"
  MIN="`date +%M`"
# Mail after 23:55
# Process file (to CSV & mail) at the end of the day / week (23:50 at Sunday when --week)
  if [ ${HR} -eq 23 ] && [ ${MIN} -gt 55 ]; then
    cat ${OUT} | /usr/bin/uuencode ${CSV} | mailx -s "DFM rpt view ${CSV} [${PGM} v${VERSION}]" ${MAILTO}
    echo "`date` Mailed ${CSV} to ${MAILTO}"|tee -a ${LOG}
  fi 
done  # ls -1


exit 0

