#!/bin/bash
PARABLU_COMPONENT_SCRIPT_PATH=../../../config/parablu_component_config.sh
PARABLU_CONFIG_SCRIPT_PATH=../../../config/parablu_config.sh
source $PARABLU_COMPONENT_SCRIPT_PATH
source $PARABLU_CONFIG_SCRIPT_PATH


rm -rf merged.log
rm -rf Backup_OverviewStatus*
cat ../watchdog.log >> merged.log
echo "<<============================= END OF MACHINE STATISTICS 1 =============================>>" >> merged.log
echo "" >> merged.log
echo "" >> merged.log

backupoverviewreport="/parablu/bkpOverview/Backup_OverviewStatus.xlsx"

################################### Copying Log files from other machines ########
	counter=1
	for j in ${OTHER_WATCHDOG_IP[@]}
		do

			scp root@$j:/root/Installable/scripts/health_check/watchdog.log .

			cat watchdog.log >> merged.log
			counter=$((counter+1))
			echo "<<============================= END OF MACHINE STATISTICS $counter =============================>>" >> merged.log
			echo "" >> merged.log
			echo "" >> merged.log
			rm -rf watchdog.log
			sleep 2s

		done
####################################################################################
sleep 1s
curl -X GET http://$BLUVAULT_IP/paracloud/cloud/$CLOUD_NAME/overview/createExcel/

if [ ! -f $backupoverviewreport ]
then
	echo "`cat merged.log`" | mail -s "Machine Statistics of [$CUSTOMER_NAME] at `date`" $WATCHDOG_MAIL_ADDRESS -aFrom:$WATCHDOG_FROM_MAIL_ADDRESS
else
	echo "`cat merged.log`" | mail -s "Machine Statistics of [$CUSTOMER_NAME] at `date`" $WATCHDOG_MAIL_ADDRESS -aFrom:$WATCHDOG_FROM_MAIL_ADDRESS -A $backupoverviewreport
fi
