mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51: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:
parent
2fd01d998d
commit
9f1d967cbc
1 changed files with 20 additions and 10 deletions
|
@ -11,14 +11,16 @@ http_response - Monitor HTTP response statistics
|
||||||
|
|
||||||
The following environment variables are used
|
The following environment variables are used
|
||||||
|
|
||||||
sites - Sites to check
|
sites - Sites to check
|
||||||
- separated by spaces
|
- separated by spaces
|
||||||
- can contain basic auth credentials
|
- can contain basic auth credentials
|
||||||
- defaults to "http://localhost/"
|
- defaults to "http://localhost/"
|
||||||
max_time - Timeout for each site check in seconds
|
max_time - Timeout for each site check in seconds
|
||||||
- defaults to 5 seconds
|
- defaults to 5 seconds
|
||||||
short_label - Switch for shortening the label below the graph
|
short_label - Switch for shortening the label below the graph
|
||||||
- defaults to false
|
- defaults to false
|
||||||
|
follow_redirect - Follow http redirects
|
||||||
|
- defaults to false
|
||||||
|
|
||||||
=head2 CONFIGURATION EXAMPLE
|
=head2 CONFIGURATION EXAMPLE
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ The following environment variables are used
|
||||||
env.sites http://example.com/ https://user:secret@example2.de
|
env.sites http://example.com/ https://user:secret@example2.de
|
||||||
env.max_time 20
|
env.max_time 20
|
||||||
env.short_label true
|
env.short_label true
|
||||||
|
env.follow_redirect true
|
||||||
|
|
||||||
=head1 PREREQUISITES
|
=head1 PREREQUISITES
|
||||||
|
|
||||||
|
@ -116,6 +119,7 @@ fi
|
||||||
sites=${sites:-"http://localhost/"}
|
sites=${sites:-"http://localhost/"}
|
||||||
max_time=${max_time:-5}
|
max_time=${max_time:-5}
|
||||||
short_label=${short_label:-"false"}
|
short_label=${short_label:-"false"}
|
||||||
|
follow_redirect=${follow_redirect:-"false"}
|
||||||
|
|
||||||
if [[ "$1" == "config" ]]; then
|
if [[ "$1" == "config" ]]; then
|
||||||
echo 'multigraph http_response_code'
|
echo 'multigraph http_response_code'
|
||||||
|
@ -168,15 +172,21 @@ for site in $sites; do
|
||||||
curl_auth_opt=(--config "$curl_config_file")
|
curl_auth_opt=(--config "$curl_config_file")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
curl_arg=""
|
||||||
|
if $follow_redirect; then
|
||||||
|
curl_arg="--location"
|
||||||
|
fi
|
||||||
|
|
||||||
siteid="$( clean_fieldname "$site_without_credentials" )"
|
siteid="$( clean_fieldname "$site_without_credentials" )"
|
||||||
statuscode=
|
statuscode=
|
||||||
loadtime=
|
loadtime=
|
||||||
start=$(date +%s.%N)
|
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=$?
|
returncode=$?
|
||||||
loadtime=$( echo "$start" "$(date +%s.%N)" | awk '{ print($2 - $1); }' )
|
loadtime=$( echo "$start" "$(date +%s.%N)" | awk '{ print($2 - $1); }' )
|
||||||
if [[ $returncode -ne 0 ]]; then
|
if [[ $returncode -ne 0 ]]; then
|
||||||
loadtime=0
|
loadtime="U"
|
||||||
|
statuscode="U"
|
||||||
fi
|
fi
|
||||||
response_codes+=(["$siteid"]="$statuscode")
|
response_codes+=(["$siteid"]="$statuscode")
|
||||||
response_times+=(["$siteid"]="$loadtime")
|
response_times+=(["$siteid"]="$loadtime")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue