check_http, redirects and expect
"Lamprecht, Andreas" <[email protected]>
| Newsgroups | gmane.network.nagios.plugins.devel |
|---|---|
| Message-ID | <CFFA578ACC0F2F4B9B2BBADD376E0863139F0774@DEERLM99EZ3MSX.ww931.my-it-solutions.net> |
Helo!
We recently ran into problems with check_http.
One of our checked webapps redirects to another website and that redirected page sends back a stupid, but correct result code of 494.
The command we run looks ike this:
check_http -p 8080 -c 30 -I ServerIP -u "URL" -f follow -e '302,494'
However, the check always returns OK, even if the redirected page returns a different error code.
It seems check_http is not following redirects when "-e" is used.
This is because of that "if" statement in line 996 . This completely disables the checking for a possible redirection.
994 /* Bypass normal status line check if server_expect was set by user and not default */
995 /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string */
996 if ( server_expect_yn ) {
997 asprintf (&msg,
998 _("Status line output matched \"%s\" - "), server_expect);
999 if (verbose)
1000 printf ("%s\n",msg);
1001 }
1002 else {
....
1028 /* check redirected page if specified */
1029 else if (http_status >= 300) {
1030
1031 if (onredirect == STATE_DEPENDENT)
1032 redir (header, status_line);
1033 else
1034 result = max_state_alt(onredirect, result);
1035 asprintf (&msg, _("%s - "), status_line);
1036 } /* end if (http_status >= 300) */
1037 else {
i could "fix" this behaviour by simply disabling the "if" in line 996 by adding a " && 0" to the if:
996 if ( server_expect_yn && 0 ) {
That works for the moment, but now check_http finishes with a WARNING state because the status-code is greater than 400.
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.
The result is this:
1006 /* server errors result in a critical state */
1007 else if (http_status >= 500 && http_status < 600 && ! expected_statuscode (status_line, server_expect) ) {
1008 asprintf (&msg, _("%s - "), status_line);
1009 result = STATE_CRITICAL;
1010 }
1011 /* client errors result in a warning state */
1012 else if (http_status >= 400 && http_status < 500 && ! expected_statuscode (status_line, server_expect) ) {
1013 asprintf (&msg, _("%s - "), status_line);
1014 result = max_state_alt(STATE_WARNING, result);
1015 }
1016 /* check redirected page if specified */
1017 else if (http_status >= 300 && http_status < 400 ) {
This seems to work now.
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.
Greetings
Andreas Lamprecht
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________________
Nagios Plugin Development Mailing List Nagiosplug-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
::: Please include plugins version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null