Monit 检查 URL 跟随重定向

Monit 检查 URL 跟随重定向

我希望使用 monit 来监视我的网站。我希望它像对待外部用户一样对待网站,所以我正在测试 URL,但它似乎没有遵循重定向。内容检查正在重定向的 html 上执行。

#request works:
if failed url http://www.sharelatex.com/blog/posts/future.html content == "301"

#request fails
if failed url http://www.sharelatex.com/blog/posts/future.html content == "actual content"

了解如何让 URL 检查遵循 30X 就太好了。

答案1

尽管我没有看到monit 手册页为了使其遵循重定向,我认为可以通过明确测试重定向的元素来实现。通过首先测试重定向标头,然后测试目标页面的内容,您可以实现相同的目的。

(这是包含从请求到 sharelatex 的重定向的响应)

HTTP/1.1 301 Moved Permanently       <---- response code here
Server: nginx/0.7.65
Date: Tue, 20 Mar 2012 22:04:48 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://www.sharelatex.com/blog/posts/future.html   <---- target location here

我会使用类似下面的东西;

check host www.sharelatex.com with address www.sharelatex.com
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "301 Moved Permanently" 
    then alert
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "Location: https://www.sharelatex.com/blog/posts/future.html"
    then alert
IF FAILED URL https://www.sharelatex.com/blog/posts/future.html content == "ShareLaTeX"         
    then alert

所以分解一下...这两行,检查 HTTP:// 页面是否正确重定向,以及是否为重定向提供了正确的目标。

check host www.sharelatex.com with address www.sharelatex.com
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "301 Moved Permanently" then alert
IF FAILED URL http://www.sharelatex.com/blog/posts/future.html content == "Location: https://www.sharelatex.com/blog/posts/future.html" then alert  

然后测试您是否被重定向到正确的位置以及某些内容......

然后执行以下几行,有效地明确遵循重定向并测试 HTTPS 页面的内容https://www.sharelatex.com/blog/posts/future.html

 IF FAILED URL https://www.sharelatex.com/blog/posts/future.html content == "ShareLaTeX" then alert   

我猜测第一个命令将会对每个页面产生一堆(2x)请求,因此可能值得以某种方式将它们组合起来......

相关内容