X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_http.c;h=5a859f98774bafa8513cbe64d91bb08fdfd277d2;hb=e7cdcfee2a6025b41f67ead5020df3965ef05a98;hp=620e1578097d1761d44e07937d1956d3809c0504;hpb=d00a53dd1e4b818f36dd8ef0ee9245445b0ee8e9;p=nagiosplug.git diff --git a/plugins/check_http.c b/plugins/check_http.c index 620e157..5a859f9 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -44,6 +44,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include #define INPUT_DELIMITER ";" +#define STICKY_NONE 0 +#define STICKY_HOST 1 +#define STICKY_PORT 2 #define HTTP_EXPECT "HTTP/1." enum { @@ -106,7 +109,7 @@ int display_html = FALSE; char **http_opt_headers; int http_opt_headers_count = 0; int onredirect = STATE_OK; -int followsticky = 0; +int followsticky = STICKY_NONE; int use_ssl = FALSE; int verbose = FALSE; int sd; @@ -300,10 +303,12 @@ process_arguments (int argc, char **argv) server_port = HTTPS_PORT; break; case 'f': /* onredirect */ + if (!strcmp (optarg, "stickyport")) + onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT; if (!strcmp (optarg, "sticky")) - onredirect = STATE_DEPENDENT, followsticky = 1; + onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST; if (!strcmp (optarg, "follow")) - onredirect = STATE_DEPENDENT, followsticky = 0; + onredirect = STATE_DEPENDENT, followsticky = STICKY_NONE; if (!strcmp (optarg, "unknown")) onredirect = STATE_UNKNOWN; if (!strcmp (optarg, "ok")) @@ -794,7 +799,7 @@ check_http (void) } #endif /* HAVE_SSL */ - asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent); + asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); /* tell HTTP/1.1 servers not to keep the connection alive */ asprintf (&buf, "%sConnection: close\r\n", buf); @@ -894,9 +899,6 @@ check_http (void) #endif if (sd) close(sd); - /* reset the alarm */ - alarm (0); - /* Save check time */ microsec = deltime (tv); elapsed_time = (double)microsec / 1.0e6; @@ -975,7 +977,7 @@ check_http (void) } /* server errors result in a critical state */ else if (http_status >= 500) { - asprintf (&msg, _("%s - "), msg, status_line); + asprintf (&msg, _("%s - "), status_line); result = STATE_CRITICAL; } /* client errors result in a warning state */ @@ -999,6 +1001,9 @@ check_http (void) } /* end else (server_expect_yn) */ + /* reset the alarm - must be called *after* redir or we'll never die on redirects! */ + alarm (0); + if (maximum_age >= 0) { result = max_state_alt(check_document_dates(header, &msg), result); } @@ -1059,8 +1064,8 @@ check_http (void) /* check elapsed time */ asprintf (&msg, - _("%s - %.3f second response time %s|%s %s"), - msg, elapsed_time, + _("%s - %d bytes in %.3f second response time %s|%s %s"), + msg, page_len, elapsed_time, (display_html ? "" : ""), perfd_time (elapsed_time), perfd_size (page_len)); @@ -1103,7 +1108,7 @@ redir (char *pos, char *status_line) url = malloc (strcspn (pos, "\r\n")); if (url == NULL) - die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate url\n")); + die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); while (pos) { sscanf (pos, "%1[Ll]%*1[Oo]%*1[Cc]%*1[Aa]%*1[Tt]%*1[Ii]%*1[Oo]%*1[Nn]:%n", xx, &i); @@ -1134,7 +1139,7 @@ redir (char *pos, char *status_line) url = realloc (url, strcspn (pos, "\r\n") + 1); if (url == NULL) - die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n")); + die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ if (sscanf (pos, HD1, type, addr, &i, url) == 4) { @@ -1203,15 +1208,18 @@ redir (char *pos, char *status_line) free (host_name); host_name = strdup (addr); - if (followsticky == 0) { + if (!(followsticky & STICKY_HOST)) { free (server_address); server_address = strdup (addr); } + if (!(followsticky & STICKY_PORT)) { + server_port = i; + } free (server_url); server_url = url; - if ((server_port = i) > MAX_PORT) + if (server_port > MAX_PORT) die (STATE_UNKNOWN, _("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"), MAX_PORT, server_type, server_address, server_port, server_url, @@ -1301,7 +1309,7 @@ print_help (void) printf (" %s\n", _("Connect via SSL. Port defaults to 443")); printf (" %s\n", "-C, --certificate=INTEGER"); printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); - printf (" %s\n", _("(when this option is used the url is not checked.)\n")); + printf (" %s\n", _("(when this option is used the URL is not checked.)\n")); #endif printf (" %s\n", "-e, --expect=STRING"); @@ -1343,9 +1351,9 @@ print_help (void) printf (" %s\n", _(" Any other tags to be sent in http header. Use multiple times for additional headers")); printf (" %s\n", "-L, --link"); printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); - printf (" %s\n", "-f, --onredirect="); + printf (" %s\n", "-f, --onredirect="); printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the")); - printf (" %s\n", _("specified IP address")); + printf (" %s\n", _("specified IP address. stickyport also ensure post stays the same.")); printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)"));