Report git commits in user agent to monitoring

This commit is contained in:
Martin Lablans 2022-11-04 17:18:09 +01:00
parent e9a2ed05f2
commit 895ee37296
2 changed files with 11 additions and 7 deletions

View File

@ -11,6 +11,7 @@ function hc_set_service(){
} }
UPTIME= UPTIME=
USER_AGENT="git-unknown"
function hc_send(){ function hc_send(){
if [ -n "$MONITOR_APIKEY" ]; then if [ -n "$MONITOR_APIKEY" ]; then
@ -32,10 +33,16 @@ function hc_send(){
UPTIME=$(docker ps -a --format 'table {{.Names}} \t{{.RunningFor}} \t {{.Status}} \t {{.Image}}' --filter name=bridgehead || echo "Unable to get docker statistics") UPTIME=$(docker ps -a --format 'table {{.Names}} \t{{.RunningFor}} \t {{.Status}} \t {{.Image}}' --filter name=bridgehead || echo "Unable to get docker statistics")
fi fi
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
if [ -n "$2" ]; then if [ -n "$2" ]; then
MSG="$2\n\nDocker stats:\n$UPTIME" MSG="$2\n\nDocker stats:\n$UPTIME"
echo -e "$MSG" | https_proxy=$HTTPS_PROXY_URL curl -s -o /dev/null -X POST --data-binary @- "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1" 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"
else else
https_proxy=$HTTPS_PROXY_URL curl -s -o /dev/null "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1" 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"
fi fi
} }

View File

@ -71,10 +71,7 @@ else
exit 1 exit 1
fi fi
COMMIT_ETC=$(git -C /etc/bridgehead rev-parse HEAD | cut -c -8) log INFO "Success - all prerequisites are met!"
COMMIT_SRV=$(git -C /srv/docker/bridgehead rev-parse HEAD | cut -c -8) hc_send log "Success - all prerequisites are met!"
log INFO "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV"
hc_send log "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV"
exit 0 exit 0