Skip to content

Commit d20b884

Browse files
committed
adding password to setup script in kickstarter
1 parent 2ba5dd9 commit d20b884

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

grafana_v2/kickstart_v2/setup.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ PROJECT="demo"
1010

1111
# this script can take a second argument; the folder from which it should load dashboards
1212
# by default it will use ../dashboards/grafana_v9-11/software/basic
13+
# this script can take a third argument; the grafana password (defaults to 'admin')
14+
15+
# Set default password
16+
password="admin"
1317

1418
if [ $# -eq 0 ]; then
15-
echo "using default endpoint and folder"
19+
echo "using default endpoint, folder, and password"
1620
folder="../dashboards/grafana_v9-11/software/basic/*"
1721
fi
1822

1923
if [ $# -eq 1 ]; then
20-
echo "using endpoint $1 and default folder"
24+
echo "using endpoint $1, default folder, and default password"
2125
folder="../dashboards/grafana_v9-11/software/basic/*"
2226
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
2327
sed -i "s/host.docker.internal/$1/g" prometheus.yml
@@ -28,8 +32,24 @@ fi
2832

2933
if [ $# -eq 2 ]; then
3034
if [ -d "$2" ]; then
31-
echo "using endpoint $1 and folder $2"
35+
echo "using endpoint $1, folder $2, and default password"
36+
folder="$2/*"
37+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
38+
sed -i "s/host.docker.internal/$1/g" prometheus.yml
39+
elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX
40+
sed -i '' "s/host.docker.internal/$1/g" prometheus.yml
41+
fi
42+
else
43+
echo "second argument must be a directory!"
44+
exit 1
45+
fi
46+
fi
47+
48+
if [ $# -eq 3 ]; then
49+
if [ -d "$2" ]; then
50+
echo "using endpoint $1, folder $2, and password $3"
3251
folder="$2/*"
52+
password="$3"
3353
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
3454
sed -i "s/host.docker.internal/$1/g" prometheus.yml
3555
elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX
@@ -54,7 +74,7 @@ done
5474
# create prometheus datasource
5575
echo ""
5676
echo "create grafana datasource"
57-
curl -s 'http://admin:admin@localhost:3000/api/datasources' \
77+
curl -s "http://admin:$password@localhost:3000/api/datasources" \
5878
--header 'Accept: application/json' \
5979
--header 'Content-Type: application/json' \
6080
--data '{ "name": "prometheus-demo",
@@ -68,13 +88,13 @@ curl -s 'http://admin:admin@localhost:3000/api/datasources' \
6888
echo ""
6989
echo ""
7090
echo "perform datasource health check"
71-
data=`curl -s 'http://admin:admin@localhost:3000/api/datasources/name/prometheus-demo'`
91+
data=`curl -s "http://admin:$password@localhost:3000/api/datasources/name/prometheus-demo"`
7292

7393
str=${data#*\"uid\"\:\"*}
7494
uid=${str%%\"*}
7595

7696
# use the datasource's uid to check its health
77-
data=`curl -s 'http://admin:admin@localhost:3000/api/datasources/uid/'$uid'/health'`
97+
data=`curl -s "http://admin:$password@localhost:3000/api/datasources/uid/$uid/health"`
7898

7999
str=${data#*\"status\"\:\"*}
80100
status=${str%%\"*}
@@ -95,7 +115,7 @@ for file in $folder; do
95115
echo "$file"
96116
d=`cat "$file"`
97117
echo "{ \"dashboard\": $d,\"folderId\": 0, \"message\": \"Created by Redis demo setup script\", \"overwrite\": false}" \
98-
| sed s/\"uid\"\:\ \"\$\{DS_PROMETHEUS\}\"/\"name\"\:\ \"prometheus-demo\"/g | curl -s 'http://admin:admin@localhost:3000/api/dashboards/db' \
118+
| sed s/\"uid\"\:\ \"\$\{DS_PROMETHEUS\}\"/\"name\"\:\ \"prometheus-demo\"/g | curl -s "http://admin:$password@localhost:3000/api/dashboards/db" \
99119
--header 'Accept: application/json' \
100120
--header 'Content-Type: application/json' \
101121
--data-binary @-
@@ -104,7 +124,7 @@ done
104124

105125
echo ""
106126
echo "You can open a browser and access Grafana, and Prometheus at:"
107-
echo " Grafana: http://localhost:3000 (username=admin and password=admin)"
127+
echo " Grafana: http://localhost:3000 (username=admin and password=$password)"
108128
echo " Prometheus: http://localhost:9090"
109129
echo ""
110130
echo ""

grafana_v2/kickstart_v2/terraform/aws/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ resource "null_resource" "run-kickstart" {
265265
inline = [
266266
"cd redis-enterprise-observability/grafana_v2/kickstart_v2",
267267
"git checkout main",
268-
"./setup.sh ${local.redis_db_primary_fqdn} ../dashboards/grafana_v9-11/cloud/basic",
268+
"./setup.sh ${local.redis_db_primary_fqdn} ../dashboards/grafana_v9-11/cloud/basic ${var.grafana_password}",
269269
]
270270
}
271271
}

grafana_v2/kickstart_v2/terraform/aws/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,11 @@ variable "existing_security_group_id" {
8585
type = string
8686
default = null
8787
description = "ID of existing security group to use. Required when existing_vpc_id is provided."
88+
}
89+
90+
variable "grafana_password" {
91+
type = string
92+
description = "The Grafana admin password"
93+
default = "admin"
94+
sensitive = true
8895
}

grafana_v2/kickstart_v2/terraform/gcp/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ resource "null_resource" "run-kickstart" {
206206
inline = [
207207
"cd redis-enterprise-observability/grafana_v2/kickstart_v2",
208208
"git checkout ${var.git_branch}",
209-
"./setup.sh ${local.redis_db_primary_fqdn} ../dashboards/grafana_v9-11/cloud/basic",
209+
"./setup.sh ${local.redis_db_primary_fqdn} ../dashboards/grafana_v9-11/cloud/basic ${var.grafana_password}",
210210
]
211211
}
212212
}

grafana_v2/kickstart_v2/terraform/gcp/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,11 @@ variable "git_branch" {
9191
type = string
9292
description = "The git branch to use for the Grafana dashboards and Prometheus rules"
9393
default = "main"
94+
}
95+
96+
variable "grafana_password" {
97+
type = string
98+
description = "The Grafana admin password"
99+
default = "admin"
100+
sensitive = true
94101
}

0 commit comments

Comments
 (0)