check_curl: format perfdata, set default timeout

This commit is contained in:
Cyberes 2023-06-22 13:23:41 -06:00
parent b291fd1a3f
commit 284843c174
1 changed files with 9 additions and 5 deletions

View File

@ -13,6 +13,7 @@ usage() {
-p Print the curl command and exit
-R Set curl --resolve option.
-M Set the HTTP mode (default: GET)
-t Timeout in seconds
-s Ignore the response status code."
exit 3
}
@ -26,7 +27,7 @@ HEADERS=""
PRINT_CURL=""
RESOLVE=""
IGNORE_STATUS=""
TIMEOUT=""
TIMEOUT="30"
HTTP_METHOD="-X GET"
# Parse arguments
@ -384,13 +385,16 @@ if [ "$IGNORE_STATUS" != "yes" ] && [ "$HTTP_CODE" -ne 200 ]; then
exit 2
fi
RESPONSE_TIME_MS=$(echo "$RESPONSE_TIME * 1000" | bc)
RESPONSE_TIME_MS=$(echo "$RESPONSE_TIME * 1000" | bc | xargs printf "%0.0f\n")
perfdata="response_time=${RESPONSE_TIME_MS}ms;$WARN_TIME;$CRIT_TIME;0;;"
# Check response time
if [ $(echo "$RESPONSE_TIME_MS > $CRIT_TIME" | bc) -eq 1 ]; then
echo "CRITICAL - Response time $RESPONSE_TIME seconds -> $URL | response_time=${RESPONSE_TIME_MS}ms"
echo "CRITICAL - Response time $RESPONSE_TIME seconds -> $URL | $perfdata"
exit 2
elif [ $(echo "$RESPONSE_TIME_MS > $WARN_TIME" | bc) -eq 1 ]; then
echo "WARNING - response time $RESPONSE_TIME seconds -> $URL | response_time=${RESPONSE_TIME_MS}s"
echo "WARNING - response time $RESPONSE_TIME seconds -> $URL | $perfdata"
exit 1
fi
@ -408,5 +412,5 @@ if [ -n "$CRIT_STRING" ]; then
fi
# All checks passed
echo "OK - response time was $RESPONSE_TIME seconds${BODY_CONTAINS}-> $URL | response_time=${RESPONSE_TIME_MS}ms;$WARN_TIME;$CRIT_TIME;0;;"
echo "OK - response time was $RESPONSE_TIME seconds${BODY_CONTAINS}-> $URL | $perfdata"
exit 0