Fix claiming script (#8220)
cosmix committed
Feb 27, 2020 at 13:18 UTC
b252345a4ac0e5c0a83907830984f63ab8a9d52b
1 file changed
+12
-12
claim/netdata-claim.sh.in
+12
-12
@@ -12,7 +12,7 @@
12
# Exit code: 5 - Unknown HTTP error message
13
#
14
# OK: Agent claimed successfully
15
-# HTTP Status code: 200
15
+# HTTP Status code: 204
16
# Exit code: 0
17
#
18
# Error: The agent id is invalid; it does not fulfill the constraints
@@ -40,10 +40,10 @@
40
# Error message: "duplicate agent id"
41
# Exit code: 10
42
#
43
-# Error: Already claimed in another workspace;
44
-# this agent (same id, same public key) already belongs to another workspace
43
+# Error: Already claimed in another space;
44
+# this agent (same id, same public key) already belongs to another space
45
# HTTP Status code: 403
46
-# Error message: "claimed in another workspace"
46
+# Error message: "claimed in another space"
47
# Exit code: 11
48
#
49
# Error: Internal server error. Any other unexpected error (DB problems, etc.)
@@ -142,7 +142,7 @@ if [ ! -f "${CLAIMING_DIR}/public.pem" ] ; then
142
fi
143
fi
144
145
-TARGET_URL="${URL_BASE}/api/v1/workspaces/agents/${ID}"
145
+TARGET_URL="${URL_BASE}/api/v1/spaces/nodes/${ID}"
146
# shellcheck disable=SC2002
147
KEY=$(cat "${CLAIMING_DIR}/public.pem" | tr '\n' '!' | sed -e 's/!/\\n/g')
148
# shellcheck disable=SC2001
@@ -150,7 +150,7 @@ KEY=$(cat "${CLAIMING_DIR}/public.pem" | tr '\n' '!' | sed -e 's/!/\\n/g')
150
151
cat > "${CLAIMING_DIR}/tmpin.txt" <<EMBED_JSON
152
{
153
- "agent": {
153
+ "node": {
154
"id": "$ID",
155
"hostname": "$HOSTNAME"
156
},
@@ -193,19 +193,19 @@ if [ "${URLCOMMAND_EXIT_CODE}" -ne 0 ] ; then
193
fi
194
195
HTTP_STATUS_CODE=$(grep "HTTP" "${CLAIMING_DIR}/tmpout.txt" | awk -F " " '{print $2}')
196
-if [ "${HTTP_STATUS_CODE}" -ne 200 ] ; then
196
+if [ "${HTTP_STATUS_CODE}" -ne 204 ] ; then
197
ERROR_MESSAGE=$(grep "\"error\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "error\":\"" '{print $2}' | sed s'/"}//g')
198
case ${ERROR_MESSAGE} in
199
- "invalid agent id") EXIT_CODE=6 ;;
199
+ "invalid node id") EXIT_CODE=6 ;;
200
"invalid public key") EXIT_CODE=7 ;;
201
"token has expired") EXIT_CODE=8 ;;
202
"invalid token") EXIT_CODE=9 ;;
203
- "duplicate agent id") EXIT_CODE=10 ;;
204
- "claimed in another workspace") EXIT_CODE=11 ;;
203
+ "duplicate node id") EXIT_CODE=10 ;;
204
+ "claimed in another space") EXIT_CODE=11 ;;
205
"internal server error") EXIT_CODE=12 ;;
206
*) EXIT_CODE=5 ;;
207
esac
208
- echo >&2 "Failed to claim agent."
208
+ echo >&2 "Failed to claim node."
209
rm -f "${CLAIMING_DIR}/tmpout.txt"
210
exit $EXIT_CODE
211
fi
@@ -213,4 +213,4 @@ fi
213
rm -f "${CLAIMING_DIR}/tmpout.txt"
214
echo -n "${ID}" >"${CLAIMING_DIR}/claimed_id"
215
rm -f "${CLAIMING_DIR}/token"
216
-echo >&2 "Agent was successfully claimed."
216
+echo >&2 "Node was successfully claimed."