Skip to content

Commit

Permalink
give recipes final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-makes committed Jul 19, 2024
1 parent ea818c9 commit 1b531f1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 87 deletions.
52 changes: 23 additions & 29 deletions recipes/newrelic/infrastructure/super-agent/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,11 @@ install:
echo "openssl is required to run the newrelic install. Please install openssl and re-run the installation." >&2
exit 17
fi
- |
IS_JQ_INSTALLED=$(which jq | wc -l)
if [ $IS_JQ_INSTALLED -eq 0 ] ; then
echo "jq is required to run the newrelic install. Please install jq and re-run the installation." >&2
exit 18
fi
- |
IS_MKTEMP_INSTALLED=$(which mktemp | wc -l)
if [ $IS_MKTEMP_INSTALLED -eq 0 ] ; then
echo "mktemp is required to run the newrelic install. Please install coreutils and re-run the installation." >&2
exit 19
exit 18
fi
- |
if [ -n "{{.DEBIAN_CODENAME}}" ]; then
Expand Down Expand Up @@ -454,6 +448,7 @@ install:
else
sed -i 's/\(endpoint: https:\/\/opamp.\).*/\1'"service.newrelic.com\/v1\/opamp"'/' /etc/newrelic-super-agent/config.yaml
fi
config_super_agent_auth:
cmds:
- |
Expand All @@ -479,41 +474,39 @@ install:
chmod 700 /etc/newrelic-super-agent/keys
TEMPORAL_FOLDER=$(mktemp -d newrelic-super-agent.XXXXXXXXXX)
trap "rm -rf $TEMPORAL_FOLDER" EXIT
openssl genrsa -out "$TEMPORAL_FOLDER/key" 4096
openssl rsa -in "$TEMPORAL_FOLDER/key" -pubout -out "$TEMPORAL_FOLDER/pub"
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
REGISTRATION_ENDPOINT=https://staging-iam-service.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://staging-iam-service.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
elif [ "{{.NEW_RELIC_REGION}}" = "EU" ]; then
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
else
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
fi
NAME="System Identity for $(hostname)"
for RETRY in 1 2 3; do
HTTP_CODE=$(echo '{ "query":
"{
mutation createSystemIdentity {
createSystemIdentity(
name: \"'$NAME'\",
organizationId: \"{{ .NEW_RELIC_ORGANIZATION }}\",
publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\"
) {
clientId,
id,
name
}
"mutation {
create(
name: \"'$NAME'\",
organizationId: \"{{ .NEW_RELIC_ORGANIZATION }}\",
publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\"
) {
clientId,
name
}
}"
}' | tr -d $'\n' | curl -X POST \
-s -w "%{http_code}" \
-H "Content-Type: application/json" \
-H "api-key: {{ .NEW_RELIC_API_KEY }}" \
-H "api-key: {{ .NEW_RELIC_LICENSE_KEY }}" \
-o "$TEMPORAL_FOLDER/response.json" \
--data @- \
"$REGISTRATION_ENDPOINT"
Expand All @@ -527,23 +520,24 @@ install:
sleep 2
done
ERROR_MESSAGE=$(jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ $HTTP_CODE -ne 200 ]; then
exit 99
fi
ERROR_MESSAGE=$(/usr/local/bin/newrelic utils jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Error creating an identity: $ERROR_MESSAGE"
exit
exit 100
fi
CLIENT_ID=$(jq 'data.createSystemIdentity.clientId' < "$TEMPORAL_FOLDER/response.json")
ID=$(jq 'data.createSystemIdentity.id' < "$TEMPORAL_FOLDER/response.json")
NAME=$(jq 'data.createSystemIdentity.name' < "$TEMPORAL_FOLDER/response.json")
CLIENT_ID=$(/usr/local/bin/newrelic utils jq -r '.data.createSystemIdentity.clientId' < "$TEMPORAL_FOLDER/response.json")
NAME=$(/usr/local/bin/newrelic utils jq -r '.data.createSystemIdentity.name' < "$TEMPORAL_FOLDER/response.json")
mv "$TEMPORAL_FOLDER/key" "/etc/newrelic-super-agent/keys/$CLIENT_ID.key"
# TODO: sed -i 's/token_url: PLACEHOLDER/token_url: '"$TOKEN_RENEWAL_ENDPOINT"'/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/client_id: PLACEHOLDER/client_id: '"$CLIENT_ID"'/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/provider: PLACEHOLDER/provider: local/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/private_key_path: PLACEHOLDER/private_key_path: '"/etc/newrelic-super-agent/keys/$CLIENT_ID.key"'/g' /etc/newrelic-super-agent/config.yaml
rm -rf "$TEMPORAL_FOLDER"
fi
config_host_monitoring:
Expand Down
51 changes: 22 additions & 29 deletions recipes/newrelic/infrastructure/super-agent/rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,11 @@ install:
echo "openssl is required to run the newrelic install. Please install openssl and re-run the installation." >&2
exit 17
fi
- |
IS_JQ_INSTALLED=$(which jq | wc -l)
if [ $IS_JQ_INSTALLED -eq 0 ] ; then
echo "jq is required to run the newrelic install. Please install jq and re-run the installation." >&2
exit 18
fi
- |
IS_MKTEMP_INSTALLED=$(which mktemp | wc -l)
if [ $IS_MKTEMP_INSTALLED -eq 0 ] ; then
echo "mktemp is required to run the newrelic install. Please install coreutils and re-run the installation." >&2
exit 19
exit 18
fi
- |
if [ "{{.AMAZON_LINUX_VERSION}}" != "2" ] && [ "{{.AMAZON_LINUX_VERSION}}" != "2023" ] ; then
Expand Down Expand Up @@ -420,41 +414,39 @@ install:
chmod 700 /etc/newrelic-super-agent/keys
TEMPORAL_FOLDER=$(mktemp -d newrelic-super-agent.XXXXXXXXXX)
trap "rm -rf $TEMPORAL_FOLDER" EXIT
openssl genrsa -out "$TEMPORAL_FOLDER/key" 4096
openssl rsa -in "$TEMPORAL_FOLDER/key" -pubout -out "$TEMPORAL_FOLDER/pub"
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
REGISTRATION_ENDPOINT=https://staging-iam-service.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://staging-iam-service.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
elif [ "{{.NEW_RELIC_REGION}}" = "EU" ]; then
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
else
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
fi
NAME="System Identity for $(hostname)"
for RETRY in 1 2 3; do
HTTP_CODE=$(echo '{ "query":
"{
mutation createSystemIdentity {
createSystemIdentity(
name: \"'$NAME'\",
organizationId: \"{{ .NEW_RELIC_ORGANIZATION }}\",
publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\"
) {
clientId,
id,
name
}
"mutation {
create(
name: \"'$NAME'\",
organizationId: \"{{ .NEW_RELIC_ORGANIZATION }}\",
publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\"
) {
clientId,
name
}
}"
}' | tr -d $'\n' | curl -X POST \
-s -w "%{http_code}" \
-H "Content-Type: application/json" \
-H "api-key: {{ .NEW_RELIC_API_KEY }}" \
-H "api-key: {{ .NEW_RELIC_LICENSE_KEY }}" \
-o "$TEMPORAL_FOLDER/response.json" \
--data @- \
"$REGISTRATION_ENDPOINT"
Expand All @@ -468,23 +460,24 @@ install:
sleep 2
done
ERROR_MESSAGE=$(jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ $HTTP_CODE -ne 200 ]; then
exit 99
fi
ERROR_MESSAGE=$(/usr/local/bin/newrelic utils jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Error creating an identity: $ERROR_MESSAGE"
exit
exit 100
fi
CLIENT_ID=$(jq 'data.createSystemIdentity.clientId' < "$TEMPORAL_FOLDER/response.json")
ID=$(jq 'data.createSystemIdentity.id' < "$TEMPORAL_FOLDER/response.json")
NAME=$(jq 'data.createSystemIdentity.name' < "$TEMPORAL_FOLDER/response.json")
CLIENT_ID=$(/usr/local/bin/newrelic utils jq -r '.data.createSystemIdentity.clientId' < "$TEMPORAL_FOLDER/response.json")
NAME=$(/usr/local/bin/newrelic utils jq -r '.data.createSystemIdentity.name' < "$TEMPORAL_FOLDER/response.json")
mv "$TEMPORAL_FOLDER/key" "/etc/newrelic-super-agent/keys/$CLIENT_ID.key"
# TODO: sed -i 's/token_url: PLACEHOLDER/token_url: '"$TOKEN_RENEWAL_ENDPOINT"'/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/client_id: PLACEHOLDER/client_id: '"$CLIENT_ID"'/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/provider: PLACEHOLDER/provider: local/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/private_key_path: PLACEHOLDER/private_key_path: '"/etc/newrelic-super-agent/keys/$CLIENT_ID.key"'/g' /etc/newrelic-super-agent/config.yaml
rm -rf "$TEMPORAL_FOLDER"
fi
config_host_monitoring:
Expand Down
51 changes: 22 additions & 29 deletions recipes/newrelic/infrastructure/super-agent/suse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,11 @@ install:
echo "openssl is required to run the newrelic install. Please install openssl and re-run the installation." >&2
exit 17
fi
- |
IS_JQ_INSTALLED=$(which jq | wc -l)
if [ $IS_JQ_INSTALLED -eq 0 ] ; then
echo "jq is required to run the newrelic install. Please install jq and re-run the installation." >&2
exit 18
fi
- |
IS_MKTEMP_INSTALLED=$(which mktemp | wc -l)
if [ $IS_MKTEMP_INSTALLED -eq 0 ] ; then
echo "mktemp is required to run the newrelic install. Please install coreutils and re-run the installation." >&2
exit 19
exit 18
fi
- |
IS_INFRA_AVAILABLE=$(curl -Is {{.NEW_RELIC_DOWNLOAD_URL}}preview/linux/zypp/sles/{{.SLES_VERSION}}/x86_64/newrelic-infra.repo | grep " 2[0-9][0-9] " | wc -l)
Expand Down Expand Up @@ -369,41 +363,39 @@ install:
chmod 700 /etc/newrelic-super-agent/keys
TEMPORAL_FOLDER=$(mktemp -d newrelic-super-agent.XXXXXXXXXX)
trap "rm -rf $TEMPORAL_FOLDER" EXIT
openssl genrsa -out "$TEMPORAL_FOLDER/key" 4096
openssl rsa -in "$TEMPORAL_FOLDER/key" -pubout -out "$TEMPORAL_FOLDER/pub"
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
REGISTRATION_ENDPOINT=https://staging-iam-service.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://staging-iam-service.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
elif [ "{{.NEW_RELIC_REGION}}" = "EU" ]; then
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
else
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/graphql
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/system-identity/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
fi
NAME="System Identity for $(hostname)"
for RETRY in 1 2 3; do
HTTP_CODE=$(echo '{ "query":
"{
mutation createSystemIdentity {
createSystemIdentity(
name: \"'$NAME'\",
organizationId: \"{{ .NEW_RELIC_ORGANIZATION }}\",
publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\"
) {
clientId,
id,
name
}
"mutation {
create(
name: \"'$NAME'\",
organizationId: \"{{ .NEW_RELIC_ORGANIZATION }}\",
publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\"
) {
clientId,
name
}
}"
}' | tr -d $'\n' | curl -X POST \
-s -w "%{http_code}" \
-H "Content-Type: application/json" \
-H "api-key: {{ .NEW_RELIC_API_KEY }}" \
-H "api-key: {{ .NEW_RELIC_LICENSE_KEY }}" \
-o "$TEMPORAL_FOLDER/response.json" \
--data @- \
"$REGISTRATION_ENDPOINT"
Expand All @@ -417,23 +409,24 @@ install:
sleep 2
done
ERROR_MESSAGE=$(jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ $HTTP_CODE -ne 200 ]; then
exit 99
fi
ERROR_MESSAGE=$(/usr/local/bin/newrelic utils jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Error creating an identity: $ERROR_MESSAGE"
exit
exit 100
fi
CLIENT_ID=$(jq 'data.createSystemIdentity.clientId' < "$TEMPORAL_FOLDER/response.json")
ID=$(jq 'data.createSystemIdentity.id' < "$TEMPORAL_FOLDER/response.json")
NAME=$(jq 'data.createSystemIdentity.name' < "$TEMPORAL_FOLDER/response.json")
CLIENT_ID=$(/usr/local/bin/newrelic utils jq -r '.data.createSystemIdentity.clientId' < "$TEMPORAL_FOLDER/response.json")
NAME=$(/usr/local/bin/newrelic utils jq -r '.data.createSystemIdentity.name' < "$TEMPORAL_FOLDER/response.json")
mv "$TEMPORAL_FOLDER/key" "/etc/newrelic-super-agent/keys/$CLIENT_ID.key"
# TODO: sed -i 's/token_url: PLACEHOLDER/token_url: '"$TOKEN_RENEWAL_ENDPOINT"'/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/client_id: PLACEHOLDER/client_id: '"$CLIENT_ID"'/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/provider: PLACEHOLDER/provider: local/g' /etc/newrelic-super-agent/config.yaml
sed -i 's/private_key_path: PLACEHOLDER/private_key_path: '"/etc/newrelic-super-agent/keys/$CLIENT_ID.key"'/g' /etc/newrelic-super-agent/config.yaml
rm -rf "$TEMPORAL_FOLDER"
fi
config_host_monitoring:
Expand Down

0 comments on commit 1b531f1

Please sign in to comment.