changed error handling for curl and the backend

This commit is contained in:
Nicolas Roman 2019-04-10 14:49:02 +02:00
parent fe095a20f7
commit f7fa476de8
1 changed files with 8 additions and 8 deletions

View File

@ -225,13 +225,13 @@ hook_db() {
hook_api() {
if [ "${VERBOSE}" = "1" ]; then
printf "\n********** API call **************\n"
printf "curl -s -X POST %s -F action=insertEvoMaintenance -F hostname=%s -F userid=%s -F ipaddress=%s -F begin_date=%s -F end_date='now()' -F details=%s" \
"${API_ENDPOINT}" "${HOSTNAME}" "${USER}" "${IP}" "${BEGIN_DATE}" "${MESSAGE}"
printf "curl -f -s -S -X POST [REDACTED] -k -F api_key=[REDACTED] -F action=insertEvoMaintenance -F hostname=%s -F userid=%s -F ipaddress=%s -F begin_date=%s -F end_date='now()' -F details=%s" \
"${HOSTNAME}" "${USER}" "${IP}" "${BEGIN_DATE}" "${MESSAGE}"
printf "\n***********************************\n"
fi
if [ "${DRY_RUN}" != "1" ] && [ -x "${CURL_BIN}" ]; then
API_RETURN_STATUS=$(curl -s -o /dev/null -X POST \
API_RETURN_STATUS=$(curl -f -s -S -X POST \
"${API_ENDPOINT}" -k \
-F api_key="${API_KEY}" \
-F action=insertEvoMaintenance \
@ -240,13 +240,13 @@ hook_api() {
-F ipaddress="${IP}" \
-F begin_date="${BEGIN_DATE}" \
-F end_date='now()' \
-F details="${MESSAGE}" \
-w '%{http_code}')
-F details="${MESSAGE}")
if [ "$API_RETURN_STATUS" -eq 200 ]; then
echo "Evomaintenance successfully sent to the API."
# either cURL or the API backend can throw an error, otherwise it returns this JSON response
if [ "$API_RETURN_STATUS" = '{"status":"Ok"}' ]; then
echo "API call OK."
else
printf "Error while sending data to the API (code %s).\n" "${API_RETURN_STATUS}"
echo "API call FAILED."
fi
fi
}