#!/bin/bash
pushd `dirname $0` > /dev/null
cd ..; . exports.sh
cd $AE_SVR/gateway


# Time (seconds) to wait in contacting a gateway before timing out
TIMEOUT=30          

# The amount of checkpoint failures to display per *APPLICATION* not gateway. 0 means show all.
MAX_LOGS_CHECK=10   

# The amount of tailpoint failures to display per *APPLICATION* not gateway. 0 means show all.
MAX_LOGS_TAIL=10    

# The amount of engine shutdowns (possible rollbacks, write_to_disk_failures)  to display per *APPLICATION* not gateway. 0 means show all.
MAX_LOGS_CLOSE=10   

# Time (hours) between checkpoints after which a warning will be displayed
# This is cleared by checkpointing.
MAX_TIME_TO_CHK=24  

# How big (percentage of the maximum load metric) can Exec & Analytics get before alerting the user.
WARN_LOAD_METRIC=75

CUSTOM_ARGS=$TIMEOUT' '$MAX_LOGS_CHECK' '$MAX_LOGS_TAIL' '$MAX_LOGS_CLOSE' '$MAX_TIME_TO_CHK' '$WARN_LOAD_METRIC

# Number of MB of transactions after which a warning will be displayed. 0 means do not check transaction size limit (default 512)
# This is cleared by checkpointing.
export TRANSACTION_SIZE_LIMIT_MB=512

# Number of transactions after which a warning will be displayed. 0 means do not check transaction count limit (default 100000)
# This is cleared by checkpointing.
export TRANSACTION_COUNT_LIMIT=100000

# Expected time to replay transactions before accepting new transactions after which a warning will be displayed. 0 means do not check transaction replay time (default 1800)
# This is cleared by checkpointing.
export TRANSACTION_REPLAY_TIME_SECONDS=1800


# ###########################
#
#   Severity Levels
#
# ###########################

WARN=1
ERROR=2
FATAL=3


# ###########################
#
#   Issue Severity
#
# ###########################

BROKEN_CHAIN=$FATAL

SERVER_TIMEOUT=$ERROR
 
NO_INSTANCE_UP=$FATAL
 
WRONG_DBID=$WARN
 
CHECKPOINT_FAIL=$ERROR

# Intermittent checkpoint failures
TEMP_CHECK_FAIL=$WARN

SHOULD_CHECKPT=$WARN

# Continuous shutdowns of an engine
CONT_SHUTDOWN=$FATAL

# Non-continuous shutdowns
DETECT_SHUTDOWN=$ERROR

NEAR_LOAD_METRIC_MAX=$WARN

PAST_LOAD_METRIC_MAX=$ERROR

#An Exec server has stopped updating Analytics
NO_EXEC_UPDATE=$ERROR

#Migration failed to run
MIGRATION_FAILED=$FATAL
 
SEVERITY=$BROKEN_CHAIN' '$SERVER_TIMEOUT' '$NO_INSTANCE_UP' '$WRONG_DBID' '$CHECKPOINT_FAIL' '$TEMP_CHECK_FAIL' '$SHOULD_CHECKPT' '$CONT_SHUTDOWN' '$DETECT_SHUTDOWN' '$NEAR_LOAD_METRIC_MAX' '$PAST_LOAD_METRIC_MAX' '$NO_EXEC_UPDATE' '$MIGRATION_FAILED

$APPIAN_EXEC checkEngineMain $CUSTOM_ARGS $SEVERITY $*

cd $OLDCD
