summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-02-08 05:32:40 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-02-08 05:32:40 (GMT)
commitd27d9950b2e698a015479b2a95e2503fe2d41848 (patch)
tree2d75436db406aa2cec2f212b6bb0c3a8e03f6211
parent799d7385bf2523ccf7a20b977b3d04a0626c9ba8 (diff)
downloadmonitoring-plugins-d27d9950b2e698a015479b2a95e2503fe2d41848.tar.gz
submit request with one send
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@292 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_http.c150
1 files changed, 48 insertions, 102 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index dabe35e..7cdd5e0 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -160,8 +160,10 @@ int check_certificate (X509 **);
160#endif 160#endif
161 161
162#ifdef HAVE_REGEX_H 162#ifdef HAVE_REGEX_H
163#define REGS 2 163enum {
164#define MAX_RE_SIZE 256 164 REGS = 2,
165 MAX_RE_SIZE = 256
166};
165#include <regex.h> 167#include <regex.h>
166regex_t preg; 168regex_t preg;
167regmatch_t pmatch[REGS]; 169regmatch_t pmatch[REGS];
@@ -178,15 +180,18 @@ struct timeval tv;
178 180
179#define server_port_check(use_ssl) (use_ssl ? HTTPS_PORT : HTTP_PORT) 181#define server_port_check(use_ssl) (use_ssl ? HTTPS_PORT : HTTP_PORT)
180 182
181#define MAX_IPV4_HOSTLENGTH 64
182#define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: " 183#define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
183#define URI_HTTP "%[HTPShtps]://" 184#define URI_HTTP "%[HTPShtps]://"
184#define URI_HOST "%[a-zA-Z0-9.-]" 185#define URI_HOST "%[a-zA-Z0-9.-]"
185#define URI_PORT ":%[0-9]" 186#define URI_PORT ":%[0-9]"
186#define URI_PATH "%[/a-zA-Z0-9._-=@,]" 187#define URI_PATH "%[/a-zA-Z0-9._-=@,]"
187 188
188#define HTTP_PORT 80 189enum {
189#define HTTPS_PORT 443 190 MAX_IPV4_HOSTLENGTH = 64,
191 HTTP_PORT = 80,
192 HTTPS_PORT = 443
193};
194
190#define HTTP_EXPECT "HTTP/1." 195#define HTTP_EXPECT "HTTP/1."
191#define HTTP_URL "/" 196#define HTTP_URL "/"
192#define CRLF "\r\n" 197#define CRLF "\r\n"
@@ -549,8 +554,9 @@ check_http (void)
549#ifdef HAVE_SSL 554#ifdef HAVE_SSL
550 if (use_ssl == TRUE) { 555 if (use_ssl == TRUE) {
551 556
552 if (connect_SSL () != OK) 557 if (connect_SSL () != OK) {
553 terminate (STATE_CRITICAL, "Unable to open TCP socket"); 558 terminate (STATE_CRITICAL, "Unable to open TCP socket");
559 }
554 560
555 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) { 561 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
556 X509_free (server_cert); 562 X509_free (server_cert);
@@ -560,112 +566,52 @@ check_http (void)
560 return STATE_CRITICAL; 566 return STATE_CRITICAL;
561 } 567 }
562 568
563 asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
564 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
565 ERR_print_errors_fp (stderr);
566 return STATE_CRITICAL;
567 }
568
569 /* optionally send the host header info (not clear if it's usable) */
570 if (strcmp (host_name, "")) {
571 asprintf (&buf, "Host: %s\r\n", host_name);
572 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
573 ERR_print_errors_fp (stderr);
574 return STATE_CRITICAL;
575 }
576 }
577
578 /* send user agent */
579 asprintf (&buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n",
580 clean_revstring (REVISION), PACKAGE_VERSION);
581 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
582 ERR_print_errors_fp (stderr);
583 return STATE_CRITICAL;
584 }
585
586 /* optionally send the authentication info */
587 if (strcmp (user_auth, "")) {
588 auth = base64 (user_auth, strlen (user_auth));
589 asprintf (&buf, "Authorization: Basic %s\r\n", auth);
590 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
591 ERR_print_errors_fp (stderr);
592 return STATE_CRITICAL;
593 }
594 }
595
596 /* either send http POST data */
597 if (strlen (http_post_data)) {
598 asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n");
599 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
600 ERR_print_errors_fp (stderr);
601 return STATE_CRITICAL;
602 }
603 asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data));
604 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
605 ERR_print_errors_fp (stderr);
606 return STATE_CRITICAL;
607 }
608 if (SSL_write (ssl, http_post_data, strlen (http_post_data)) == -1) {
609 ERR_print_errors_fp (stderr);
610 return STATE_CRITICAL;
611 }
612 asprintf (&buf, CRLF);
613 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
614 ERR_print_errors_fp (stderr);
615 return STATE_CRITICAL;
616 }
617 }
618 else {
619 /* or just a newline so the server knows we're done with the request */
620 asprintf (&buf, "\r\n");
621 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
622 ERR_print_errors_fp (stderr);
623 return STATE_CRITICAL;
624 }
625 }
626
627 } 569 }
628 else { 570 else {
629#endif 571#endif
630 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 572 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
631 terminate (STATE_CRITICAL, "Unable to open TCP socket"); 573 terminate (STATE_CRITICAL, "Unable to open TCP socket");
632 asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); 574#ifdef HAVE_SSL
633 send (sd, buf, strlen (buf), 0); 575 }
576#endif
634 577
635 /* optionally send the host header info */ 578 asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
636 if (strcmp (host_name, "")) {
637 asprintf (&buf, "Host: %s\r\n", host_name);
638 send (sd, buf, strlen (buf), 0);
639 }
640 579
641 /* send user agent */ 580 /* optionally send the host header info (not clear if it's usable) */
642 asprintf (&buf, 581 if (strcmp (host_name, ""))
643 "User-Agent: check_http/%s (nagios-plugins %s)\r\n", 582 asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
644 clean_revstring (REVISION), PACKAGE_VERSION);
645 send (sd, buf, strlen (buf), 0);
646 583
647 /* optionally send the authentication info */ 584 /* send user agent */
648 if (strcmp (user_auth, "")) { 585 asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n",
649 auth = base64 (user_auth, strlen (user_auth)); 586 buf, clean_revstring (REVISION), PACKAGE_VERSION);
650 asprintf (&buf, "Authorization: Basic %s\r\n", auth);
651 send (sd, buf, strlen (buf), 0);
652 }
653 587
654 /* either send http POST data */ 588 /* optionally send the authentication info */
655 /* written by Chris Henesy <lurker@shadowtech.org> */ 589 if (strcmp (user_auth, "")) {
656 if (strlen (http_post_data)) { 590 auth = base64 (user_auth, strlen (user_auth));
657 asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n"); 591 asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
658 send (sd, buf, strlen (buf), 0); 592 }
659 asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); 593
660 send (sd, buf, strlen (buf), 0); 594 /* either send http POST data */
661 send (sd, http_post_data, strlen (http_post_data), 0); 595 if (strlen (http_post_data)) {
662 send (sd, CRLF, strlen (CRLF), 0); 596 asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
663 } 597 asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data));
664 else { 598 asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF);
665 /* or just a newline so the server knows we're done with the request */ 599 }
666 asprintf (&buf, "\r\n"); 600 else {
667 send (sd, buf, strlen (buf), 0); 601 /* or just a newline so the server knows we're done with the request */
602 asprintf (&buf, "%s%s", buf, CRLF);
603 }
604
605#ifdef HAVE_SSL
606 if (use_ssl == TRUE) {
607 if (SSL_write (ssl, buf, strlen (buf)) == -1) {
608 ERR_print_errors_fp (stderr);
609 return STATE_CRITICAL;
668 } 610 }
611 }
612 else {
613#endif
614 send (sd, buf, strlen (buf), 0);
669#ifdef HAVE_SSL 615#ifdef HAVE_SSL
670 } 616 }
671#endif 617#endif