summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2022-11-13 14:47:29 +0100
committerSven Nierlein <sven@nierlein.org>2023-01-07 18:34:46 +0100
commit698eed58f80b9706acc0d9da166eb8eab5cd081d (patch)
tree06717c1134632c05eaf32d11dac865fa75d9b9b0
parent9ba8f5ed66004c102bb626e47bb36dc9d0388632 (diff)
downloadmonitoring-plugins-698eed58f80b9706acc0d9da166eb8eab5cd081d.tar.gz
Use real booleans instead of ints
-rw-r--r--plugins/check_http.c111
1 files changed, 55 insertions, 56 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 1835a2d0..b1effd8d 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -57,8 +57,8 @@ enum {
57}; 57};
58 58
59#ifdef HAVE_SSL 59#ifdef HAVE_SSL
60int check_cert = FALSE; 60bool check_cert = false;
61int continue_after_check_cert = FALSE; 61bool continue_after_check_cert = false;
62int ssl_version = 0; 62int ssl_version = 0;
63int days_till_exp_warn, days_till_exp_crit; 63int days_till_exp_warn, days_till_exp_crit;
64char *randbuff; 64char *randbuff;
@@ -69,7 +69,7 @@ X509 *server_cert;
69# define my_recv(buf, len) read(sd, buf, len) 69# define my_recv(buf, len) read(sd, buf, len)
70# define my_send(buf, len) send(sd, buf, len, 0) 70# define my_send(buf, len) send(sd, buf, len, 0)
71#endif /* HAVE_SSL */ 71#endif /* HAVE_SSL */
72int no_body = FALSE; 72bool no_body = false;
73int maximum_age = -1; 73int maximum_age = -1;
74 74
75enum { 75enum {
@@ -91,7 +91,7 @@ struct timeval tv_temp;
91#define HTTP_URL "/" 91#define HTTP_URL "/"
92#define CRLF "\r\n" 92#define CRLF "\r\n"
93 93
94int specify_port = FALSE; 94bool specify_port = false;
95int server_port = HTTP_PORT; 95int server_port = HTTP_PORT;
96int virtual_port = 0; 96int virtual_port = 0;
97char server_port_text[6] = ""; 97char server_port_text[6] = "";
@@ -113,16 +113,16 @@ char *critical_thresholds = NULL;
113thresholds *thlds; 113thresholds *thlds;
114char user_auth[MAX_INPUT_BUFFER] = ""; 114char user_auth[MAX_INPUT_BUFFER] = "";
115char proxy_auth[MAX_INPUT_BUFFER] = ""; 115char proxy_auth[MAX_INPUT_BUFFER] = "";
116int display_html = FALSE; 116bool display_html = false;
117char **http_opt_headers; 117char **http_opt_headers;
118int http_opt_headers_count = 0; 118int http_opt_headers_count = 0;
119int onredirect = STATE_OK; 119int onredirect = STATE_OK;
120int followsticky = STICKY_NONE; 120int followsticky = STICKY_NONE;
121int use_ssl = FALSE; 121bool use_ssl = false;
122int use_sni = FALSE; 122bool use_sni = false;
123int verbose = FALSE; 123bool verbose = false;
124int show_extended_perfdata = FALSE; 124bool show_extended_perfdata = false;
125int show_body = FALSE; 125bool show_body = false;
126int sd; 126int sd;
127int min_page_len = 0; 127int min_page_len = 0;
128int max_page_len = 0; 128int max_page_len = 0;
@@ -136,10 +136,10 @@ char buffer[MAX_INPUT_BUFFER];
136char *client_cert = NULL; 136char *client_cert = NULL;
137char *client_privkey = NULL; 137char *client_privkey = NULL;
138 138
139int process_arguments (int, char **); 139bool process_arguments (int, char **);
140int check_http (void); 140int check_http (void);
141void redir (char *pos, char *status_line); 141void redir (char *pos, char *status_line);
142int server_type_check(const char *type); 142bool server_type_check(const char *type);
143int server_port_check(int ssl_flag); 143int server_port_check(int ssl_flag);
144char *perfd_time (double microsec); 144char *perfd_time (double microsec);
145char *perfd_time_connect (double microsec); 145char *perfd_time_connect (double microsec);
@@ -169,10 +169,10 @@ main (int argc, char **argv)
169 /* Parse extra opts if any */ 169 /* Parse extra opts if any */
170 argv=np_extra_opts (&argc, argv, progname); 170 argv=np_extra_opts (&argc, argv, progname);
171 171
172 if (process_arguments (argc, argv) == ERROR) 172 if (process_arguments (argc, argv) == false)
173 usage4 (_("Could not parse arguments")); 173 usage4 (_("Could not parse arguments"));
174 174
175 if (display_html == TRUE) 175 if (display_html == true)
176 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", 176 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
177 use_ssl ? "https" : "http", host_name ? host_name : server_address, 177 use_ssl ? "https" : "http", host_name ? host_name : server_address,
178 server_port, server_url); 178 server_port, server_url);
@@ -196,8 +196,7 @@ test_file (char *path)
196} 196}
197 197
198/* process command-line arguments */ 198/* process command-line arguments */
199int 199bool process_arguments (int argc, char **argv)
200process_arguments (int argc, char **argv)
201{ 200{
202 int c = 1; 201 int c = 1;
203 char *p; 202 char *p;
@@ -252,7 +251,7 @@ process_arguments (int argc, char **argv)
252 }; 251 };
253 252
254 if (argc < 2) 253 if (argc < 2)
255 return ERROR; 254 return false;
256 255
257 for (c = 1; c < argc; c++) { 256 for (c = 1; c < argc; c++) {
258 if (strcmp ("-to", argv[c]) == 0) 257 if (strcmp ("-to", argv[c]) == 0)
@@ -308,10 +307,10 @@ process_arguments (int argc, char **argv)
308 /* xasprintf (&http_opt_headers, "%s", optarg); */ 307 /* xasprintf (&http_opt_headers, "%s", optarg); */
309 break; 308 break;
310 case 'L': /* show html link */ 309 case 'L': /* show html link */
311 display_html = TRUE; 310 display_html = true;
312 break; 311 break;
313 case 'n': /* do not show html link */ 312 case 'n': /* do not show html link */
314 display_html = FALSE; 313 display_html = false;
315 break; 314 break;
316 case 'C': /* Check SSL cert validity */ 315 case 'C': /* Check SSL cert validity */
317#ifdef HAVE_SSL 316#ifdef HAVE_SSL
@@ -332,12 +331,12 @@ process_arguments (int argc, char **argv)
332 usage2 (_("Invalid certificate expiration period"), optarg); 331 usage2 (_("Invalid certificate expiration period"), optarg);
333 days_till_exp_warn = atoi (optarg); 332 days_till_exp_warn = atoi (optarg);
334 } 333 }
335 check_cert = TRUE; 334 check_cert = true;
336 goto enable_ssl; 335 goto enable_ssl;
337#endif 336#endif
338 case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ 337 case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */
339#ifdef HAVE_SSL 338#ifdef HAVE_SSL
340 continue_after_check_cert = TRUE; 339 continue_after_check_cert = true;
341 break; 340 break;
342#endif 341#endif
343 case 'J': /* use client certificate */ 342 case 'J': /* use client certificate */
@@ -357,7 +356,7 @@ process_arguments (int argc, char **argv)
357 enable_ssl: 356 enable_ssl:
358 /* ssl_version initialized to 0 as a default. Only set if it's non-zero. This helps when we include multiple 357 /* ssl_version initialized to 0 as a default. Only set if it's non-zero. This helps when we include multiple
359 parameters, like -S and -C combinations */ 358 parameters, like -S and -C combinations */
360 use_ssl = TRUE; 359 use_ssl = true;
361 if (c=='S' && optarg != NULL) { 360 if (c=='S' && optarg != NULL) {
362 int got_plus = strchr(optarg, '+') != NULL; 361 int got_plus = strchr(optarg, '+') != NULL;
363 362
@@ -374,7 +373,7 @@ process_arguments (int argc, char **argv)
374 else 373 else
375 usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)")); 374 usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)"));
376 } 375 }
377 if (specify_port == FALSE) 376 if (specify_port == false)
378 server_port = HTTPS_PORT; 377 server_port = HTTPS_PORT;
379#else 378#else
380 /* -C -J and -K fall through to here without SSL */ 379 /* -C -J and -K fall through to here without SSL */
@@ -382,7 +381,7 @@ process_arguments (int argc, char **argv)
382#endif 381#endif
383 break; 382 break;
384 case SNI_OPTION: 383 case SNI_OPTION:
385 use_sni = TRUE; 384 use_sni = true;
386 break; 385 break;
387 case MAX_REDIRS_OPTION: 386 case MAX_REDIRS_OPTION:
388 if (!is_intnonneg (optarg)) 387 if (!is_intnonneg (optarg))
@@ -420,7 +419,7 @@ process_arguments (int argc, char **argv)
420 host_name_length = strlen (host_name) - strlen (p) - 1; 419 host_name_length = strlen (host_name) - strlen (p) - 1;
421 free (host_name); 420 free (host_name);
422 host_name = strndup (optarg, host_name_length); 421 host_name = strndup (optarg, host_name_length);
423 if (specify_port == FALSE) 422 if (specify_port == false)
424 server_port = virtual_port; 423 server_port = virtual_port;
425 } 424 }
426 } else if ((p = strchr (host_name, ':')) != NULL 425 } else if ((p = strchr (host_name, ':')) != NULL
@@ -430,7 +429,7 @@ process_arguments (int argc, char **argv)
430 host_name_length = strlen (host_name) - strlen (p) - 1; 429 host_name_length = strlen (host_name) - strlen (p) - 1;
431 free (host_name); 430 free (host_name);
432 host_name = strndup (optarg, host_name_length); 431 host_name = strndup (optarg, host_name_length);
433 if (specify_port == FALSE) 432 if (specify_port == false)
434 server_port = virtual_port; 433 server_port = virtual_port;
435 } 434 }
436 break; 435 break;
@@ -446,7 +445,7 @@ process_arguments (int argc, char **argv)
446 usage2 (_("Invalid port number"), optarg); 445 usage2 (_("Invalid port number"), optarg);
447 else { 446 else {
448 server_port = atoi (optarg); 447 server_port = atoi (optarg);
449 specify_port = TRUE; 448 specify_port = true;
450 } 449 }
451 break; 450 break;
452 case 'a': /* authorization info */ 451 case 'a': /* authorization info */
@@ -502,7 +501,7 @@ process_arguments (int argc, char **argv)
502 if (errcode != 0) { 501 if (errcode != 0) {
503 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 502 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
504 printf (_("Could Not Compile Regular Expression: %s"), errbuf); 503 printf (_("Could Not Compile Regular Expression: %s"), errbuf);
505 return ERROR; 504 return false;
506 } 505 }
507 break; 506 break;
508 case INVERT_REGEX: 507 case INVERT_REGEX:
@@ -519,7 +518,7 @@ process_arguments (int argc, char **argv)
519#endif 518#endif
520 break; 519 break;
521 case 'v': /* verbose */ 520 case 'v': /* verbose */
522 verbose = TRUE; 521 verbose = true;
523 break; 522 break;
524 case 'm': /* min_page_length */ 523 case 'm': /* min_page_length */
525 { 524 {
@@ -544,7 +543,7 @@ process_arguments (int argc, char **argv)
544 break; 543 break;
545 } 544 }
546 case 'N': /* no-body */ 545 case 'N': /* no-body */
547 no_body = TRUE; 546 no_body = true;
548 break; 547 break;
549 case 'M': /* max-age */ 548 case 'M': /* max-age */
550 { 549 {
@@ -565,10 +564,10 @@ process_arguments (int argc, char **argv)
565 } 564 }
566 break; 565 break;
567 case 'E': /* show extended perfdata */ 566 case 'E': /* show extended perfdata */
568 show_extended_perfdata = TRUE; 567 show_extended_perfdata = true;
569 break; 568 break;
570 case 'B': /* print body content after status line */ 569 case 'B': /* print body content after status line */
571 show_body = TRUE; 570 show_body = true;
572 break; 571 break;
573 } 572 }
574 } 573 }
@@ -605,7 +604,7 @@ process_arguments (int argc, char **argv)
605 if (virtual_port == 0) 604 if (virtual_port == 0)
606 virtual_port = server_port; 605 virtual_port = server_port;
607 606
608 return TRUE; 607 return true;
609} 608}
610 609
611 610
@@ -945,7 +944,7 @@ check_http (void)
945 /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */ 944 /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */
946 945
947 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 946 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
948 && host_name != NULL && use_ssl == TRUE) { 947 && host_name != NULL && use_ssl == true) {
949 948
950 if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT); 949 if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT);
951 asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent); 950 asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent);
@@ -979,7 +978,7 @@ check_http (void)
979 } 978 }
980#ifdef HAVE_SSL 979#ifdef HAVE_SSL
981 elapsed_time_connect = (double)microsec_connect / 1.0e6; 980 elapsed_time_connect = (double)microsec_connect / 1.0e6;
982 if (use_ssl == TRUE) { 981 if (use_ssl == true) {
983 gettimeofday (&tv_temp, NULL); 982 gettimeofday (&tv_temp, NULL);
984 result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); 983 result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey);
985 if (verbose) printf ("SSL initialized\n"); 984 if (verbose) printf ("SSL initialized\n");
@@ -987,9 +986,9 @@ check_http (void)
987 die (STATE_CRITICAL, NULL); 986 die (STATE_CRITICAL, NULL);
988 microsec_ssl = deltime (tv_temp); 987 microsec_ssl = deltime (tv_temp);
989 elapsed_time_ssl = (double)microsec_ssl / 1.0e6; 988 elapsed_time_ssl = (double)microsec_ssl / 1.0e6;
990 if (check_cert == TRUE) { 989 if (check_cert == true) {
991 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); 990 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
992 if (continue_after_check_cert == FALSE) { 991 if (continue_after_check_cert == false) {
993 if (sd) close(sd); 992 if (sd) close(sd);
994 np_net_ssl_cleanup(); 993 np_net_ssl_cleanup();
995 return result; 994 return result;
@@ -999,7 +998,7 @@ check_http (void)
999#endif /* HAVE_SSL */ 998#endif /* HAVE_SSL */
1000 999
1001 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 1000 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
1002 && host_name != NULL && use_ssl == TRUE) 1001 && host_name != NULL && use_ssl == true)
1003 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 1002 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
1004 else 1003 else
1005 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 1004 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
@@ -1027,10 +1026,10 @@ check_http (void)
1027 * 14.23). Some server applications/configurations cause trouble if the 1026 * 14.23). Some server applications/configurations cause trouble if the
1028 * (default) port is explicitly specified in the "Host:" header line. 1027 * (default) port is explicitly specified in the "Host:" header line.
1029 */ 1028 */
1030 if ((use_ssl == FALSE && virtual_port == HTTP_PORT) || 1029 if ((use_ssl == false && virtual_port == HTTP_PORT) ||
1031 (use_ssl == TRUE && virtual_port == HTTPS_PORT) || 1030 (use_ssl == true && virtual_port == HTTPS_PORT) ||
1032 (server_address != NULL && strcmp(http_method, "CONNECT") == 0 1031 (server_address != NULL && strcmp(http_method, "CONNECT") == 0
1033 && host_name != NULL && use_ssl == TRUE)) 1032 && host_name != NULL && use_ssl == true))
1034 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); 1033 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name);
1035 else 1034 else
1036 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port); 1035 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port);
@@ -1334,7 +1333,7 @@ check_http (void)
1334 perfd_time (elapsed_time), 1333 perfd_time (elapsed_time),
1335 perfd_size (page_len), 1334 perfd_size (page_len),
1336 perfd_time_connect (elapsed_time_connect), 1335 perfd_time_connect (elapsed_time_connect),
1337 use_ssl == TRUE ? perfd_time_ssl (elapsed_time_ssl) : "", 1336 use_ssl == true ? perfd_time_ssl (elapsed_time_ssl) : "",
1338 perfd_time_headers (elapsed_time_headers), 1337 perfd_time_headers (elapsed_time_headers),
1339 perfd_time_firstbyte (elapsed_time_firstbyte), 1338 perfd_time_firstbyte (elapsed_time_firstbyte),
1340 perfd_time_transfer (elapsed_time_transfer)); 1339 perfd_time_transfer (elapsed_time_transfer));
@@ -1529,13 +1528,13 @@ redir (char *pos, char *status_line)
1529} 1528}
1530 1529
1531 1530
1532int 1531bool
1533server_type_check (const char *type) 1532server_type_check (const char *type)
1534{ 1533{
1535 if (strcmp (type, "https")) 1534 if (strcmp (type, "https"))
1536 return FALSE; 1535 return false;
1537 else 1536 else
1538 return TRUE; 1537 return true;
1539} 1538}
1540 1539
1541int 1540int
@@ -1550,42 +1549,42 @@ server_port_check (int ssl_flag)
1550char *perfd_time (double elapsed_time) 1549char *perfd_time (double elapsed_time)
1551{ 1550{
1552 return fperfdata ("time", elapsed_time, "s", 1551 return fperfdata ("time", elapsed_time, "s",
1553 thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, 1552 thlds->warning?true:false, thlds->warning?thlds->warning->end:0,
1554 thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, 1553 thlds->critical?true:false, thlds->critical?thlds->critical->end:0,
1555 TRUE, 0, TRUE, socket_timeout); 1554 true, 0, true, socket_timeout);
1556} 1555}
1557 1556
1558char *perfd_time_connect (double elapsed_time_connect) 1557char *perfd_time_connect (double elapsed_time_connect)
1559{ 1558{
1560 return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1559 return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1561} 1560}
1562 1561
1563char *perfd_time_ssl (double elapsed_time_ssl) 1562char *perfd_time_ssl (double elapsed_time_ssl)
1564{ 1563{
1565 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1564 return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1566} 1565}
1567 1566
1568char *perfd_time_headers (double elapsed_time_headers) 1567char *perfd_time_headers (double elapsed_time_headers)
1569{ 1568{
1570 return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1569 return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1571} 1570}
1572 1571
1573char *perfd_time_firstbyte (double elapsed_time_firstbyte) 1572char *perfd_time_firstbyte (double elapsed_time_firstbyte)
1574{ 1573{
1575 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1574 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1576} 1575}
1577 1576
1578char *perfd_time_transfer (double elapsed_time_transfer) 1577char *perfd_time_transfer (double elapsed_time_transfer)
1579{ 1578{
1580 return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); 1579 return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout);
1581} 1580}
1582 1581
1583char *perfd_size (int page_len) 1582char *perfd_size (int page_len)
1584{ 1583{
1585 return perfdata ("size", page_len, "B", 1584 return perfdata ("size", page_len, "B",
1586 (min_page_len>0?TRUE:FALSE), min_page_len, 1585 (min_page_len>0?true:false), min_page_len,
1587 (min_page_len>0?TRUE:FALSE), 0, 1586 (min_page_len>0?true:false), 0,
1588 TRUE, 0, FALSE, 0); 1587 true, 0, false, 0);
1589} 1588}
1590 1589
1591void 1590void