summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_curl.c8
-rw-r--r--plugins/check_http.c10
-rw-r--r--plugins/check_mysql_query.c12
-rw-r--r--plugins/check_pgsql.c2
-rw-r--r--plugins/check_snmp.c5
-rw-r--r--plugins/t/check_curl.t4
-rwxr-xr-xplugins/tests/check_curl.t16
7 files changed, 37 insertions, 20 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 19f80b74..8125ee84 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -314,8 +314,8 @@ static char *string_statuscode (int major, int minor)
314 /* assuming here HTTP/N with N>=4 */ 314 /* assuming here HTTP/N with N>=4 */
315 snprintf (buf, sizeof (buf), "HTTP/%d", major); 315 snprintf (buf, sizeof (buf), "HTTP/%d", major);
316 break; 316 break;
317 } 317 }
318 318
319 return buf; 319 return buf;
320} 320}
321 321
@@ -665,7 +665,7 @@ check_http (void)
665 /* Curl errors, result in critical Nagios state */ 665 /* Curl errors, result in critical Nagios state */
666 if (res != CURLE_OK) { 666 if (res != CURLE_OK) {
667 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), 667 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"),
668 server_port, res, curl_easy_strerror(res)); 668 server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res));
669 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); 669 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
670 } 670 }
671 671
@@ -2071,7 +2071,7 @@ get_header_value (const struct phr_header* headers, const size_t nof_headers, co
2071{ 2071{
2072 int i; 2072 int i;
2073 for( i = 0; i < nof_headers; i++ ) { 2073 for( i = 0; i < nof_headers; i++ ) {
2074 if( strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { 2074 if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) {
2075 return strndup( headers[i].value, headers[i].value_len ); 2075 return strndup( headers[i].value, headers[i].value_len );
2076 } 2076 }
2077 } 2077 }
diff --git a/plugins/check_http.c b/plugins/check_http.c
index e2298b17..0b712665 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -72,7 +72,7 @@ int maximum_age = -1;
72 72
73enum { 73enum {
74 REGS = 2, 74 REGS = 2,
75 MAX_RE_SIZE = 256 75 MAX_RE_SIZE = 1024
76}; 76};
77#include "regex.h" 77#include "regex.h"
78regex_t preg; 78regex_t preg;
@@ -1567,6 +1567,10 @@ print_help (void)
1567 1567
1568 print_usage (); 1568 print_usage ();
1569 1569
1570#ifdef HAVE_SSL
1571 printf (_("In the first form, make an HTTP request."));
1572 printf (_("In the second form, connect to the server and check the TLS certificate."));
1573#endif
1570 printf (_("NOTE: One or both of -H and -I must be specified")); 1574 printf (_("NOTE: One or both of -H and -I must be specified"));
1571 1575
1572 printf ("\n"); 1576 printf ("\n");
@@ -1726,6 +1730,8 @@ print_usage (void)
1726 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); 1730 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
1727 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1731 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1728 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1732 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1729 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); 1733 printf (" [-A string] [-k string] [-S <version>] [--sni]\n");
1730 printf (" [-T <content-type>] [-j method]\n"); 1734 printf (" [-T <content-type>] [-j method]\n");
1735 printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname);
1736 printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n");
1731} 1737}
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index 49a14dd3..ac2fb15d 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -136,18 +136,18 @@ main (int argc, char **argv)
136 die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error); 136 die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error);
137 } 137 }
138 138
139 /* free the result */
140 mysql_free_result (res);
141
142 /* close the connection */
143 mysql_close (&mysql);
144
145 if (! is_numeric(row[0])) { 139 if (! is_numeric(row[0])) {
146 die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]); 140 die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]);
147 } 141 }
148 142
149 value = strtod(row[0], NULL); 143 value = strtod(row[0], NULL);
150 144
145 /* free the result */
146 mysql_free_result (res);
147
148 /* close the connection */
149 mysql_close (&mysql);
150
151 if (verbose >= 3) 151 if (verbose >= 3)
152 printf("mysql result: %f\n", value); 152 printf("mysql result: %f\n", value);
153 153
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 11ce6916..b8fc5f1d 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -347,7 +347,7 @@ process_arguments (int argc, char **argv)
347 if (!is_pg_dbname (optarg)) /* checks length and valid chars */ 347 if (!is_pg_dbname (optarg)) /* checks length and valid chars */
348 usage2 (_("Database name is not valid"), optarg); 348 usage2 (_("Database name is not valid"), optarg);
349 else /* we know length, and know optarg is terminated, so us strcpy */ 349 else /* we know length, and know optarg is terminated, so us strcpy */
350 strcpy (dbName, optarg); 350 snprintf(dbName, NAMEDATALEN, "%s", optarg);
351 break; 351 break;
352 case 'l': /* login name */ 352 case 'l': /* login name */
353 if (!is_pg_logname (optarg)) 353 if (!is_pg_logname (optarg))
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index e8a21a40..afc568b2 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -576,6 +576,9 @@ main (int argc, char **argv)
576 len = sizeof(perfstr)-strlen(perfstr)-1; 576 len = sizeof(perfstr)-strlen(perfstr)-1;
577 strncat(perfstr, show, len>ptr-show ? ptr-show : len); 577 strncat(perfstr, show, len>ptr-show ? ptr-show : len);
578 578
579 if (type)
580 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
581
579 if (warning_thresholds) { 582 if (warning_thresholds) {
580 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 583 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
581 strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); 584 strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
@@ -588,8 +591,6 @@ main (int argc, char **argv)
588 strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); 591 strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
589 } 592 }
590 593
591 if (type)
592 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
593 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 594 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
594 } 595 }
595 } 596 }
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t
index 55577add..a4f1dfb3 100644
--- a/plugins/t/check_curl.t
+++ b/plugins/t/check_curl.t
@@ -46,7 +46,7 @@ $res = NPTest->testCmd(
46 ); 46 );
47cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); 47cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
48# was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) 48# was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!)
49cmp_ok( $res->output, 'eq', "HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Timeout was reached", "Output OK"); 49like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK");
50 50
51$res = NPTest->testCmd( 51$res = NPTest->testCmd(
52 "./$plugin $hostname_invalid -wt 1 -ct 2" 52 "./$plugin $hostname_invalid -wt 1 -ct 2"
@@ -56,7 +56,7 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
56# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename 56# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename
57# Is also possible to get a socket timeout if DNS is not responding fast enough 57# Is also possible to get a socket timeout if DNS is not responding fast enough
58# cURL gives us consistent strings from it's own 'lib/strerror.c' 58# cURL gives us consistent strings from it's own 'lib/strerror.c'
59like( $res->output, "/cURL returned 6 - Couldn't resolve host name/", "Output OK"); 59like( $res->output, "/cURL returned 6 - Could not resolve host:/", "Output OK");
60 60
61# host header checks 61# host header checks
62$res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); 62$res = NPTest->testCmd("./$plugin -v -H $host_tcp_http");
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
index 1afbe4bb..0caad23d 100755
--- a/plugins/tests/check_curl.t
+++ b/plugins/tests/check_curl.t
@@ -21,7 +21,7 @@ use FindBin qw($Bin);
21 21
22$ENV{'LC_TIME'} = "C"; 22$ENV{'LC_TIME'} = "C";
23 23
24my $common_tests = 70; 24my $common_tests = 72;
25my $ssl_only_tests = 8; 25my $ssl_only_tests = 8;
26# Check that all dependent modules are available 26# Check that all dependent modules are available
27eval "use HTTP::Daemon 6.01;"; 27eval "use HTTP::Daemon 6.01;";
@@ -188,6 +188,12 @@ sub run_server {
188 $c->send_basic_header; 188 $c->send_basic_header;
189 $c->send_header('foo'); 189 $c->send_header('foo');
190 $c->send_crlf; 190 $c->send_crlf;
191 } elsif ($r->url->path eq "/header_broken_check") {
192 $c->send_basic_header;
193 $c->send_header('foo');
194 print $c "Test1:: broken\n";
195 print $c " Test2: leading whitespace\n";
196 $c->send_crlf;
191 } elsif ($r->url->path eq "/virtual_port") { 197 } elsif ($r->url->path eq "/virtual_port") {
192 # return sent Host header 198 # return sent Host header
193 $c->send_basic_header; 199 $c->send_basic_header;
@@ -247,7 +253,7 @@ my $cmd;
247# advanced checks with virtual hostname and virtual port 253# advanced checks with virtual hostname and virtual port
248SKIP: { 254SKIP: {
249 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks; 255 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks;
250 256
251 # http without virtual port 257 # http without virtual port
252 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; 258 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$";
253 $result = NPTest->testCmd( $cmd ); 259 $result = NPTest->testCmd( $cmd );
@@ -259,7 +265,7 @@ SKIP: {
259 $result = NPTest->testCmd( $cmd ); 265 $result = NPTest->testCmd( $cmd );
260 is( $result->return_code, 0, $cmd); 266 is( $result->return_code, 0, $cmd);
261 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 267 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
262 268
263 # http with virtual port (80) 269 # http with virtual port (80)
264 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; 270 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$";
265 $result = NPTest->testCmd( $cmd ); 271 $result = NPTest->testCmd( $cmd );
@@ -321,6 +327,10 @@ sub run_common_tests {
321 is( $result->return_code, 2, "Missing header string check"); 327 is( $result->return_code, 2, "Missing header string check");
322 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); 328 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location");
323 329
330 $result = NPTest->testCmd( "$command -u /header_broken_check" );
331 is( $result->return_code, 0, "header_check search for string");
332 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" );
333
324 my $cmd; 334 my $cmd;
325 $cmd = "$command -u /slow"; 335 $cmd = "$command -u /slow";
326 $result = NPTest->testCmd( $cmd ); 336 $result = NPTest->testCmd( $cmd );