<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Helo!<o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">We recently ran into problems with check_http.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">One of our checked webapps redirects to another website and that redirected page sends back a stupid, but correct result code of 494.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The command we run looks ike this:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> check_http -p 8080 -c 30 -I ServerIP -u "URL" -f follow -e '302,494'<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">However, the check always returns OK, even if the redirected page returns a different error code.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">It seems check_http is not following redirects when “-e” is used.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This is because of that “if” statement in line 996 . This completely disables the checking for a possible redirection.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 994 /* Bypass normal status line check if server_expect was set by user and not default */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 995 /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 996 if ( server_expect_yn ) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 997 asprintf (&msg,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 998 _("Status line output matched \"%s\" - "), server_expect);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 999 if (verbose)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1000 printf ("%s\n",msg);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1001 }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1002 else {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> ....<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1028 /* check redirected page if specified */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1029 else if (http_status >= 300) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1030<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1031 if (onredirect == STATE_DEPENDENT)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1032 redir (header, status_line);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1033 else<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1034 result = max_state_alt(onredirect, result);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1035 asprintf (&msg, _("%s - "), status_line);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1036 } /* end if (http_status >= 300) */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1037 else {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">i could “fix” this behaviour by simply disabling the “if” in line 996 by adding a “ && 0” to the if:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 996 if ( server_expect_yn && 0 ) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">That works for the moment, but now check_http finishes with a WARNING state because the status-code is greater than 400.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">To fix this, too, i had to change the stauts-code logic to include a check for the expected status code. And since this resulted into a segfault, i had to extend the “if” even further.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The result is this:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1006 /* server errors result in a critical state */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1007 else if (http_status >= 500 && http_status < 600 && ! expected_statuscode (status_line, server_expect) ) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1008 asprintf (&msg, _("%s - "), status_line);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1009 result = STATE_CRITICAL;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1010 }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1011 /* client errors result in a warning state */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1012 else if (http_status >= 400 && http_status < 500 && ! expected_statuscode (status_line, server_expect) ) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1013 asprintf (&msg, _("%s - "), status_line);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1014 result = max_state_alt(STATE_WARNING, result);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1015 }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1016 /* check redirected page if specified */<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 1017 else if (http_status >= 300 && http_status < 400 ) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This seems to work now.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I am sure that could be done in a more elegant way and i am willing to invest more time in coding a better fix but first of all i would like to check with you guys if such a change in the behaviour of check_http would
be acceptable.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Greetings<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Andreas Lamprecht<o:p></o:p></span></p>
</div>
</body>
</html>