2020-01-10 15:55:35 +03:00
|
|
|
#!/bin/bash
|
2020-05-18 21:24:16 +03:00
|
|
|
|
|
|
|
CONFIGDIR="configs"
|
|
|
|
RESPONSESDIR="responses"
|
2020-10-29 11:25:43 +03:00
|
|
|
ACLDIR="access-lists"
|
|
|
|
ALLOWANCEFILE="allowance_list.txt"
|
|
|
|
BLOCKFILE="block_list.txt"
|
|
|
|
CACHEDIR="cache"
|
2020-05-18 21:24:16 +03:00
|
|
|
IMAGETAG="latest"
|
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
cd $(dirname $0)/..
|
|
|
|
|
|
|
|
if /usr/local/bin/docker-compose ps | grep -q -i 'monitor'; then
|
2020-05-18 21:24:16 +03:00
|
|
|
tstart=`date +"%s"`
|
2020-11-04 14:24:42 +03:00
|
|
|
|
2020-05-18 21:24:16 +03:00
|
|
|
for file in ${CONFIGDIR}/*.env
|
2020-01-10 15:55:35 +03:00
|
|
|
do
|
2020-05-18 21:24:16 +03:00
|
|
|
echo "${file} handling..."
|
2020-11-04 14:24:42 +03:00
|
|
|
|
2020-05-18 21:24:16 +03:00
|
|
|
bridgename=`source ${file} && echo ${MONITOR_BRIDGE_NAME}`
|
|
|
|
reportdir=${RESPONSESDIR}"/"${bridgename}
|
|
|
|
if [ ! -d ${reportdir} ]; then
|
|
|
|
mkdir -p ${reportdir}
|
|
|
|
fi
|
|
|
|
checksumfile=${bridgename}".shasum"
|
|
|
|
rm -f ${checksumfile}
|
|
|
|
for json in alerts.json eventsStats.json getBalances.json validators.json stuckTransfers.json; do
|
|
|
|
if [ -f ${reportdir}/${json} ]; then
|
|
|
|
shasum -a 256 ${reportdir}/${json} >> ${checksumfile}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-10-29 11:25:43 +03:00
|
|
|
alist=`source ${file} && echo ${MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST}`
|
|
|
|
blist=`source ${file} && echo ${MONITOR_HOME_TO_FOREIGN_BLOCK_LIST}`
|
|
|
|
al_param="$(pwd)/${ACLDIR}/${bridgename}/${ALLOWANCEFILE}:/mono/monitor/access-lists/allowance_list.txt"
|
|
|
|
bl_param="$(pwd)/${ACLDIR}/${bridgename}/${BLOCKFILE}:/mono/monitor/access-lists/block_list.txt"
|
|
|
|
|
2020-05-18 21:24:16 +03:00
|
|
|
containername=${bridgename}"-checker"
|
|
|
|
docker container stats --no-stream ${containername} 2>/dev/null 1>&2
|
|
|
|
if [ ! "$?" == "0" ]; then
|
2020-11-04 14:24:42 +03:00
|
|
|
mkdir -p "$(pwd)/$CACHEDIR/$bridgename"
|
2020-05-18 21:24:16 +03:00
|
|
|
docker run --rm --env-file $file -v $(pwd)/${RESPONSESDIR}:/mono/monitor/responses \
|
2020-10-29 11:25:43 +03:00
|
|
|
${alist:+"-v"} ${alist:+"$al_param"} ${blist:+"-v"} ${blist:+"$bl_param"} \
|
2020-11-04 14:24:42 +03:00
|
|
|
-v $(pwd)/${CACHEDIR}/${bridgename}:/mono/monitor/cache/${bridgename} \
|
2020-05-18 21:24:16 +03:00
|
|
|
--name ${containername} poanetwork/tokenbridge-monitor:${IMAGETAG} \
|
|
|
|
/bin/bash -c 'yarn check-all'
|
|
|
|
shasum -a 256 -s -c ${checksumfile}
|
|
|
|
if [ "$?" == "0" ]; then
|
|
|
|
echo "JSON files have not been updated - the monitor is not healthy"
|
|
|
|
for json in alerts.json eventsStats.json getBalances.json validators.json stuckTransfers.json; do
|
|
|
|
if [ -f ${reportdir}/${json} ]; then
|
|
|
|
echo '{"health": false, "lastChecked": '`date +"%s"`'}' > ${reportdir}/${json}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "JSON files have been updated - new metrics collected"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "${containername} have not finished yet" >&2
|
|
|
|
fi
|
2020-11-04 14:24:42 +03:00
|
|
|
|
2020-05-18 21:24:16 +03:00
|
|
|
rm ${checksumfile}
|
|
|
|
echo "========================================"
|
2020-01-10 15:55:35 +03:00
|
|
|
done
|
2020-11-04 14:24:42 +03:00
|
|
|
|
2020-05-18 21:24:16 +03:00
|
|
|
tend=`date +"%s"`
|
|
|
|
tdiff=`expr ${tend} - ${tstart}`
|
|
|
|
echo "Total time to run: ${tdiff}"
|
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
else
|
|
|
|
echo "Monitor is not running, skipping checks."
|
2020-10-29 11:25:43 +03:00
|
|
|
fi
|