diff options
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index c36d916a..51679975 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Nagios check_http plugin | 3 | * Monitoring check_http plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2013 Nagios Plugins Development Team | 6 | * Copyright (c) 1999-2013 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
@@ -35,7 +35,7 @@ | |||
35 | 35 | ||
36 | const char *progname = "check_http"; | 36 | const char *progname = "check_http"; |
37 | const char *copyright = "1999-2013"; | 37 | const char *copyright = "1999-2013"; |
38 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 38 | const char *email = "devel@monitoring-plugins.org"; |
39 | 39 | ||
40 | #include "common.h" | 40 | #include "common.h" |
41 | #include "netutils.h" | 41 | #include "netutils.h" |
@@ -57,7 +57,7 @@ enum { | |||
57 | 57 | ||
58 | #ifdef HAVE_SSL | 58 | #ifdef HAVE_SSL |
59 | int check_cert = FALSE; | 59 | int check_cert = FALSE; |
60 | int ssl_version; | 60 | int ssl_version = 0; |
61 | int days_till_exp_warn, days_till_exp_crit; | 61 | int days_till_exp_warn, days_till_exp_crit; |
62 | char *randbuff; | 62 | char *randbuff; |
63 | X509 *server_cert; | 63 | X509 *server_cert; |
@@ -157,7 +157,7 @@ main (int argc, char **argv) | |||
157 | /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ | 157 | /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ |
158 | server_url = strdup(HTTP_URL); | 158 | server_url = strdup(HTTP_URL); |
159 | server_url_length = strlen(server_url); | 159 | server_url_length = strlen(server_url); |
160 | xasprintf (&user_agent, "User-Agent: check_http/v%s (nagios-plugins %s)", | 160 | xasprintf (&user_agent, "User-Agent: check_http/v%s (monitoring-plugins %s)", |
161 | NP_VERSION, VERSION); | 161 | NP_VERSION, VERSION); |
162 | 162 | ||
163 | /* Parse extra opts if any */ | 163 | /* Parse extra opts if any */ |
@@ -257,7 +257,7 @@ process_arguments (int argc, char **argv) | |||
257 | } | 257 | } |
258 | 258 | ||
259 | while (1) { | 259 | while (1) { |
260 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:N:E", longopts, &option); | 260 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NE", longopts, &option); |
261 | if (c == -1 || c == EOF) | 261 | if (c == -1 || c == EOF) |
262 | break; | 262 | break; |
263 | 263 | ||
@@ -339,10 +339,10 @@ process_arguments (int argc, char **argv) | |||
339 | case 'S': /* use SSL */ | 339 | case 'S': /* use SSL */ |
340 | #ifdef HAVE_SSL | 340 | #ifdef HAVE_SSL |
341 | enable_ssl: | 341 | enable_ssl: |
342 | /* ssl_version initialized to 0 as a default. Only set if it's non-zero. This helps when we include multiple | ||
343 | parameters, like -S and -C combinations */ | ||
342 | use_ssl = TRUE; | 344 | use_ssl = TRUE; |
343 | if (optarg == NULL || c != 'S') | 345 | if (c=='S' && optarg != NULL) { |
344 | ssl_version = 0; | ||
345 | else { | ||
346 | ssl_version = atoi(optarg); | 346 | ssl_version = atoi(optarg); |
347 | if (ssl_version < 1 || ssl_version > 3) | 347 | if (ssl_version < 1 || ssl_version > 3) |
348 | usage4 (_("Invalid option - Valid values for SSL Version are 1 (TLSv1), 2 (SSLv2) or 3 (SSLv3)")); | 348 | usage4 (_("Invalid option - Valid values for SSL Version are 1 (TLSv1), 2 (SSLv2) or 3 (SSLv3)")); |
@@ -1243,6 +1243,7 @@ redir (char *pos, char *status_line) | |||
1243 | if (addr == NULL) | 1243 | if (addr == NULL) |
1244 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n")); | 1244 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n")); |
1245 | 1245 | ||
1246 | memset(addr, 0, MAX_IPV4_HOSTLENGTH); | ||
1246 | url = malloc (strcspn (pos, "\r\n")); | 1247 | url = malloc (strcspn (pos, "\r\n")); |
1247 | if (url == NULL) | 1248 | if (url == NULL) |
1248 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); | 1249 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); |
@@ -1333,8 +1334,8 @@ redir (char *pos, char *status_line) | |||
1333 | max_depth, type, addr, i, url, (display_html ? "</A>" : "")); | 1334 | max_depth, type, addr, i, url, (display_html ? "</A>" : "")); |
1334 | 1335 | ||
1335 | if (server_port==i && | 1336 | if (server_port==i && |
1336 | !strcmp(server_address, addr) && | 1337 | !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && |
1337 | (host_name && !strcmp(host_name, addr)) && | 1338 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && |
1338 | !strcmp(server_url, url)) | 1339 | !strcmp(server_url, url)) |
1339 | die (STATE_WARNING, | 1340 | die (STATE_WARNING, |
1340 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), | 1341 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), |
@@ -1343,11 +1344,11 @@ redir (char *pos, char *status_line) | |||
1343 | strcpy (server_type, type); | 1344 | strcpy (server_type, type); |
1344 | 1345 | ||
1345 | free (host_name); | 1346 | free (host_name); |
1346 | host_name = strdup (addr); | 1347 | host_name = strndup (addr, MAX_IPV4_HOSTLENGTH); |
1347 | 1348 | ||
1348 | if (!(followsticky & STICKY_HOST)) { | 1349 | if (!(followsticky & STICKY_HOST)) { |
1349 | free (server_address); | 1350 | free (server_address); |
1350 | server_address = strdup (addr); | 1351 | server_address = strndup (addr, MAX_IPV4_HOSTLENGTH); |
1351 | } | 1352 | } |
1352 | if (!(followsticky & STICKY_PORT)) { | 1353 | if (!(followsticky & STICKY_PORT)) { |
1353 | server_port = i; | 1354 | server_port = i; |
@@ -1366,6 +1367,7 @@ redir (char *pos, char *status_line) | |||
1366 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, | 1367 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, |
1367 | host_name ? host_name : server_address, server_port, server_url); | 1368 | host_name ? host_name : server_address, server_port, server_url); |
1368 | 1369 | ||
1370 | free(addr); | ||
1369 | check_http (); | 1371 | check_http (); |
1370 | } | 1372 | } |
1371 | 1373 | ||
@@ -1534,7 +1536,7 @@ print_help (void) | |||
1534 | 1536 | ||
1535 | printf (UT_WARN_CRIT); | 1537 | printf (UT_WARN_CRIT); |
1536 | 1538 | ||
1537 | printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1539 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
1538 | 1540 | ||
1539 | printf (UT_VERBOSE); | 1541 | printf (UT_VERBOSE); |
1540 | 1542 | ||