201 lines
6.4 KiB
Bash
Executable File
201 lines
6.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Author : NTT Data AG
|
|
# Date : 16-05-2023
|
|
|
|
# Installs New Relic agent on target machine
|
|
|
|
show_help() {
|
|
cat <<EOF
|
|
Usage: $0 [options]
|
|
|
|
Options:
|
|
-h, --help Show help information
|
|
-e, --enironment <environment> Set environment for New Relic installation (k8s | helm | docker | linux)
|
|
-a, --account <account_number> Set account id (int)
|
|
-k, --api-key <api_key> Set API key
|
|
-r, --region <region> Set New Relic Region (EU)
|
|
-n, --cluster-name <cluster-name> Set cluster name. Required for k8s
|
|
-l, --license-key <license-key> Set license key
|
|
EOF
|
|
}
|
|
|
|
show_allowed_environments () {
|
|
cat <<EOF
|
|
Supported Environments:
|
|
- k8s
|
|
- helm not supported yet
|
|
- docker not supported yet
|
|
- linux not supported yet
|
|
EOF
|
|
}
|
|
|
|
environment=""
|
|
account_id=""
|
|
api_key=""
|
|
region=""
|
|
cluster_name=""
|
|
license_key=""
|
|
|
|
setup_k8s () {
|
|
curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh \
|
|
| bash && NEW_RELIC_CLI_SKIP_CORE=1 NR_CLI_CLUSTERNAME=$cluster_name \
|
|
NR_CLI_NAMESPACE=newrelic NR_CLI_PRIVILEGED=true NR_CLI_LOW_DATA_MODE=true \
|
|
NR_CLI_KSM=true NR_CLI_KUBE_EVENTS=true NR_CLI_PROMETHEUS_AGENT=true \
|
|
NR_CLI_PROMETHEUS_AGENT_LOW_DATA_MODE=true NR_CLI_CURATED=false NR_CLI_LOGGING=true \
|
|
NR_CLI_LOGGING_LOW_DATA_MODE=true NEW_RELIC_API_KEY=$api_key \
|
|
NEW_RELIC_ACCOUNT_ID=$account_id NEW_RELIC_REGION=$region\
|
|
/usr/local/bin/newrelic install -n kubernetes-open-source-integration
|
|
}
|
|
|
|
setup_docker () {
|
|
# docker run \
|
|
# -d \
|
|
# --name newrelic-infra \
|
|
# --network=host \
|
|
# --cap-add=SYS_PTRACE \
|
|
# --privileged \
|
|
# --pid=host \
|
|
# -v "/:/host:ro" \
|
|
# -v "/var/run/docker.sock:/var/run/docker.sock" \
|
|
# -e NRIA_LICENSE_KEY=$license_key \
|
|
# newrelic/infrastructure:latest
|
|
echo "Docker not supported yet"
|
|
exit 1
|
|
}
|
|
|
|
setup_linux () {
|
|
# curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY=$api_key NEW_RELIC_ACCOUNT_ID=$account_id NEW_RELIC_REGION=$region /usr/local/bin/newrelic install -y
|
|
echo "Linux not supported yet"
|
|
exit 1
|
|
}
|
|
|
|
setup_helm () {
|
|
# function ver { printf "%03d%03d" $(echo "$1" | tr '.' ' '); } && \
|
|
# K8S_VERSION=$(kubectl version --short 2>&1 | grep 'Server Version' | awk -F' v' '{ print $2; }' | awk -F. '{ print $1"."$2; }') && \
|
|
# if [[ $(ver $K8S_VERSION) -lt $(ver "1.25") ]]; then KSM_IMAGE_VERSION="v2.6.0"; else KSM_IMAGE_VERSION="v2.7.0"; fi && \
|
|
# helm repo add newrelic https://helm-charts.newrelic.com && helm repo update && \
|
|
# kubectl create namespace newrelic ; helm upgrade --install newrelic-bundle newrelic/nri-bundle \
|
|
# --set global.licenseKey=$license_key \
|
|
# --set global.cluster=$cluster_name \
|
|
# --namespace=newrelic \
|
|
# --set newrelic-infrastructure.privileged=true \
|
|
# --set global.lowDataMode=true \
|
|
# --set kube-state-metrics.image.tag=${KSM_IMAGE_VERSION} \
|
|
# --set kube-state-metrics.enabled=true \
|
|
# --set kubeEvents.enabled=true \
|
|
# --set newrelic-prometheus-agent.enabled=true \
|
|
# --set newrelic-prometheus-agent.lowDataMode=true \
|
|
# --set newrelic-prometheus-agent.config.kubernetes.integrations_filter.enabled=false \
|
|
# --set logging.enabled=true \
|
|
# --set newrelic-logging.lowDataMode=true
|
|
echo "helm not supported yet"
|
|
exit 1
|
|
}
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
case "$1" in
|
|
-h|--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
-e|--environment)
|
|
if [ "$2" ]; then
|
|
environment="$2"
|
|
shift 2
|
|
else
|
|
echo "Error: Missing argument for $1 option"
|
|
show_help
|
|
exit 1
|
|
fi
|
|
;;
|
|
-a|--account)
|
|
if [ "$2" ]; then
|
|
account_id="$2"
|
|
shift 2
|
|
else
|
|
if [ "$environment" == "k8s" ] || [ "$environment" == "linux"]; then
|
|
echo "Error: Missing argument for $1 option"
|
|
show_help
|
|
exit 1
|
|
else
|
|
$account_id = ""
|
|
fi
|
|
fi
|
|
;;
|
|
-k|--api-key)
|
|
if [ "$2" ]; then
|
|
api_key="$2"
|
|
shift 2
|
|
else
|
|
if [ "$environment" == "k8s" ] || [ "$environment" == "linux"]; then
|
|
echo "Error: Missing argument for $1 option"
|
|
show_help
|
|
exit 1
|
|
else
|
|
$api_key = ""
|
|
fi
|
|
fi
|
|
;;
|
|
-r|--region)
|
|
if [ "$2" ]; then
|
|
region="$2"
|
|
shift 2
|
|
else
|
|
if [ "$environment" == "k8s" ] || [ "$environment" == "linux"]; then
|
|
echo "Error: Missing argument for $1 option"
|
|
show_help
|
|
exit 1
|
|
else
|
|
$region = ""
|
|
fi
|
|
fi
|
|
;;
|
|
-n|--cluster-name)
|
|
if [ "$2" ]; then
|
|
cluster_name="$2"
|
|
shift 2
|
|
else
|
|
if [ "$environment" == "k8s" ] || [ "$environment" == "helm"]; then
|
|
echo "Error: Missing argument for $1 option"
|
|
show_help
|
|
exit 1
|
|
else
|
|
$cluster_name = ""
|
|
fi
|
|
fi
|
|
;;
|
|
-l|--license-key)
|
|
if [ "$2" ]; then
|
|
license_key="$2"
|
|
shift 2
|
|
else
|
|
if [ "$environment" == "docker" ] || [ "$environment" == "helm"]; then
|
|
echo "Error: Missing argument for $1 option"
|
|
show_help
|
|
exit 1
|
|
else
|
|
$license_key = ""
|
|
fi
|
|
fi
|
|
;;
|
|
*)
|
|
echo "Error: Unrecognized option $1"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ "$environment" = "k8s" ]; then
|
|
if [ -z "$account_id" ] || [ -z "$api_key" ] || [ -z "$region" ] || [ -z "$cluster_name" ]; then
|
|
echo "Error: Missing required options for k8s environment"
|
|
show_help
|
|
exit 1
|
|
fi
|
|
setup_k8s
|
|
else
|
|
echo "Error: $environment is not supported yet."
|
|
show_allowed_environments
|
|
exit 1
|
|
fi |