summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2022-01-29 11:11:36 +0100
committerSven Nierlein <sven@nierlein.org>2022-01-29 12:15:12 +0100
commit737412f7391ae430a51e8f2c2a3b1ab2d35a6394 (patch)
tree7cf7996e8a2fe227edab7fb8c6279fdf6d42424d /plugins
parente2397167c7e5c7a02b68de45de946f63706e7d12 (diff)
downloadmonitoring-plugins-737412f7391ae430a51e8f2c2a3b1ab2d35a6394.tar.gz
check_http and check_curl: added --max-redirs=N option (feature #1684)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_curl.c16
-rw-r--r--plugins/check_http.c20
2 files changed, 30 insertions, 6 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 14cc8463..32d919fe 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -66,13 +66,13 @@ const char *email = "devel@monitoring-plugins.org";
66#define DEFAULT_BUFFER_SIZE 2048 66#define DEFAULT_BUFFER_SIZE 2048
67#define DEFAULT_SERVER_URL "/" 67#define DEFAULT_SERVER_URL "/"
68#define HTTP_EXPECT "HTTP/" 68#define HTTP_EXPECT "HTTP/"
69#define DEFAULT_MAX_REDIRS 15
70#define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN 69#define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN
71enum { 70enum {
72 MAX_IPV4_HOSTLENGTH = 255, 71 MAX_IPV4_HOSTLENGTH = 255,
73 HTTP_PORT = 80, 72 HTTP_PORT = 80,
74 HTTPS_PORT = 443, 73 HTTPS_PORT = 443,
75 MAX_PORT = 65535 74 MAX_PORT = 65535,
75 DEFAULT_MAX_REDIRS = 15
76}; 76};
77 77
78enum { 78enum {
@@ -1210,6 +1210,7 @@ process_arguments (int argc, char **argv)
1210 enum { 1210 enum {
1211 INVERT_REGEX = CHAR_MAX + 1, 1211 INVERT_REGEX = CHAR_MAX + 1,
1212 SNI_OPTION, 1212 SNI_OPTION,
1213 MAX_REDIRS_OPTION,
1213 CA_CERT_OPTION, 1214 CA_CERT_OPTION,
1214 HTTP_VERSION_OPTION, 1215 HTTP_VERSION_OPTION,
1215 AUTOMATIC_DECOMPRESSION 1216 AUTOMATIC_DECOMPRESSION
@@ -1254,6 +1255,7 @@ process_arguments (int argc, char **argv)
1254 {"use-ipv6", no_argument, 0, '6'}, 1255 {"use-ipv6", no_argument, 0, '6'},
1255 {"extended-perfdata", no_argument, 0, 'E'}, 1256 {"extended-perfdata", no_argument, 0, 'E'},
1256 {"show-body", no_argument, 0, 'B'}, 1257 {"show-body", no_argument, 0, 'B'},
1258 {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION},
1257 {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, 1259 {"http-version", required_argument, 0, HTTP_VERSION_OPTION},
1258 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, 1260 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
1259 {0, 0, 0, 0} 1261 {0, 0, 0, 0}
@@ -1512,6 +1514,13 @@ process_arguments (int argc, char **argv)
1512 use_sni = TRUE; 1514 use_sni = TRUE;
1513 break; 1515 break;
1514#endif /* LIBCURL_FEATURE_SSL */ 1516#endif /* LIBCURL_FEATURE_SSL */
1517 case MAX_REDIRS_OPTION:
1518 if (!is_intnonneg (optarg))
1519 usage2 (_("Invalid max_redirs count"), optarg);
1520 else {
1521 max_depth = atoi (optarg);
1522 }
1523 break;
1515 case 'f': /* onredirect */ 1524 case 'f': /* onredirect */
1516 if (!strcmp (optarg, "ok")) 1525 if (!strcmp (optarg, "ok"))
1517 onredirect = STATE_OK; 1526 onredirect = STATE_OK;
@@ -1854,6 +1863,9 @@ print_help (void)
1854 printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same.")); 1863 printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same."));
1855 printf (" %s\n", _("follow uses the old redirection algorithm of check_http.")); 1864 printf (" %s\n", _("follow uses the old redirection algorithm of check_http."));
1856 printf (" %s\n", _("curl uses CURL_FOLLOWLOCATION built into libcurl.")); 1865 printf (" %s\n", _("curl uses CURL_FOLLOWLOCATION built into libcurl."));
1866 printf (" %s\n", "--max-redirs=INTEGER");
1867 printf (" %s", _("Maximal number of redirects (default: "));
1868 printf ("%d)\n", DEFAULT_MAX_REDIRS);
1857 printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); 1869 printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>");
1858 printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); 1870 printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)"));
1859 printf ("\n"); 1871 printf ("\n");
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 34fb4f01..df2a79c2 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -52,7 +52,8 @@ enum {
52 MAX_IPV4_HOSTLENGTH = 255, 52 MAX_IPV4_HOSTLENGTH = 255,
53 HTTP_PORT = 80, 53 HTTP_PORT = 80,
54 HTTPS_PORT = 443, 54 HTTPS_PORT = 443,
55 MAX_PORT = 65535 55 MAX_PORT = 65535,
56 DEFAULT_MAX_REDIRS = 15
56}; 57};
57 58
58#ifdef HAVE_SSL 59#ifdef HAVE_SSL
@@ -125,7 +126,7 @@ int sd;
125int min_page_len = 0; 126int min_page_len = 0;
126int max_page_len = 0; 127int max_page_len = 0;
127int redir_depth = 0; 128int redir_depth = 0;
128int max_depth = 15; 129int max_depth = DEFAULT_MAX_REDIRS;
129char *http_method; 130char *http_method;
130char *http_method_proxy; 131char *http_method_proxy;
131char *http_post_data; 132char *http_post_data;
@@ -203,7 +204,8 @@ process_arguments (int argc, char **argv)
203 204
204 enum { 205 enum {
205 INVERT_REGEX = CHAR_MAX + 1, 206 INVERT_REGEX = CHAR_MAX + 1,
206 SNI_OPTION 207 SNI_OPTION,
208 MAX_REDIRS_OPTION
207 }; 209 };
208 210
209 int option = 0; 211 int option = 0;
@@ -242,6 +244,7 @@ process_arguments (int argc, char **argv)
242 {"use-ipv6", no_argument, 0, '6'}, 244 {"use-ipv6", no_argument, 0, '6'},
243 {"extended-perfdata", no_argument, 0, 'E'}, 245 {"extended-perfdata", no_argument, 0, 'E'},
244 {"show-body", no_argument, 0, 'B'}, 246 {"show-body", no_argument, 0, 'B'},
247 {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION},
245 {0, 0, 0, 0} 248 {0, 0, 0, 0}
246 }; 249 };
247 250
@@ -373,6 +376,13 @@ process_arguments (int argc, char **argv)
373 case SNI_OPTION: 376 case SNI_OPTION:
374 use_sni = TRUE; 377 use_sni = TRUE;
375 break; 378 break;
379 case MAX_REDIRS_OPTION:
380 if (!is_intnonneg (optarg))
381 usage2 (_("Invalid max_redirs count"), optarg);
382 else {
383 max_depth = atoi (optarg);
384 }
385 break;
376 case 'f': /* onredirect */ 386 case 'f': /* onredirect */
377 if (!strcmp (optarg, "stickyport")) 387 if (!strcmp (optarg, "stickyport"))
378 onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT; 388 onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT;
@@ -1657,9 +1667,11 @@ print_help (void)
1657 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); 1667 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>");
1658 printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the")); 1668 printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the"));
1659 printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same.")); 1669 printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same."));
1670 printf (" %s\n", "--max-redirs=INTEGER");
1671 printf (" %s", _("Maximal number of redirects (default: "));
1672 printf ("%d)\n", DEFAULT_MAX_REDIRS);
1660 printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); 1673 printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>");
1661 printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); 1674 printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)"));
1662
1663 printf (UT_WARN_CRIT); 1675 printf (UT_WARN_CRIT);
1664 1676
1665 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 1677 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);