added return code handler for curl

This commit is contained in:
Nicolas Roman 2019-04-10 10:45:21 +02:00
parent 8c6c7d5b00
commit 5ad41113ad
2 changed files with 11 additions and 2 deletions

View file

@ -15,6 +15,8 @@ Options
--no-mail disable the mail hook --no-mail disable the mail hook
--db enable the database hook (default) --db enable the database hook (default)
--no-db disable the database hook --no-db disable the database hook
--api enable the API hook (default)
--no-api disable the API hook
--commit enable the commit hook (default) --commit enable the commit hook (default)
--no-commit disable the commit hook --no-commit disable the commit hook
--evocheck enable evocheck execution (default) --evocheck enable evocheck execution (default)

View file

@ -231,7 +231,7 @@ hook_api() {
fi fi
if [ "${DRY_RUN}" != "1" ] && [ -x "${CURL_BIN}" ]; then if [ "${DRY_RUN}" != "1" ] && [ -x "${CURL_BIN}" ]; then
curl -s -X POST \ API_RETURN_STATUS=$(curl -s -o /dev/null -X POST \
"${API_ENDPOINT}" -k \ "${API_ENDPOINT}" -k \
-F api_key="${API_KEY}" \ -F api_key="${API_KEY}" \
-F action=insertEvoMaintenance \ -F action=insertEvoMaintenance \
@ -240,7 +240,14 @@ hook_api() {
-F ipaddress="${IP}" \ -F ipaddress="${IP}" \
-F begin_date="${BEGIN_DATE}" \ -F begin_date="${BEGIN_DATE}" \
-F end_date='now()' \ -F end_date='now()' \
-F details="${MESSAGE}" > /dev/null -F details="${MESSAGE}" \
-w '%{http_code}')
if [ "$API_RETURN_STATUS" -eq 200 ]; then
echo "Evomaintenance successfully sent to the API."
else
printf "Error while sending data to the API (code %s).\n" "${API_RETURN_STATUS}"
fi
fi fi
} }