Website Monitoring - Catching Loop Redirects
Issue #648
new
Hello, will Monit provide an option to catch loop redirects during a website page monitoring?
The configuration should have a maximum number of page redirects, after which the request is considered failed.
Thank you very much!
Comments (2)
-
repo owner -
I used the following "program" to monitor this for a single address:
curl --max-redirs 10 -Lvs -o/dev/null example.com 2>&1 | grep '^< Location:' | wc -l
Details:
--max-redirs 10
: Follow up to 10 redirects-L
: Follow redirects-v
: Verbose output (no output is generated otherwise)-s
: silent: Do not print page bodies-o /dev/null
: drop any output2>&1
: redirect stderr to stdout to be available with grepgrep '^< Location:'
: Finds any line starting with< Location:
wc -l
: count lines
By using
check program RedirectsOnExampleCom with path "/usr/bin/bash -c 'exit $(curl --max-redirs 10 -Lvs -o/dev/null example.com 2>&1 | grep '^< Location:' | wc -l)'"
It will exit normally (exit code 0) if no redirect happened. It will walk up to 10 redirects, so one might to enhance like
check program RedirectsOnExampleCom with path "/usr/bin/bash -c 'exit $(curl --max-redirs 10 -Lvs -o/dev/null example.com 2>&1 | grep '^< Location:' | wc -l)'" if status > 2 then alert
So the alert is triggered if there are more than 2 redirects. That might make sence if you are redirected from http://example.com to http://www.example.com and finally to https://www.example.com.
- Log in to comment
Hello,
the http protocol test currently doesn't follow redirects, it could be interesting feature to add.
Best regards, The Monit team