diff --git a/plugins/check_http.c b/plugins/check_http.c
index 2f2460c637b53c0604ab6d31c23de961376f4d93..79f6adf39962767c4d14a19d6d587c988afb6d8f 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
#include <ctype.h>
#define INPUT_DELIMITER ";"
+#define STICKY_NONE 0
+#define STICKY_HOST 1
+#define STICKY_PORT 2
#define HTTP_EXPECT "HTTP/1."
enum {
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;
server_port = HTTPS_PORT;
break;
case 'f': /* onredirect */
- if (!strcmp (optarg, "sticky"))
- onredirect = STATE_DEPENDENT, followsticky = 1;
- if (!strcmp (optarg, "follow"))
- onredirect = STATE_DEPENDENT, followsticky = 0;
- if (!strcmp (optarg, "unknown"))
+ if (!strcmp (optarg, "stickyport"))
+ onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT;
+ else if (!strcmp (optarg, "sticky"))
+ onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST;
+ else if (!strcmp (optarg, "follow"))
+ onredirect = STATE_DEPENDENT, followsticky = STICKY_NONE;
+ else if (!strcmp (optarg, "unknown"))
onredirect = STATE_UNKNOWN;
- if (!strcmp (optarg, "ok"))
+ else if (!strcmp (optarg, "ok"))
onredirect = STATE_OK;
- if (!strcmp (optarg, "warning"))
+ else if (!strcmp (optarg, "warning"))
onredirect = STATE_WARNING;
- if (!strcmp (optarg, "critical"))
+ else if (!strcmp (optarg, "critical"))
onredirect = STATE_CRITICAL;
+ else usage2 (_("Invalid onredirect option"), optarg);
if (verbose)
printf(_("option f:%d \n"), onredirect);
break;
die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
#ifdef HAVE_SSL
if (use_ssl == TRUE) {
- np_net_ssl_init(sd);
+ np_net_ssl_init_with_hostname(sd, host_name);
if (check_cert == TRUE) {
result = np_net_ssl_check_cert(days_till_exp);
np_net_ssl_cleanup();
#endif
if (sd) close(sd);
- /* reset the alarm */
- alarm (0);
-
/* Save check time */
microsec = deltime (tv);
elapsed_time = (double)microsec / 1.0e6;
} /* 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);
}
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,
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=<ok|warning|critical|follow|sticky>");
+ printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>");
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)"));
printf (_("Usage:"));
printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n");
- printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n");
- printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n");
- printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]\n");
- printf (" [-k string] [-S] [-C <age>] [-T <content-type>] [-j method]\n");
+ printf (" [-a auth] [-f <ok | warn | critcal | follow | sticky | stickyport>]\n");
+ printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
+ printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
+ printf (" [-A string] [-k string] [-S] [-C <age>] [-T <content-type>] [-j method]\n");
}