1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

http_response: Add follow_redirect and undefined

- Add "--location" to curl with env.follow_redirect true
- When connections fails, set U (undefined)
This commit is contained in:
Sebastian L 2021-03-31 21:44:24 +02:00 committed by Lars Kruse
parent 2fd01d998d
commit 9f1d967cbc

View file

@ -11,14 +11,16 @@ http_response - Monitor HTTP response statistics
The following environment variables are used
sites - Sites to check
- separated by spaces
- can contain basic auth credentials
- defaults to "http://localhost/"
max_time - Timeout for each site check in seconds
- defaults to 5 seconds
short_label - Switch for shortening the label below the graph
- defaults to false
sites - Sites to check
- separated by spaces
- can contain basic auth credentials
- defaults to "http://localhost/"
max_time - Timeout for each site check in seconds
- defaults to 5 seconds
short_label - Switch for shortening the label below the graph
- defaults to false
follow_redirect - Follow http redirects
- defaults to false
=head2 CONFIGURATION EXAMPLE
@ -26,6 +28,7 @@ The following environment variables are used
env.sites http://example.com/ https://user:secret@example2.de
env.max_time 20
env.short_label true
env.follow_redirect true
=head1 PREREQUISITES
@ -116,6 +119,7 @@ fi
sites=${sites:-"http://localhost/"}
max_time=${max_time:-5}
short_label=${short_label:-"false"}
follow_redirect=${follow_redirect:-"false"}
if [[ "$1" == "config" ]]; then
echo 'multigraph http_response_code'
@ -168,15 +172,21 @@ for site in $sites; do
curl_auth_opt=(--config "$curl_config_file")
fi
curl_arg=""
if $follow_redirect; then
curl_arg="--location"
fi
siteid="$( clean_fieldname "$site_without_credentials" )"
statuscode=
loadtime=
start=$(date +%s.%N)
statuscode=$( curl "${curl_auth_opt[@]}" --write-out '%{http_code}' --max-time "$max_time" --silent --output /dev/null "$site_without_credentials" )
statuscode=$( curl "${curl_auth_opt[@]}" --write-out '%{http_code}' --max-time "$max_time" $curl_arg --silent --output /dev/null "$site_without_credentials" )
returncode=$?
loadtime=$( echo "$start" "$(date +%s.%N)" | awk '{ print($2 - $1); }' )
if [[ $returncode -ne 0 ]]; then
loadtime=0
loadtime="U"
statuscode="U"
fi
response_codes+=(["$siteid"]="$statuscode")
response_times+=(["$siteid"]="$loadtime")