@cryptotaxi247 / netdata-1 / commits / 6eda68135

Adapt the claiming script to new API responses (#8245)

Hilari Moragrega committed Mar 1, 2020 at 23:11 UTC 6eda6813533ece2d8a1612b346dcc858b87ad5f8
1 file changed +53 -26
claim/netdata-claim.sh.in
+53 -26
@@ -17,39 +17,63 @@
17 #
18 # Error: The agent id is invalid; it does not fulfill the constraints
19 # HTTP Status code: 422
20 -# Error message: "invalid agent id"
20 +# Error key: "ErrInvalidNodeID"
21 +# Error message: "invalid node id"
22 # Exit code: 6
22 -#
23 -# Error: Invalid public key; the public key is empty or not present
23 +
24 +# Error: The agent hostname is invalid; it does not fulfill the constraints
25 # HTTP Status code: 422
25 -# Error message: "invalid public key"
26 +# Error key: "ErrInvalidNodeName"
27 +# Error message: "invalid node name"
28 # Exit code: 7
29 #
28 -# Error: Expired token
29 -# HTTP Status code: 403
30 -# Error message: "token has expired"
30 +# Error: At least one of the given rooms ids is invalid; it does not fulfill the constraints
31 +# HTTP Status code: 422
32 +# Error key: "ErrInvalidRoomID"
33 +# Error message: "invalid room id"
34 # Exit code: 8
35 #
33 -# Error: Invalid claiming token; missing, undecryptable, invalid payload...
36 +# Error: Invalid public key; the public key is empty or not present
37 # HTTP Status code: 422
35 -# Error message: "invalid token"
38 +# Error key: "ErrInvalidPublicKey"
39 +# Error message: "invalid public key"
40 # Exit code: 9
41 #
38 -# Error: Duplicate agent id; an agent with the same id but a different public key is already registered in the cloud
39 -# HTTP Status code: 409
40 -# Error message: "duplicate agent id"
42 +# Error: Expired, missing or invalid token
43 +# HTTP Status code: 403
44 +# Error key: "ErrForbidden"
45 +# Error message: "token expired" | "token not found" | "invalid token"
46 # Exit code: 10
47 #
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 space"
48 +# Error: Duplicate agent id; an agent with the same id is already registered in the cloud
49 +# HTTP Status code: 409
50 +# Error key: "ErrAlreadyClaimed"
51 +# Error message: "already claimed"
52 # Exit code: 11
53 #
54 +# Error: The node claiming process is still in progress.
55 +# HTTP Status code: 102
56 +# Error key: "ErrProcessingClaim"
57 +# Error message: "processing claiming"
58 +# Exit code: 12
59 +#
60 # Error: Internal server error. Any other unexpected error (DB problems, etc.)
61 # HTTP Status code: 500
51 -# Error message: "internal server error"
52 -# Exit code: 12
62 +# Error key: "ErrInternalServerError"
63 +# Error message: "Internal Server Error"
64 +# Exit code: 13
65 +#
66 +# Error: There was a timout processing the claim.
67 +# HTTP Status code: 504
68 +# Error key: "ErrGatewayTimeout"
69 +# Error message: "Gateway Timeout"
70 +# Exit code: 14
71 +#
72 +# Error: The service cannot handle the claiming request at this time.
73 +# HTTP Status code: 503
74 +# Error key: "ErrServiceUnavailable"
75 +# Error message: "Service Unavailable"
76 +# Exit code: 15
77
78 if command -v curl >/dev/null 2>&1 ; then
79 URLTOOL="curl"
@@ -194,15 +218,18 @@ fi
218
219 HTTP_STATUS_CODE=$(grep "HTTP" "${CLAIMING_DIR}/tmpout.txt" | awk -F " " '{print $2}')
220 if [ "${HTTP_STATUS_CODE}" -ne 204 ] ; then
197 - ERROR_MESSAGE=$(grep "\"error\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "error\":\"" '{print $2}' | sed s'/"}//g')
221 + ERROR_MESSAGE=$(grep "\"errorMsgKey\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "errorMsgKey\":\"" '{print $2}' | awk -F "\"" '{print $1}')
222 case ${ERROR_MESSAGE} in
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 node id") EXIT_CODE=10 ;;
204 - "claimed in another space") EXIT_CODE=11 ;;
205 - "internal server error") EXIT_CODE=12 ;;
223 + "ErrInvalidNodeID") EXIT_CODE=6 ;;
224 + "ErrInvalidNodeName") EXIT_CODE=7 ;;
225 + "ErrInvalidRoomID") EXIT_CODE=8 ;;
226 + "ErrInvalidPublicKey") EXIT_CODE=9 ;;
227 + "ErrForbidden") EXIT_CODE=10 ;;
228 + "ErrAlreadyClaimed") EXIT_CODE=11 ;;
229 + "ErrProcessingClaim") EXIT_CODE=12 ;;
230 + "ErrInternalServerError") EXIT_CODE=13 ;;
231 + "ErrGatewayTimeout") EXIT_CODE=14 ;;
232 + "ErrServiceUnavailable") EXIT_CODE=15 ;;
233 *) EXIT_CODE=5 ;;
234 esac
235 echo >&2 "Failed to claim node."