Skip to content

Commit

Permalink
add all distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-makes committed Jul 18, 2024
1 parent d25bae9 commit 1438048
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 29 deletions.
34 changes: 19 additions & 15 deletions recipes/newrelic/infrastructure/super-agent/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ install:
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
fi
- |
if [ -n "{{.DEBIAN_CODENAME}}" ]; then
IS_AGENT_AVAILABLE=$(curl -Is {{.NEW_RELIC_DOWNLOAD_URL}}preview/linux/apt/dists/{{.DEBIAN_CODENAME}}/InRelease | grep " 2[0-9][0-9] " | wc -l)
Expand Down Expand Up @@ -429,13 +435,23 @@ install:
sed -i '/^\s*#\s*endpoint: https:\/\/opamp/s/# //' /etc/newrelic-super-agent/config.yaml
fi
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" == "" ]; then
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ]; then
sed -i '/^\s*api-key:/s/^/#/' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*headers:/s/^/#/' /etc/newrelic-super-agent/config.yaml
else
sed -i '/^\s*#\s*api-key:/s/# //' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*headers:/s/# //' /etc/newrelic-super-agent/config.yaml
fi
- |
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
sed -i 's/\(endpoint: https:\/\/opamp.\).*/\1'"staging-service.newrelic.com\/v1\/opamp"'/' /etc/newrelic-super-agent/config.yaml
elif [ "{{.NEW_RELIC_REGION}}" = "EU" ]; then
sed -i 's/\(endpoint: https:\/\/opamp.\).*/\1'"service.eu.newrelic.com\/v1\/opamp"'/' /etc/newrelic-super-agent/config.yaml
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:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" != "" ]; then
sed -i '/^\s*auth_config: PLACEHOLDER/s/^/#/' /etc/newrelic-super-agent/config.yaml
Expand All @@ -450,25 +466,15 @@ install:
sed -i '/^\s*#\s*provider: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*private_key_path: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
fi
- |
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
sed -i 's/\(endpoint: https:\/\/opamp.\).*/\1'"staging-service.newrelic.com\/v1\/opamp"'/' /etc/newrelic-super-agent/config.yaml
elif [ "{{.NEW_RELIC_REGION}}" = "EU" ]; then
sed -i 's/\(endpoint: https:\/\/opamp.\).*/\1'"service.eu.newrelic.com\/v1\/opamp"'/' /etc/newrelic-super-agent/config.yaml
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:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" != "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" != "" ]; then
set -o nounset,pipefail
set -uo pipefail
mkdir /etc/newrelic-super-agent/keys
chown root:root /etc/newrelic-super-agent/keys
chmod 700 /etc/newrelic-super-agent/keys
TEMPORAL_FOLDER=$(mkdir -p "$TMP/super-agent-installation-$RANDOM")
TEMPORAL_FOLDER=$(mktemp -d newrelic-super-agent.XXXXXXXXXX)
openssl genrsa -out "$TEMPORAL_FOLDER/key" 4096
openssl rsa -in "$TEMPORAL_FOLDER/key" -pubout -out "$TEMPORAL_FOLDER/pub"
Expand Down Expand Up @@ -507,8 +513,6 @@ install:
-o "$TEMPORAL_FOLDER/response.json" \
--data @- \
"$REGISTRATION_ENDPOINT"
--data '{ "query": "mutation { createSystemIdentity(name: \"'${NAME}'\", organizationId: \"'${ORGANIZATION_ID}'\", publicKey: \"'$(openssl enc -base64 -A -in "$TEMPORAL_FOLDER/pub")'\") { id name organizationId clientId publicKey } }" }' \
${REGISTRATION_ENDPOINT}
)
if [ $HTTP_CODE -eq 200 ]; then
Expand Down
131 changes: 124 additions & 7 deletions recipes/newrelic/infrastructure/super-agent/rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ install:
- task: config_supervisors
- task: config_fleet_id
- task: config_opamp
- task: config_super_agent_auth
- task: config_host_monitoring
- task: update_otel_mem_limit
- task: update_otel_end_point
Expand Down Expand Up @@ -158,6 +159,30 @@ install:
echo "touch is required to run the newrelic install. Please install touch and re-run the installation." >&2
exit 15
fi
- |
IS_CURL_INSTALLED=$(which curl | wc -l)
if [ $IS_CURL_INSTALLED -eq 0 ] ; then
echo "curl is required to run the newrelic install. Please install curl and re-run the installation." >&2
exit 16
fi
- |
IS_OPENSSL_INSTALLED=$(which openssl | wc -l)
if [ $IS_OPENSSL_INSTALLED -eq 0 ] ; then
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
fi
- |
if [ "{{.AMAZON_LINUX_VERSION}}" != "2" ] && [ "{{.AMAZON_LINUX_VERSION}}" != "2023" ] ; then
REPO_URL=$(echo -n "{{.NEW_RELIC_DOWNLOAD_URL}}preview/linux/yum/{{.REPO_DIR}}/{{.DISTRO_VERSION}}/{{.ARCH}}/newrelic-infra.repo")
Expand Down Expand Up @@ -342,16 +367,20 @@ install:
config_opamp:
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ] ; then
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ]; then
sed -i '/^\s*opamp:/s/^/#/' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*endpoint: https:\/\/opamp/s/^/#/' /etc/newrelic-super-agent/config.yaml
else
sed -i 's/s*#\s*opamp:/opamp:/g' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*endpoint: https:\/\/opamp/s/# //' /etc/newrelic-super-agent/config.yaml
fi
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ]; then
sed -i '/^\s*api-key:/s/^/#/' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*headers:/s/^/#/' /etc/newrelic-super-agent/config.yaml
else
sed -i 's/s*#\s*opamp:/opamp:/g' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*endpoint: https:\/\/opamp/s/#//' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*api-key:/s/#//' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*headers:/s/#//' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*api-key:/s/# //' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*headers:/s/# //' /etc/newrelic-super-agent/config.yaml
fi
- |
if [ "{{.NEW_RELIC_REGION}}" = "STAGING" ]; then
Expand All @@ -361,9 +390,97 @@ 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:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" != "false" ] ; then
sed -i 's/api-key: API_KEY_HERE/api-key: {{.NEW_RELIC_LICENSE_KEY}}/g' /etc/newrelic-super-agent/config.yaml
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" != "" ]; then
sed -i '/^\s*auth_config: PLACEHOLDER/s/^/#/' /etc/newrelic-super-agent/config.yaml
# TODO: sed -i '/^\s*token_url: PLACEHOLDER/s/^/#/' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*client_id: PLACEHOLDER/s/^/#/' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*provider: PLACEHOLDER/s/^/#/' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*private_key_path: PLACEHOLDER/s/^/#/' /etc/newrelic-super-agent/config.yaml
else
sed -i '/^\s*#\s*auth_config: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
# TODO: sed -i '/^\s*#\s*token_url: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*client_id: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*provider: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
sed -i '/^\s*#\s*private_key_path: PLACEHOLDER/s/# //' /etc/newrelic-super-agent/config.yaml
fi
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" != "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" != "" ]; then
set -uo pipefail
mkdir /etc/newrelic-super-agent/keys
chown root:root /etc/newrelic-super-agent/keys
chmod 700 /etc/newrelic-super-agent/keys
TEMPORAL_FOLDER=$(mktemp -d newrelic-super-agent.XXXXXXXXXX)
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
# TODO: TOKEN_RENEWAL_ENDPOINT
elif [ "{{.NEW_RELIC_REGION}}" = "EU" ]; then
REGISTRATION_ENDPOINT=https://iam-service.eu.vip.cf.nr-ops.net/graphql
# TODO: TOKEN_RENEWAL_ENDPOINT
else
REGISTRATION_ENDPOINT=https://iam-service.vip.cf.nr-ops.net/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
}
}
}"
}' | tr -d $'\n' | curl -X POST \
-s -w "%{http_code}" \
-H "Content-Type: application/json" \
-H "api-key: {{ .NEW_RELIC_API_KEY }}" \
-o "$TEMPORAL_FOLDER/response.json" \
--data @- \
"$REGISTRATION_ENDPOINT"
)
if [ $HTTP_CODE -eq 200 ]; then
break
fi
echo "Error creating the new system identity. The API endpoint returned $HTTP_CODE. Retrying ($RETRY/3)..."
sleep 2
done
ERROR_MESSAGE=$(jq -r '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json")
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Error creating an identity: $ERROR_MESSAGE"
exit
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")
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
Loading

0 comments on commit 1438048

Please sign in to comment.