#!/bin/bash
# IBM Confidential
# OCO Source Materials
# 5724-V51
#
# (c) Copyright IBM Corp. 2000, 2008 All Rights Reserved.
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.

# This is the interface script between pimSuport.sh and actual health-check
# scripts. Based on options, this script will figure out a proper corresponding
# health check function to execute.
#

. ${TOP}/bin/get_params.sh

if [ "${_CCD_HEALTH}" != "yes" ]; then
	echo "healthCheck.sh: option not set to --health=yes"
	exit 1
fi

# source necessary functions
#
. $TOP/bin/diagnostic/common/common.functions
. $TOP/bin/diagnostic/health_check/healthCheck.functions


# setup working directory and final output file
#
export WORKINGDIR=$TOP/logs/diagnostic/health_check
mkdir -p $WORKINGDIR
OUTPUT_FILE=$WORKINGDIR/healthCheckResult.out
touch ${OUTPUT_FILE}
HC_LOG_FILE=$WORKINGDIR/healthCheck.log
# touch ${HC_LOG_FILE}

# write out timestamp header
#
getReportHeader > ${OUTPUT_FILE}

# prepare the database connection information
#
setupdbcredentials


#
# sofeware stack info
#
echo "=======================================" 
echo "Software and System Stack: starting...."

printSoftwareStackHeader >> ${OUTPUT_FILE}

. $TOP/bin/diagnostic/health_check/softwareStack.functions
getSoftwareStack >> ${OUTPUT_FILE} 

echo "Software and System Stack: Done"


# setup and config
#
echo "======================================="
echo "Setup and Configuration: starting......"

printSetupConfigHeader >> ${OUTPUT_FILE}

. $TOP/bin/diagnostic/health_check/commonProperty.functions
getConfigFromCommonProperty >> ${OUTPUT_FILE}

. $TOP/bin/diagnostic/health_check/memoryFlags.functions
getSysEnvSetup >> ${OUTPUT_FILE}

if [ "X${CCD_DB}" = "Xoracle" ]; then
. $TOP/bin/diagnostic/health_check/oracleConfig.functions
getOracleConfig >> ${OUTPUT_FILE}
fi

if [ "X${CCD_DB}" = "Xdb2" ]; then
. $TOP/bin/diagnostic/health_check/db2Config.functions
getDB2Config >> ${OUTPUT_FILE}
fi

echo "Setup and Configuration: Done"


# implementation and deployment
#
echo "======================================="
echo "Implementation & Deployment: starting.."

printDeploymentHeader >> ${OUTPUT_FILE}

. $TOP/bin/diagnostic/health_check/deployment.functions
getImplDeployment >> ${OUTPUT_FILE}

echo "Implementation & Deployment: Done"


# runtime snapshot and statistics
#
echo "======================================="
echo "Runtime Statistics: starting..........."

printRuntimeHeader >> ${OUTPUT_FILE}

. $TOP/bin/diagnostic/health_check/runtimeSnapshot.functions
getRuntimeSnapshot >> ${OUTPUT_FILE}

echo "Runtime Statistics: Done"
echo "=======================================" 

# write out footer
echo " "
echo " "
getReportFooter >> ${OUTPUT_FILE}

echo "Health Check result is available at: $TOP/logs/diagnostic/health_check/healthCheckResult.out"
echo " "
 
