Last active
January 29, 2020 11:26
-
-
Save astronoka/d7a787be625a69bc2a73bc7929e790da to your computer and use it in GitHub Desktop.
Create newrelic deployment resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
NEWRELIC_ADMIN_USERS_KEY="$1" | |
NEWRELIC_APP_NAME="$2" | |
REVISION="$3" | |
usage () { | |
cat <<EOF | |
Usage: create-newrelic-deployment-marker.sh <newrelic-admin-users-key> <newrelic-app-name> <revision> | |
EOF | |
} | |
fetch_app_id () { | |
# see: https://rpm.newrelic.com/api/explore/applications/list | |
echo $(curl -s -X GET 'https://api.newrelic.com/v2/applications.json' \ | |
-H "X-Api-Key: ${NEWRELIC_ADMIN_USERS_KEY}" \ | |
-G -d "filter[name]=${NEWRELIC_APP_NAME}" | jq '.applications[0].id') | |
} | |
generate_deployments_json () { | |
cat <<EOF | |
{ | |
"deployment": { | |
"revision": "${REVISION}" | |
} | |
} | |
EOF | |
} | |
create_deployment () { | |
# see: https://rpm.newrelic.com/api/explore/application_deployments/create | |
curl -X POST "https://api.newrelic.com/v2/applications/$(fetch_app_id)/deployments.json" \ | |
-H "X-Api-Key: ${NEWRELIC_ADMIN_USERS_KEY}" -i \ | |
-H 'Content-Type: application/json' \ | |
-d "$(generate_deployments_json)" | |
} | |
if [ "$NEWRELIC_ADMIN_USERS_KEY" != "" ] && [ "$NEWRELIC_APP_NAME" != "" ] && [ "$REVISION" != "" ]; then | |
echo "NEWRELIC_APP_NAME = ${NEWRELIC_APP_NAME}" | |
echo "REVISION = ${REVISION}" | |
create_deployment | |
else | |
echo $(usage) >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment