2

I am looking to use monit to keep an eye on my site. I want it to treat it the site like an external user so am testing the url but it doesn't seem to follow redirects. The content check is being performed on the html of the redirect.

#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"

Finding out how to get the url check to follow 30X would be great.

henry.oswald
  • 127
  • 1
  • 8
  • it kind of makes sense that it doesn't follow the redirect because, I don't see the monit http tool as a web client, its just there to search for strings. Like you wouldn't expect it to follow a javascript redirect, or a tag Refresh either. – Tom Mar 20 '12 at 23:07

1 Answers1

1

Even though I dont see an option in the monit man page to make it follow redirects, I think that by testing the elements of the redirect explicitly. By first testing the redirect headers, and then the content of the target page, that you achieve the same sort of thing.

(Here is the response including a redirect from a request to 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

I would use something like the following;

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

So breaking that down... These 2 lines, check that the HTTP:// page redirects correctly, and that it provides the correct target for the redirection.

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  

Then test that you were redirected to the right place, and for some content....

then the following lines, effective follow the redirect explicitly and test the content of the HTTPS page at https://www.sharelatex.com/blog/posts/future.html

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

I guess the first commands are going to make a bunch (2x) of requests per page, so it might be worth combining them somehow....

Tom
  • 10,886
  • 5
  • 39
  • 62