summaryrefslogtreecommitdiffstats
path: root/claim
diff options
context:
space:
mode:
authorMarkos Fountoulakis <44345837+mfundul@users.noreply.github.com>2020-03-21 23:01:58 +0200
committerGitHub <noreply@github.com>2020-03-21 23:01:58 +0200
commitb862a14064433c8b16cfc6a1e37d8dc21240b77a (patch)
tree4e02f7f047838881d27a250b148cf2d8d9c9805c /claim
parentdc9322438de56a8d1c22e186101ce2561cc22e4f (diff)
Fix syntax error in claiming script. (#8452)
* Fix syntax error in claiming script. * Synchronized error messages between claiming script and C code * Fix exit code check
Diffstat (limited to 'claim')
-rw-r--r--claim/claim.c19
-rwxr-xr-xclaim/netdata-claim.sh.in44
2 files changed, 34 insertions, 29 deletions
diff --git a/claim/claim.c b/claim/claim.c
index dd6f1bbf0c..0ecc0b712c 100644
--- a/claim/claim.c
+++ b/claim/claim.c
@@ -13,13 +13,16 @@ static char *claiming_errors[] = {
"Missing dependencies", // 3
"Failure to connect to endpoint", // 4
"Unknown HTTP error message", // 5
- "invalid agent id", // 6
- "invalid public key", // 7
- "token has expired", // 8
- "invalid token", // 9
- "duplicate agent id", // 10
- "claimed in another workspace", // 11
- "internal server error" // 12
+ "invalid node id", // 6
+ "invalid node name", // 7
+ "invalid room id", // 8
+ "invalid public key", // 9
+ "token expired/token not found/invalid token", // 10
+ "already claimed", // 11
+ "processing claiming", // 12
+ "Internal Server Error", // 13
+ "Gateway Timeout", // 14
+ "Service Unavailable" // 15
};
@@ -95,7 +98,7 @@ void claim_agent(char *claiming_arguments)
return;
}
errno = 0;
- unsigned maximum_known_exit_code = sizeof(claiming_errors) / sizeof(claiming_errors[0]);
+ unsigned maximum_known_exit_code = sizeof(claiming_errors) / sizeof(claiming_errors[0]) - 1;
if ((unsigned)exit_code > maximum_known_exit_code) {
error("Agent failed to be claimed with an unknown error.");
diff --git a/claim/netdata-claim.sh.in b/claim/netdata-claim.sh.in
index bcfa37a620..6284868aa7 100755
--- a/claim/netdata-claim.sh.in
+++ b/claim/netdata-claim.sh.in
@@ -203,7 +203,7 @@ fi
if [ "${URLTOOL}" = "curl" ] ; then
- URLCOMMAND="curl --connect-timeout 5 --retry 3 -s -i -X PUT -d \"@${CLAIMING_DIR}/tmpin.txt\""
+ URLCOMMAND="curl --connect-timeout 5 --retry 0 -s -i -X PUT -d \"@${CLAIMING_DIR}/tmpin.txt\""
if [ "${NOPROXY}" = "yes" ] ; then
URLCOMMAND="${URLCOMMAND} -x \"\""
elif [ -n "${PROXY}" ] ; then
@@ -258,27 +258,29 @@ if [ "${VERBOSE}" == 1 ] ; then
fi
HTTP_STATUS_CODE=$(grep "HTTP" "${CLAIMING_DIR}/tmpout.txt" | awk -F " " '{print $2}')
-if [ "${HTTP_STATUS_CODE}" -ne 204 ] ; then
- ERROR_MESSAGE=$(grep "\"errorMsgKey\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "errorMsgKey\":\"" '{print $2}' | awk -F "\"" '{print $1}')
- case ${ERROR_MESSAGE} in
- "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."
+
+if [ "${HTTP_STATUS_CODE}" = "204" ] ; then
rm -f "${CLAIMING_DIR}/tmpout.txt"
- exit $EXIT_CODE
+ echo -n "${ID}" >"${CLAIMING_DIR}/claimed_id"
+ rm -f "${CLAIMING_DIR}/token"
+ echo >&2 "Node was successfully claimed."
+ exit 0
fi
+ERROR_MESSAGE=$(grep "\"errorMsgKey\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "errorMsgKey\":\"" '{print $2}' | awk -F "\"" '{print $1}')
+case ${ERROR_MESSAGE} in
+ "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."
rm -f "${CLAIMING_DIR}/tmpout.txt"
-echo -n "${ID}" >"${CLAIMING_DIR}/claimed_id"
-rm -f "${CLAIMING_DIR}/token"
-echo >&2 "Node was successfully claimed."
+exit $EXIT_CODE