summaryrefslogtreecommitdiffstats
path: root/claim
diff options
context:
space:
mode:
authorHilari Moragrega <hilari@hilarimoragrega.com>2020-03-01 23:11:42 +0100
committerGitHub <noreply@github.com>2020-03-02 00:11:42 +0200
commit6eda6813533ece2d8a1612b346dcc858b87ad5f8 (patch)
tree55317fab585263906cf4477cd8f5a186ce77209c /claim
parenta04632ab3b334b97a228c5905bbb79c0d24c4cb2 (diff)
Adapt the claiming script to new API responses (#8245)
Diffstat (limited to 'claim')
-rwxr-xr-xclaim/netdata-claim.sh.in79
1 files changed, 53 insertions, 26 deletions
diff --git a/claim/netdata-claim.sh.in b/claim/netdata-claim.sh.in
index 03d9261374..e8b10d7aa3 100755
--- a/claim/netdata-claim.sh.in
+++ b/claim/netdata-claim.sh.in
@@ -17,39 +17,63 @@
#
# Error: The agent id is invalid; it does not fulfill the constraints
# HTTP Status code: 422
-# Error message: "invalid agent id"
+# Error key: "ErrInvalidNodeID"
+# Error message: "invalid node id"
# Exit code: 6
-#
-# Error: Invalid public key; the public key is empty or not present
+
+# Error: The agent hostname is invalid; it does not fulfill the constraints
# HTTP Status code: 422
-# Error message: "invalid public key"
+# Error key: "ErrInvalidNodeName"
+# Error message: "invalid node name"
# Exit code: 7
#
-# Error: Expired token
-# HTTP Status code: 403
-# Error message: "token has expired"
+# Error: At least one of the given rooms ids is invalid; it does not fulfill the constraints
+# HTTP Status code: 422
+# Error key: "ErrInvalidRoomID"
+# Error message: "invalid room id"
# Exit code: 8
#
-# Error: Invalid claiming token; missing, undecryptable, invalid payload...
+# Error: Invalid public key; the public key is empty or not present
# HTTP Status code: 422
-# Error message: "invalid token"
+# Error key: "ErrInvalidPublicKey"
+# Error message: "invalid public key"
# Exit code: 9
#
-# Error: Duplicate agent id; an agent with the same id but a different public key is already registered in the cloud
-# HTTP Status code: 409
-# Error message: "duplicate agent id"
+# Error: Expired, missing or invalid token
+# HTTP Status code: 403
+# Error key: "ErrForbidden"
+# Error message: "token expired" | "token not found" | "invalid token"
# Exit code: 10
#
-# Error: Already claimed in another space;
-# this agent (same id, same public key) already belongs to another space
-# HTTP Status code: 403
-# Error message: "claimed in another space"
+# Error: Duplicate agent id; an agent with the same id is already registered in the cloud
+# HTTP Status code: 409
+# Error key: "ErrAlreadyClaimed"
+# Error message: "already claimed"
# Exit code: 11
#
+# Error: The node claiming process is still in progress.
+# HTTP Status code: 102
+# Error key: "ErrProcessingClaim"
+# Error message: "processing claiming"
+# Exit code: 12
+#
# Error: Internal server error. Any other unexpected error (DB problems, etc.)
# HTTP Status code: 500
-# Error message: "internal server error"
-# Exit code: 12
+# Error key: "ErrInternalServerError"
+# Error message: "Internal Server Error"
+# Exit code: 13
+#
+# Error: There was a timout processing the claim.
+# HTTP Status code: 504
+# Error key: "ErrGatewayTimeout"
+# Error message: "Gateway Timeout"
+# Exit code: 14
+#
+# Error: The service cannot handle the claiming request at this time.
+# HTTP Status code: 503
+# Error key: "ErrServiceUnavailable"
+# Error message: "Service Unavailable"
+# Exit code: 15
if command -v curl >/dev/null 2>&1 ; then
URLTOOL="curl"
@@ -194,15 +218,18 @@ fi
HTTP_STATUS_CODE=$(grep "HTTP" "${CLAIMING_DIR}/tmpout.txt" | awk -F " " '{print $2}')
if [ "${HTTP_STATUS_CODE}" -ne 204 ] ; then
- ERROR_MESSAGE=$(grep "\"error\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "error\":\"" '{print $2}' | sed s'/"}//g')
+ ERROR_MESSAGE=$(grep "\"errorMsgKey\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "errorMsgKey\":\"" '{print $2}' | awk -F "\"" '{print $1}')
case ${ERROR_MESSAGE} in
- "invalid node id") EXIT_CODE=6 ;;
- "invalid public key") EXIT_CODE=7 ;;
- "token has expired") EXIT_CODE=8 ;;
- "invalid token") EXIT_CODE=9 ;;
- "duplicate node id") EXIT_CODE=10 ;;
- "claimed in another space") EXIT_CODE=11 ;;
- "internal server error") EXIT_CODE=12 ;;
+ "ErrInvalidNodeID") EXIT_CODE=6 ;;
+ "ErrInvalidNodeName") EXIT_CODE=7 ;;
+ "ErrInvalidRoomID") EXIT_CODE=8 ;;
+ "ErrInvalidPublicKey") EXIT_CODE=9 ;;
+ "ErrForbidden") EXIT_CODE=10 ;;
+ "ErrAlreadyClaimed") EXIT_CODE=11 ;;
+ "ErrProcessingClaim") EXIT_CODE=12 ;;
+ "ErrInternalServerError") EXIT_CODE=13 ;;
+ "ErrGatewayTimeout") EXIT_CODE=14 ;;
+ "ErrServiceUnavailable") EXIT_CODE=15 ;;
*) EXIT_CODE=5 ;;
esac
echo >&2 "Failed to claim node."