2022-10-06 10:45:50 +02:00
#!/bin/bash
source lib/log.sh
function hc_set_uuid( ) {
HCUUID = " $1 "
}
function hc_set_service( ) {
HCSERVICE = " $1 "
}
UPTIME =
2022-11-04 17:20:17 +01:00
USER_AGENT =
2022-10-06 10:45:50 +02:00
function hc_send( ) {
if [ -n " $MONITOR_APIKEY " ] ; then
hc_set_uuid $MONITOR_APIKEY
fi
if [ -n " $HCSERVICE " ] ; then
HCURL = " https://hc-ping.com/ $PING_KEY / $HCSERVICE "
fi
if [ -n " $HCUUID " ] ; then
HCURL = " https://hc-ping.com/ $HCUUID "
fi
if [ ! -n " $HCURL " ] ; then
2022-10-27 11:58:24 +02:00
log WARN "Did not report Healthcheck: Neither Healthcheck UUID nor service set. Please define MONITOR_APIKEY in /etc/bridgehead."
return 0
2022-10-06 10:45:50 +02:00
fi
if [ -z " $UPTIME " ] ; then
2022-10-06 12:49:31 +02:00
UPTIME = $( docker ps -a --format 'table {{.Names}} \t{{.RunningFor}} \t {{.Status}} \t {{.Image}}' --filter name = bridgehead || echo "Unable to get docker statistics" )
2022-10-06 10:45:50 +02:00
fi
2022-11-04 17:18:09 +01:00
if [ -z " $USER_AGENT " ] ; then
COMMIT_ETC = $( git -C /etc/bridgehead rev-parse HEAD | cut -c -8)
COMMIT_SRV = $( git -C /srv/docker/bridgehead rev-parse HEAD | cut -c -8)
USER_AGENT = " srv: $COMMIT_SRV etc: $COMMIT_ETC "
fi
2022-10-06 10:45:50 +02:00
if [ -n " $2 " ] ; then
MSG = " $2 \n\nDocker stats:\n $UPTIME "
2022-11-04 17:18:09 +01:00
echo -e " $MSG " | https_proxy = $HTTPS_PROXY_URL curl -A " $USER_AGENT " -s -o /dev/null -X POST --data-binary @- " $HCURL " /" $1 " || log WARN " Monitoring failed: Unable to send data to $HCURL / $1 "
2022-10-06 10:45:50 +02:00
else
2022-11-04 17:18:09 +01:00
https_proxy = $HTTPS_PROXY_URL curl -A " $USER_AGENT " -s -o /dev/null " $HCURL " /" $1 " || log WARN " Monitoring failed: Unable to send data to $HCURL / $1 "
2022-10-06 10:45:50 +02:00
fi
}