Skip to content

Instantly share code, notes, and snippets.

@golonzovsky
Created July 2, 2018 09:35
Show Gist options
  • Save golonzovsky/04759023ecbbbcfaa5b8bcec299204c1 to your computer and use it in GitHub Desktop.
Save golonzovsky/04759023ecbbbcfaa5b8bcec299204c1 to your computer and use it in GitHub Desktop.
grafana annotation on deployment
#!/bin/bash
# this would create annotation in grafana with current date and tags: ["backend-deployment", "prod", "$1"]
# '$grafanaTokenPassword' is defined in CI - API token with EDIT permissions
# Command line:
# ./annotateDeployment.sh <project> <service/batch> <image-tag>
PROJECT_NAME=$1
DEPLOYMENT_TYPE=$2
IMAGE_TAG=$3
DATE_MILLIS=$(date +%s%3N)
read -r -d '' JSON_BODY <<- EOM
{
"time":$DATE_MILLIS,
"tags":[ "deployment", "prod", "$PROJECT_NAME", "$DEPLOYMENT_TYPE"],
"text":"$PROJECT_NAME $IMAGE_TAG"
}
EOM
echo posting grafana annotation: $JSON_BODY
curl -H "Authorization: Bearer $bamboo_grafanaTokenPassword" \
-H "Content-Type: application/json" \
-d "$JSON_BODY" -s \
http://grafana.example.com/api/annotations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment