diff options
Diffstat (limited to 'plugins')
41 files changed, 666 insertions, 305 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ab59eb7..49086b7 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -112,7 +112,7 @@ check_tcp_LDADD = $(SSLOBJS) | |||
112 | check_time_LDADD = $(NETLIBS) | 112 | check_time_LDADD = $(NETLIBS) |
113 | check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) | 113 | check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) |
114 | check_ups_LDADD = $(NETLIBS) | 114 | check_ups_LDADD = $(NETLIBS) |
115 | check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS) | 115 | check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS) $(SYSTEMDLIBS) |
116 | check_by_ssh_LDADD = $(NETLIBS) | 116 | check_by_ssh_LDADD = $(NETLIBS) |
117 | check_ide_smart_LDADD = $(BASEOBJS) | 117 | check_ide_smart_LDADD = $(BASEOBJS) |
118 | negate_LDADD = $(BASEOBJS) | 118 | negate_LDADD = $(BASEOBJS) |
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index c37d45d..d0871c4 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -55,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
55 | #include "uriparser/Uri.h" | 55 | #include "uriparser/Uri.h" |
56 | 56 | ||
57 | #include <arpa/inet.h> | 57 | #include <arpa/inet.h> |
58 | #include <netinet/in.h> | ||
58 | 59 | ||
59 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 60 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
60 | #include <openssl/opensslv.h> | 61 | #include <openssl/opensslv.h> |
@@ -243,7 +244,7 @@ void curlhelp_freewritebuffer (curlhelp_write_curlbuf*); | |||
243 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); | 244 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); |
244 | int curlhelp_buffer_read_callback (void *, size_t , size_t , void *); | 245 | int curlhelp_buffer_read_callback (void *, size_t , size_t , void *); |
245 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); | 246 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); |
246 | curlhelp_ssl_library curlhelp_get_ssl_library (CURL*); | 247 | curlhelp_ssl_library curlhelp_get_ssl_library (); |
247 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); | 248 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); |
248 | int net_noopenssl_check_certificate (cert_ptr_union*, int, int); | 249 | int net_noopenssl_check_certificate (cert_ptr_union*, int, int); |
249 | 250 | ||
@@ -296,6 +297,7 @@ main (int argc, char **argv) | |||
296 | 297 | ||
297 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | 298 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) |
298 | { | 299 | { |
300 | (void) preverify_ok; | ||
299 | /* TODO: we get all certificates of the chain, so which ones | 301 | /* TODO: we get all certificates of the chain, so which ones |
300 | * should we test? | 302 | * should we test? |
301 | * TODO: is the last certificate always the server certificate? | 303 | * TODO: is the last certificate always the server certificate? |
@@ -320,6 +322,8 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | |||
320 | 322 | ||
321 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) | 323 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) |
322 | { | 324 | { |
325 | (void) curl; // ignore unused parameter | ||
326 | (void) parm; // ignore unused parameter | ||
323 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); | 327 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); |
324 | 328 | ||
325 | return CURLE_OK; | 329 | return CURLE_OK; |
@@ -374,8 +378,12 @@ void | |||
374 | handle_curl_option_return_code (CURLcode res, const char* option) | 378 | handle_curl_option_return_code (CURLcode res, const char* option) |
375 | { | 379 | { |
376 | if (res != CURLE_OK) { | 380 | if (res != CURLE_OK) { |
377 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Error while setting cURL option '%s': cURL returned %d - %s"), | 381 | snprintf (msg, |
378 | option, res, curl_easy_strerror(res)); | 382 | DEFAULT_BUFFER_SIZE, |
383 | _("Error while setting cURL option '%s': cURL returned %d - %s"), | ||
384 | option, | ||
385 | res, | ||
386 | curl_easy_strerror(res)); | ||
379 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 387 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
380 | } | 388 | } |
381 | } | 389 | } |
@@ -384,8 +392,11 @@ int | |||
384 | lookup_host (const char *host, char *buf, size_t buflen) | 392 | lookup_host (const char *host, char *buf, size_t buflen) |
385 | { | 393 | { |
386 | struct addrinfo hints, *res, *result; | 394 | struct addrinfo hints, *res, *result; |
395 | char addrstr[100]; | ||
396 | size_t addrstr_len; | ||
387 | int errcode; | 397 | int errcode; |
388 | void *ptr; | 398 | void *ptr; |
399 | size_t buflen_remaining = buflen - 1; | ||
389 | 400 | ||
390 | memset (&hints, 0, sizeof (hints)); | 401 | memset (&hints, 0, sizeof (hints)); |
391 | hints.ai_family = address_family; | 402 | hints.ai_family = address_family; |
@@ -395,26 +406,40 @@ lookup_host (const char *host, char *buf, size_t buflen) | |||
395 | errcode = getaddrinfo (host, NULL, &hints, &result); | 406 | errcode = getaddrinfo (host, NULL, &hints, &result); |
396 | if (errcode != 0) | 407 | if (errcode != 0) |
397 | return errcode; | 408 | return errcode; |
398 | 409 | ||
410 | strcpy(buf, ""); | ||
399 | res = result; | 411 | res = result; |
400 | 412 | ||
401 | while (res) { | 413 | while (res) { |
402 | inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); | 414 | switch (res->ai_family) { |
403 | switch (res->ai_family) { | 415 | case AF_INET: |
404 | case AF_INET: | 416 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; |
405 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; | 417 | break; |
406 | break; | 418 | case AF_INET6: |
407 | case AF_INET6: | 419 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; |
408 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | 420 | break; |
409 | break; | ||
410 | } | 421 | } |
411 | inet_ntop (res->ai_family, ptr, buf, buflen); | 422 | |
412 | if (verbose >= 1) | 423 | inet_ntop (res->ai_family, ptr, addrstr, 100); |
424 | if (verbose >= 1) { | ||
413 | printf ("* getaddrinfo IPv%d address: %s\n", | 425 | printf ("* getaddrinfo IPv%d address: %s\n", |
414 | res->ai_family == PF_INET6 ? 6 : 4, buf); | 426 | res->ai_family == PF_INET6 ? 6 : 4, addrstr); |
427 | } | ||
428 | |||
429 | // Append all IPs to buf as a comma-separated string | ||
430 | addrstr_len = strlen(addrstr); | ||
431 | if (buflen_remaining > addrstr_len + 1) { | ||
432 | if (buf[0] != '\0') { | ||
433 | strncat(buf, ",", buflen_remaining); | ||
434 | buflen_remaining -= 1; | ||
435 | } | ||
436 | strncat(buf, addrstr, buflen_remaining); | ||
437 | buflen_remaining -= addrstr_len; | ||
438 | } | ||
439 | |||
415 | res = res->ai_next; | 440 | res = res->ai_next; |
416 | } | 441 | } |
417 | 442 | ||
418 | freeaddrinfo(result); | 443 | freeaddrinfo(result); |
419 | 444 | ||
420 | return 0; | 445 | return 0; |
@@ -445,7 +470,7 @@ check_http (void) | |||
445 | int i; | 470 | int i; |
446 | char *force_host_header = NULL; | 471 | char *force_host_header = NULL; |
447 | struct curl_slist *host = NULL; | 472 | struct curl_slist *host = NULL; |
448 | char addrstr[100]; | 473 | char addrstr[DEFAULT_BUFFER_SIZE/2]; |
449 | char dnscache[DEFAULT_BUFFER_SIZE]; | 474 | char dnscache[DEFAULT_BUFFER_SIZE]; |
450 | 475 | ||
451 | /* initialize curl */ | 476 | /* initialize curl */ |
@@ -497,10 +522,14 @@ check_http (void) | |||
497 | 522 | ||
498 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy | 523 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy |
499 | if(use_ssl && host_name != NULL) { | 524 | if(use_ssl && host_name != NULL) { |
500 | if ( (res=lookup_host (server_address, addrstr, 100)) != 0) { | 525 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { |
501 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), | 526 | snprintf (msg, |
502 | server_address, res, gai_strerror (res)); | 527 | DEFAULT_BUFFER_SIZE, |
503 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 528 | _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), |
529 | server_address, | ||
530 | res, | ||
531 | gai_strerror (res)); | ||
532 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
504 | } | 533 | } |
505 | snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, addrstr); | 534 | snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, addrstr); |
506 | host = curl_slist_append(NULL, dnscache); | 535 | host = curl_slist_append(NULL, dnscache); |
@@ -524,7 +553,7 @@ check_http (void) | |||
524 | /* compose URL: use the address we want to connect to, set Host: header later */ | 553 | /* compose URL: use the address we want to connect to, set Host: header later */ |
525 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", | 554 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", |
526 | use_ssl ? "https" : "http", | 555 | use_ssl ? "https" : "http", |
527 | use_ssl & host_name != NULL ? host_name : server_address, | 556 | ( use_ssl & ( host_name != NULL ) ) ? host_name : server_address, |
528 | server_port, | 557 | server_port, |
529 | server_url | 558 | server_url |
530 | ); | 559 | ); |
@@ -600,7 +629,7 @@ check_http (void) | |||
600 | 629 | ||
601 | #ifdef LIBCURL_FEATURE_SSL | 630 | #ifdef LIBCURL_FEATURE_SSL |
602 | 631 | ||
603 | /* set SSL version, warn about unsecure or unsupported versions */ | 632 | /* set SSL version, warn about insecure or unsupported versions */ |
604 | if (use_ssl) { | 633 | if (use_ssl) { |
605 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version), "CURLOPT_SSLVERSION"); | 634 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version), "CURLOPT_SSLVERSION"); |
606 | } | 635 | } |
@@ -628,7 +657,7 @@ check_http (void) | |||
628 | } | 657 | } |
629 | 658 | ||
630 | /* detect SSL library used by libcurl */ | 659 | /* detect SSL library used by libcurl */ |
631 | ssl_library = curlhelp_get_ssl_library (curl); | 660 | ssl_library = curlhelp_get_ssl_library (); |
632 | 661 | ||
633 | /* try hard to get a stack of certificates to verify against */ | 662 | /* try hard to get a stack of certificates to verify against */ |
634 | if (check_cert) { | 663 | if (check_cert) { |
@@ -792,12 +821,19 @@ check_http (void) | |||
792 | /* free header and server IP resolve lists, we don't need it anymore */ | 821 | /* free header and server IP resolve lists, we don't need it anymore */ |
793 | curl_slist_free_all (header_list); header_list = NULL; | 822 | curl_slist_free_all (header_list); header_list = NULL; |
794 | curl_slist_free_all (server_ips); server_ips = NULL; | 823 | curl_slist_free_all (server_ips); server_ips = NULL; |
824 | if (host) { | ||
825 | curl_slist_free_all (host); host = NULL; | ||
826 | } | ||
795 | 827 | ||
796 | /* Curl errors, result in critical Nagios state */ | 828 | /* Curl errors, result in critical Nagios state */ |
797 | if (res != CURLE_OK) { | 829 | if (res != CURLE_OK) { |
798 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), | 830 | snprintf (msg, |
799 | server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res)); | 831 | DEFAULT_BUFFER_SIZE, |
800 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 832 | _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), |
833 | server_port, | ||
834 | res, | ||
835 | errbuf[0] ? errbuf : curl_easy_strerror(res)); | ||
836 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
801 | } | 837 | } |
802 | 838 | ||
803 | /* certificate checks */ | 839 | /* certificate checks */ |
@@ -840,15 +876,19 @@ check_http (void) | |||
840 | } | 876 | } |
841 | GOT_FIRST_CERT: | 877 | GOT_FIRST_CERT: |
842 | if (!raw_cert) { | 878 | if (!raw_cert) { |
843 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot retrieve certificates from CERTINFO information - certificate data was empty")); | 879 | snprintf (msg, |
844 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 880 | DEFAULT_BUFFER_SIZE, |
881 | _("Cannot retrieve certificates from CERTINFO information - certificate data was empty")); | ||
882 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
845 | } | 883 | } |
846 | BIO* cert_BIO = BIO_new (BIO_s_mem()); | 884 | BIO* cert_BIO = BIO_new (BIO_s_mem()); |
847 | BIO_write (cert_BIO, raw_cert, strlen(raw_cert)); | 885 | BIO_write (cert_BIO, raw_cert, strlen(raw_cert)); |
848 | cert = PEM_read_bio_X509 (cert_BIO, NULL, NULL, NULL); | 886 | cert = PEM_read_bio_X509 (cert_BIO, NULL, NULL, NULL); |
849 | if (!cert) { | 887 | if (!cert) { |
850 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot read certificate from CERTINFO information - BIO error")); | 888 | snprintf (msg, |
851 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 889 | DEFAULT_BUFFER_SIZE, |
890 | _("Cannot read certificate from CERTINFO information - BIO error")); | ||
891 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
852 | } | 892 | } |
853 | BIO_free (cert_BIO); | 893 | BIO_free (cert_BIO); |
854 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 894 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
@@ -865,9 +905,12 @@ GOT_FIRST_CERT: | |||
865 | } | 905 | } |
866 | #endif /* USE_OPENSSL */ | 906 | #endif /* USE_OPENSSL */ |
867 | } else { | 907 | } else { |
868 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot retrieve certificates - cURL returned %d - %s"), | 908 | snprintf (msg, |
869 | res, curl_easy_strerror(res)); | 909 | DEFAULT_BUFFER_SIZE, |
870 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 910 | _("Cannot retrieve certificates - cURL returned %d - %s"), |
911 | res, | ||
912 | curl_easy_strerror(res)); | ||
913 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
871 | } | 914 | } |
872 | } | 915 | } |
873 | } | 916 | } |
@@ -906,8 +949,11 @@ GOT_FIRST_CERT: | |||
906 | 949 | ||
907 | /* get status line of answer, check sanity of HTTP code */ | 950 | /* get status line of answer, check sanity of HTTP code */ |
908 | if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { | 951 | if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { |
909 | snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n", | 952 | snprintf (msg, |
910 | total_time, perfstring); | 953 | DEFAULT_BUFFER_SIZE, |
954 | "Unparsable status line in %.3g seconds response time|%s\n", | ||
955 | total_time, | ||
956 | perfstring); | ||
911 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | 957 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ |
912 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); | 958 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); |
913 | } | 959 | } |
@@ -927,9 +973,16 @@ GOT_FIRST_CERT: | |||
927 | /* make sure the status line matches the response we are looking for */ | 973 | /* make sure the status line matches the response we are looking for */ |
928 | if (!expected_statuscode(status_line.first_line, server_expect)) { | 974 | if (!expected_statuscode(status_line.first_line, server_expect)) { |
929 | if (server_port == HTTP_PORT) | 975 | if (server_port == HTTP_PORT) |
930 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), status_line.first_line); | 976 | snprintf(msg, |
977 | DEFAULT_BUFFER_SIZE, | ||
978 | _("Invalid HTTP response received from host: %s\n"), | ||
979 | status_line.first_line); | ||
931 | else | 980 | else |
932 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line.first_line); | 981 | snprintf(msg, |
982 | DEFAULT_BUFFER_SIZE, | ||
983 | _("Invalid HTTP response received from host on port %d: %s\n"), | ||
984 | server_port, | ||
985 | status_line.first_line); | ||
933 | die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg, | 986 | die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg, |
934 | show_body ? "\n" : "", | 987 | show_body ? "\n" : "", |
935 | show_body ? body_buf.buf : ""); | 988 | show_body ? body_buf.buf : ""); |
@@ -965,7 +1018,7 @@ GOT_FIRST_CERT: | |||
965 | } | 1018 | } |
966 | } else { | 1019 | } else { |
967 | /* this is a specific code in the command line to | 1020 | /* this is a specific code in the command line to |
968 | * be returned when a redirection is encoutered | 1021 | * be returned when a redirection is encountered |
969 | */ | 1022 | */ |
970 | } | 1023 | } |
971 | result = max_state_alt (onredirect, result); | 1024 | result = max_state_alt (onredirect, result); |
@@ -1002,23 +1055,55 @@ GOT_FIRST_CERT: | |||
1002 | 1055 | ||
1003 | if (strlen (header_expect)) { | 1056 | if (strlen (header_expect)) { |
1004 | if (!strstr (header_buf.buf, header_expect)) { | 1057 | if (!strstr (header_buf.buf, header_expect)) { |
1058 | |||
1005 | strncpy(&output_header_search[0],header_expect,sizeof(output_header_search)); | 1059 | strncpy(&output_header_search[0],header_expect,sizeof(output_header_search)); |
1060 | |||
1006 | if(output_header_search[sizeof(output_header_search)-1]!='\0') { | 1061 | if(output_header_search[sizeof(output_header_search)-1]!='\0') { |
1007 | bcopy("...",&output_header_search[sizeof(output_header_search)-4],4); | 1062 | bcopy("...",&output_header_search[sizeof(output_header_search)-4],4); |
1008 | } | 1063 | } |
1009 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, output_header_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); | 1064 | |
1010 | result = STATE_CRITICAL; | 1065 | char tmp[DEFAULT_BUFFER_SIZE]; |
1066 | |||
1067 | snprintf (tmp, | ||
1068 | DEFAULT_BUFFER_SIZE, | ||
1069 | _("%sheader '%s' not found on '%s://%s:%d%s', "), | ||
1070 | msg, | ||
1071 | output_header_search, | ||
1072 | use_ssl ? "https" : "http", | ||
1073 | host_name ? host_name : server_address, | ||
1074 | server_port, | ||
1075 | server_url); | ||
1076 | |||
1077 | strcpy(msg, tmp); | ||
1078 | |||
1079 | result = STATE_CRITICAL; | ||
1011 | } | 1080 | } |
1012 | } | 1081 | } |
1013 | 1082 | ||
1014 | if (strlen (string_expect)) { | 1083 | if (strlen (string_expect)) { |
1015 | if (!strstr (body_buf.buf, string_expect)) { | 1084 | if (!strstr (body_buf.buf, string_expect)) { |
1085 | |||
1016 | strncpy(&output_string_search[0],string_expect,sizeof(output_string_search)); | 1086 | strncpy(&output_string_search[0],string_expect,sizeof(output_string_search)); |
1087 | |||
1017 | if(output_string_search[sizeof(output_string_search)-1]!='\0') { | 1088 | if(output_string_search[sizeof(output_string_search)-1]!='\0') { |
1018 | bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); | 1089 | bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); |
1019 | } | 1090 | } |
1020 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); | 1091 | |
1021 | result = STATE_CRITICAL; | 1092 | char tmp[DEFAULT_BUFFER_SIZE]; |
1093 | |||
1094 | snprintf (tmp, | ||
1095 | DEFAULT_BUFFER_SIZE, | ||
1096 | _("%sstring '%s' not found on '%s://%s:%d%s', "), | ||
1097 | msg, | ||
1098 | output_string_search, | ||
1099 | use_ssl ? "https" : "http", | ||
1100 | host_name ? host_name : server_address, | ||
1101 | server_port, | ||
1102 | server_url); | ||
1103 | |||
1104 | strcpy(msg, tmp); | ||
1105 | |||
1106 | result = STATE_CRITICAL; | ||
1022 | } | 1107 | } |
1023 | } | 1108 | } |
1024 | 1109 | ||
@@ -1029,27 +1114,48 @@ GOT_FIRST_CERT: | |||
1029 | result = max_state_alt(STATE_OK, result); | 1114 | result = max_state_alt(STATE_OK, result); |
1030 | } | 1115 | } |
1031 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { | 1116 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { |
1032 | if (!invert_regex) | 1117 | if (!invert_regex) { |
1033 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); | 1118 | char tmp[DEFAULT_BUFFER_SIZE]; |
1034 | else | 1119 | |
1035 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); | 1120 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); |
1036 | result = STATE_CRITICAL; | 1121 | strcpy(msg, tmp); |
1037 | } | 1122 | |
1038 | else { | 1123 | } else { |
1039 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1124 | char tmp[DEFAULT_BUFFER_SIZE]; |
1040 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sExecute Error: %s, "), msg, errbuf); | 1125 | |
1041 | result = STATE_UNKNOWN; | 1126 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); |
1042 | } | 1127 | strcpy(msg, tmp); |
1128 | |||
1129 | } | ||
1130 | result = STATE_CRITICAL; | ||
1131 | } else { | ||
1132 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | ||
1133 | |||
1134 | char tmp[DEFAULT_BUFFER_SIZE]; | ||
1135 | |||
1136 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sExecute Error: %s, "), msg, errbuf); | ||
1137 | strcpy(msg, tmp); | ||
1138 | result = STATE_UNKNOWN; | ||
1139 | } | ||
1043 | } | 1140 | } |
1044 | 1141 | ||
1045 | /* make sure the page is of an appropriate size */ | 1142 | /* make sure the page is of an appropriate size */ |
1046 | if ((max_page_len > 0) && (page_len > max_page_len)) { | 1143 | if ((max_page_len > 0) && (page_len > max_page_len)) { |
1047 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); | 1144 | char tmp[DEFAULT_BUFFER_SIZE]; |
1048 | result = max_state_alt(STATE_WARNING, result); | 1145 | |
1049 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { | 1146 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); |
1050 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too small, "), msg, page_len); | 1147 | |
1051 | result = max_state_alt(STATE_WARNING, result); | 1148 | strcpy(msg, tmp); |
1052 | } | 1149 | |
1150 | result = max_state_alt(STATE_WARNING, result); | ||
1151 | |||
1152 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { | ||
1153 | char tmp[DEFAULT_BUFFER_SIZE]; | ||
1154 | |||
1155 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%spage size %d too small, "), msg, page_len); | ||
1156 | strcpy(msg, tmp); | ||
1157 | result = max_state_alt(STATE_WARNING, result); | ||
1158 | } | ||
1053 | 1159 | ||
1054 | /* -w, -c: check warning and critical level */ | 1160 | /* -w, -c: check warning and critical level */ |
1055 | result = max_state_alt(get_status(total_time, thlds), result); | 1161 | result = max_state_alt(get_status(total_time, thlds), result); |
@@ -1633,6 +1739,7 @@ process_arguments (int argc, char **argv) | |||
1633 | break; | 1739 | break; |
1634 | case 'R': /* regex */ | 1740 | case 'R': /* regex */ |
1635 | cflags |= REG_ICASE; | 1741 | cflags |= REG_ICASE; |
1742 | // fall through | ||
1636 | case 'r': /* regex */ | 1743 | case 'r': /* regex */ |
1637 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); | 1744 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); |
1638 | regexp[MAX_RE_SIZE - 1] = 0; | 1745 | regexp[MAX_RE_SIZE - 1] = 0; |
@@ -2030,7 +2137,7 @@ print_usage (void) | |||
2030 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); | 2137 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); |
2031 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>] [-D]\n"); | 2138 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>] [-D]\n"); |
2032 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); | 2139 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); |
2033 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\n"); | 2140 | printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n"); |
2034 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 2141 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
2035 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 2142 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
2036 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); | 2143 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
@@ -2196,11 +2303,10 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line) | |||
2196 | if( strchr( p, '.' ) != NULL ) { | 2303 | if( strchr( p, '.' ) != NULL ) { |
2197 | 2304 | ||
2198 | /* HTTP 1.x case */ | 2305 | /* HTTP 1.x case */ |
2199 | char *ppp; | 2306 | strtok( p, "." ); |
2200 | ppp = strtok( p, "." ); | ||
2201 | status_line->http_major = (int)strtol( p, &pp, 10 ); | 2307 | status_line->http_major = (int)strtol( p, &pp, 10 ); |
2202 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | 2308 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } |
2203 | ppp = strtok( NULL, " " ); | 2309 | strtok( NULL, " " ); |
2204 | status_line->http_minor = (int)strtol( p, &pp, 10 ); | 2310 | status_line->http_minor = (int)strtol( p, &pp, 10 ); |
2205 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | 2311 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } |
2206 | p += 4; /* 1.x SP */ | 2312 | p += 4; /* 1.x SP */ |
@@ -2287,37 +2393,67 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA | |||
2287 | server_date = get_header_value (headers, nof_headers, "date"); | 2393 | server_date = get_header_value (headers, nof_headers, "date"); |
2288 | document_date = get_header_value (headers, nof_headers, "last-modified"); | 2394 | document_date = get_header_value (headers, nof_headers, "last-modified"); |
2289 | 2395 | ||
2290 | if (!server_date || !*server_date) { | 2396 | if (!server_date || !*server_date) { |
2291 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date unknown, "), *msg); | 2397 | char tmp[DEFAULT_BUFFER_SIZE]; |
2292 | date_result = max_state_alt(STATE_UNKNOWN, date_result); | 2398 | |
2293 | } else if (!document_date || !*document_date) { | 2399 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sServer date unknown, "), *msg); |
2294 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument modification date unknown, "), *msg); | 2400 | strcpy(*msg, tmp); |
2295 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2401 | |
2402 | date_result = max_state_alt(STATE_UNKNOWN, date_result); | ||
2403 | |||
2404 | } else if (!document_date || !*document_date) { | ||
2405 | char tmp[DEFAULT_BUFFER_SIZE]; | ||
2406 | |||
2407 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sDocument modification date unknown, "), *msg); | ||
2408 | strcpy(*msg, tmp); | ||
2409 | |||
2410 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2411 | |||
2296 | } else { | 2412 | } else { |
2297 | time_t srv_data = curl_getdate (server_date, NULL); | 2413 | time_t srv_data = curl_getdate (server_date, NULL); |
2298 | time_t doc_data = curl_getdate (document_date, NULL); | 2414 | time_t doc_data = curl_getdate (document_date, NULL); |
2299 | if (verbose >= 2) | 2415 | if (verbose >= 2) |
2300 | printf ("* server date: '%s' (%d), doc_date: '%s' (%d)\n", server_date, (int)srv_data, document_date, (int)doc_data); | 2416 | printf ("* server date: '%s' (%d), doc_date: '%s' (%d)\n", server_date, (int)srv_data, document_date, (int)doc_data); |
2301 | if (srv_data <= 0) { | 2417 | if (srv_data <= 0) { |
2302 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); | 2418 | char tmp[DEFAULT_BUFFER_SIZE]; |
2303 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2419 | |
2304 | } else if (doc_data <= 0) { | 2420 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); |
2305 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); | 2421 | strcpy(*msg, tmp); |
2306 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2422 | |
2307 | } else if (doc_data > srv_data + 30) { | 2423 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
2308 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); | 2424 | } else if (doc_data <= 0) { |
2309 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2425 | char tmp[DEFAULT_BUFFER_SIZE]; |
2310 | } else if (doc_data < srv_data - maximum_age) { | 2426 | |
2311 | int n = (srv_data - doc_data); | 2427 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); |
2312 | if (n > (60 * 60 * 24 * 2)) { | 2428 | strcpy(*msg, tmp); |
2313 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); | 2429 | |
2314 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2430 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
2315 | } else { | 2431 | } else if (doc_data > srv_data + 30) { |
2316 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); | 2432 | char tmp[DEFAULT_BUFFER_SIZE]; |
2317 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2433 | |
2318 | } | 2434 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); |
2319 | } | 2435 | strcpy(*msg, tmp); |
2320 | } | 2436 | |
2437 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2438 | } else if (doc_data < srv_data - maximum_age) { | ||
2439 | int n = (srv_data - doc_data); | ||
2440 | if (n > (60 * 60 * 24 * 2)) { | ||
2441 | char tmp[DEFAULT_BUFFER_SIZE]; | ||
2442 | |||
2443 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); | ||
2444 | strcpy(*msg, tmp); | ||
2445 | |||
2446 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2447 | } else { | ||
2448 | char tmp[DEFAULT_BUFFER_SIZE]; | ||
2449 | |||
2450 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); | ||
2451 | strcpy(*msg, tmp); | ||
2452 | |||
2453 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2454 | } | ||
2455 | } | ||
2456 | } | ||
2321 | 2457 | ||
2322 | if (server_date) free (server_date); | 2458 | if (server_date) free (server_date); |
2323 | if (document_date) free (document_date); | 2459 | if (document_date) free (document_date); |
@@ -2359,7 +2495,7 @@ get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_wri | |||
2359 | 2495 | ||
2360 | /* TODO: is there a better way in libcurl to check for the SSL library? */ | 2496 | /* TODO: is there a better way in libcurl to check for the SSL library? */ |
2361 | curlhelp_ssl_library | 2497 | curlhelp_ssl_library |
2362 | curlhelp_get_ssl_library (CURL* curl) | 2498 | curlhelp_get_ssl_library () |
2363 | { | 2499 | { |
2364 | curl_version_info_data* version_data; | 2500 | curl_version_info_data* version_data; |
2365 | char *ssl_version; | 2501 | char *ssl_version; |
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index ced13d0..c24ca24 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c | |||
@@ -141,21 +141,28 @@ main (int argc, char **argv) | |||
141 | if (verbose > 2) | 141 | if (verbose > 2) |
142 | printf ("Initializing DBI\n"); | 142 | printf ("Initializing DBI\n"); |
143 | 143 | ||
144 | if (dbi_initialize (NULL) < 0) { | 144 | dbi_inst *instance_p; |
145 | |||
146 | if (dbi_initialize_r(NULL, instance_p) < 0) { | ||
145 | printf ("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n"); | 147 | printf ("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n"); |
146 | return STATE_UNKNOWN; | 148 | return STATE_UNKNOWN; |
147 | } | 149 | } |
148 | 150 | ||
151 | if (instance_p == NULL) { | ||
152 | printf ("UNKNOWN - failed to initialize DBI.\n"); | ||
153 | return STATE_UNKNOWN; | ||
154 | } | ||
155 | |||
149 | if (verbose) | 156 | if (verbose) |
150 | printf ("Opening DBI driver '%s'\n", np_dbi_driver); | 157 | printf ("Opening DBI driver '%s'\n", np_dbi_driver); |
151 | 158 | ||
152 | driver = dbi_driver_open (np_dbi_driver); | 159 | driver = dbi_driver_open_r(np_dbi_driver, instance_p); |
153 | if (! driver) { | 160 | if (! driver) { |
154 | printf ("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n", | 161 | printf ("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n", |
155 | np_dbi_driver); | 162 | np_dbi_driver); |
156 | 163 | ||
157 | printf ("Known drivers:\n"); | 164 | printf ("Known drivers:\n"); |
158 | for (driver = dbi_driver_list (NULL); driver; driver = dbi_driver_list (driver)) { | 165 | for (driver = dbi_driver_list_r(NULL, instance_p); driver; driver = dbi_driver_list_r(driver, instance_p)) { |
159 | printf (" - %s\n", dbi_driver_get_name (driver)); | 166 | printf (" - %s\n", dbi_driver_get_name (driver)); |
160 | } | 167 | } |
161 | return STATE_UNKNOWN; | 168 | return STATE_UNKNOWN; |
@@ -426,6 +433,7 @@ process_arguments (int argc, char **argv) | |||
426 | else | 433 | else |
427 | timeout_interval = atoi (optarg); | 434 | timeout_interval = atoi (optarg); |
428 | 435 | ||
436 | break; | ||
429 | case 'H': /* host */ | 437 | case 'H': /* host */ |
430 | if (!is_host (optarg)) | 438 | if (!is_host (optarg)) |
431 | usage2 (_("Invalid hostname/address"), optarg); | 439 | usage2 (_("Invalid hostname/address"), optarg); |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index bd84c82..05e5502 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -131,9 +131,6 @@ bool stat_path (struct parameter_list *p); | |||
131 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); | 131 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); |
132 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); | 132 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); |
133 | 133 | ||
134 | double w_dfp = -1.0; | ||
135 | double c_dfp = -1.0; | ||
136 | char *path; | ||
137 | char *exclude_device; | 134 | char *exclude_device; |
138 | char *units; | 135 | char *units; |
139 | uintmax_t mult = 1024 * 1024; | 136 | uintmax_t mult = 1024 * 1024; |
@@ -587,7 +584,7 @@ process_arguments (int argc, char **argv) | |||
587 | 584 | ||
588 | /* Awful mistake where the range values do not make sense. Normally, | 585 | /* Awful mistake where the range values do not make sense. Normally, |
589 | you alert if the value is within the range, but since we are using | 586 | you alert if the value is within the range, but since we are using |
590 | freespace, we have to alert if outside the range. Thus we artifically | 587 | freespace, we have to alert if outside the range. Thus we artificially |
591 | force @ at the beginning of the range, so that it is backwards compatible | 588 | force @ at the beginning of the range, so that it is backwards compatible |
592 | */ | 589 | */ |
593 | case 'c': /* critical threshold */ | 590 | case 'c': /* critical threshold */ |
@@ -626,21 +623,36 @@ process_arguments (int argc, char **argv) | |||
626 | if (! strcasecmp (optarg, "bytes")) { | 623 | if (! strcasecmp (optarg, "bytes")) { |
627 | mult = (uintmax_t)1; | 624 | mult = (uintmax_t)1; |
628 | units = strdup ("B"); | 625 | units = strdup ("B"); |
629 | } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) { | 626 | } else if (!strcmp(optarg, "KiB")) { |
630 | mult = (uintmax_t)1024; | 627 | mult = (uintmax_t)1024; |
631 | units = strdup ("kiB"); | 628 | units = strdup ("KiB"); |
632 | } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) { | 629 | } else if (! strcmp (optarg, "kB")) { |
630 | mult = (uintmax_t)1000; | ||
631 | units = strdup ("kB"); | ||
632 | } else if (!strcmp(optarg, "MiB")) { | ||
633 | mult = (uintmax_t)1024 * 1024; | 633 | mult = (uintmax_t)1024 * 1024; |
634 | units = strdup ("MiB"); | 634 | units = strdup ("MiB"); |
635 | } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) { | 635 | } else if (! strcmp (optarg, "MB")) { |
636 | mult = (uintmax_t)1000 * 1000; | ||
637 | units = strdup ("MB"); | ||
638 | } else if (!strcmp(optarg, "GiB")) { | ||
636 | mult = (uintmax_t)1024 * 1024 * 1024; | 639 | mult = (uintmax_t)1024 * 1024 * 1024; |
637 | units = strdup ("GiB"); | 640 | units = strdup ("GiB"); |
638 | } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) { | 641 | } else if (! strcmp (optarg, "GB")){ |
642 | mult = (uintmax_t)1000 * 1000 * 1000; | ||
643 | units = strdup ("GB"); | ||
644 | } else if (!strcmp(optarg, "TiB")) { | ||
639 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; | 645 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; |
640 | units = strdup ("TiB"); | 646 | units = strdup ("TiB"); |
641 | } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) { | 647 | } else if (! strcmp (optarg, "TB")) { |
648 | mult = (uintmax_t)1000 * 1000 * 1000 * 1000; | ||
649 | units = strdup ("TB"); | ||
650 | } else if (!strcmp(optarg, "PiB")) { | ||
642 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; | 651 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; |
643 | units = strdup ("PiB"); | 652 | units = strdup ("PiB"); |
653 | } else if (! strcmp (optarg, "PB")){ | ||
654 | mult = (uintmax_t)1000 * 1000 * 1000 * 1000 * 1000; | ||
655 | units = strdup ("PB"); | ||
644 | } else { | 656 | } else { |
645 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); | 657 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); |
646 | } | 658 | } |
@@ -874,7 +886,7 @@ process_arguments (int argc, char **argv) | |||
874 | if (crit_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c])) | 886 | if (crit_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c])) |
875 | crit_usedspace_percent = argv[c++]; | 887 | crit_usedspace_percent = argv[c++]; |
876 | 888 | ||
877 | if (argc > c && path == NULL) { | 889 | if (argc > c) { |
878 | se = np_add_parameter(&path_select_list, strdup(argv[c++])); | 890 | se = np_add_parameter(&path_select_list, strdup(argv[c++])); |
879 | path_selected = TRUE; | 891 | path_selected = TRUE; |
880 | set_all_thresholds(se); | 892 | set_all_thresholds(se); |
@@ -1115,7 +1127,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1115 | p->available_to_root = fsp->fsu_bfree; | 1127 | p->available_to_root = fsp->fsu_bfree; |
1116 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; | 1128 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; |
1117 | if (freespace_ignore_reserved) { | 1129 | if (freespace_ignore_reserved) { |
1118 | /* option activated : we substract the root-reserved space from the total */ | 1130 | /* option activated : we subtract the root-reserved space from the total */ |
1119 | p->total = fsp->fsu_blocks - p->available_to_root + p->available; | 1131 | p->total = fsp->fsu_blocks - p->available_to_root + p->available; |
1120 | } else { | 1132 | } else { |
1121 | /* default behaviour : take all the blocks into account */ | 1133 | /* default behaviour : take all the blocks into account */ |
@@ -1130,7 +1142,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1130 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ | 1142 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ |
1131 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; | 1143 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; |
1132 | if (freespace_ignore_reserved) { | 1144 | if (freespace_ignore_reserved) { |
1133 | /* option activated : we substract the root-reserved inodes from the total */ | 1145 | /* option activated : we subtract the root-reserved inodes from the total */ |
1134 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ | 1146 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ |
1135 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ | 1147 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ |
1136 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; | 1148 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 9de6caf..7ffce98 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -75,7 +75,7 @@ main (int argc, char **argv) | |||
75 | { | 75 | { |
76 | char *command_line = NULL; | 76 | char *command_line = NULL; |
77 | char input_buffer[MAX_INPUT_BUFFER]; | 77 | char input_buffer[MAX_INPUT_BUFFER]; |
78 | char *address = NULL; /* comma seperated str with addrs/ptrs (sorted) */ | 78 | char *address = NULL; /* comma separated str with addrs/ptrs (sorted) */ |
79 | char **addresses = NULL; | 79 | char **addresses = NULL; |
80 | int n_addresses = 0; | 80 | int n_addresses = 0; |
81 | char *msg = NULL; | 81 | char *msg = NULL; |
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index db43316..23a9e99 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -73,7 +73,7 @@ int wrta_p = FALSE; | |||
73 | int | 73 | int |
74 | main (int argc, char **argv) | 74 | main (int argc, char **argv) |
75 | { | 75 | { |
76 | /* normaly should be int result = STATE_UNKNOWN; */ | 76 | /* normally should be int result = STATE_UNKNOWN; */ |
77 | 77 | ||
78 | int status = STATE_UNKNOWN; | 78 | int status = STATE_UNKNOWN; |
79 | int result = 0; | 79 | int result = 0; |
@@ -354,6 +354,7 @@ process_arguments (int argc, char **argv) | |||
354 | break; | 354 | break; |
355 | case 'I': /* sourceip */ | 355 | case 'I': /* sourceip */ |
356 | sourceif = strscpy (sourceif, optarg); | 356 | sourceif = strscpy (sourceif, optarg); |
357 | break; | ||
357 | case '4': /* IPv4 only */ | 358 | case '4': /* IPv4 only */ |
358 | address_family = AF_INET; | 359 | address_family = AF_INET; |
359 | break; | 360 | break; |
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index c4b4417..c34bb08 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -353,6 +353,7 @@ process_arguments (int argc, char **argv) | |||
353 | usage2 (_("Port must be a positive short integer"), optarg); | 353 | usage2 (_("Port must be a positive short integer"), optarg); |
354 | else | 354 | else |
355 | port = atoi(optarg); | 355 | port = atoi(optarg); |
356 | break; | ||
356 | case 'D': /* disable paper out check*/ | 357 | case 'D': /* disable paper out check*/ |
357 | check_paper_out = 0; | 358 | check_paper_out = 0; |
358 | break; | 359 | break; |
diff --git a/plugins/check_http.c b/plugins/check_http.c index 8dda046..718c8ee 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -198,7 +198,7 @@ test_file (char *path) | |||
198 | 198 | ||
199 | /* | 199 | /* |
200 | * process command-line arguments | 200 | * process command-line arguments |
201 | * returns true on succes, false otherwise | 201 | * returns true on success, false otherwise |
202 | */ | 202 | */ |
203 | bool process_arguments (int argc, char **argv) | 203 | bool process_arguments (int argc, char **argv) |
204 | { | 204 | { |
@@ -498,6 +498,7 @@ bool process_arguments (int argc, char **argv) | |||
498 | break; | 498 | break; |
499 | case 'R': /* regex */ | 499 | case 'R': /* regex */ |
500 | cflags |= REG_ICASE; | 500 | cflags |= REG_ICASE; |
501 | // fall through | ||
501 | case 'r': /* regex */ | 502 | case 'r': /* regex */ |
502 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); | 503 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); |
503 | regexp[MAX_RE_SIZE - 1] = 0; | 504 | regexp[MAX_RE_SIZE - 1] = 0; |
@@ -1278,7 +1279,7 @@ check_http (void) | |||
1278 | 1279 | ||
1279 | regmatch_t chre_pmatch[1]; // We actually do not care about this, since we only want to know IF it was found | 1280 | regmatch_t chre_pmatch[1]; // We actually do not care about this, since we only want to know IF it was found |
1280 | 1281 | ||
1281 | if (regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) { | 1282 | if (!no_body && regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) { |
1282 | if (verbose) { | 1283 | if (verbose) { |
1283 | printf("Found chunked content\n"); | 1284 | printf("Found chunked content\n"); |
1284 | } | 1285 | } |
@@ -1391,7 +1392,6 @@ char *unchunk_content(const char *content) { | |||
1391 | // https://en.wikipedia.org/wiki/Chunked_transfer_encoding | 1392 | // https://en.wikipedia.org/wiki/Chunked_transfer_encoding |
1392 | // https://www.rfc-editor.org/rfc/rfc7230#section-4.1 | 1393 | // https://www.rfc-editor.org/rfc/rfc7230#section-4.1 |
1393 | char *result = NULL; | 1394 | char *result = NULL; |
1394 | size_t content_length = strlen(content); | ||
1395 | char *start_of_chunk; | 1395 | char *start_of_chunk; |
1396 | char* end_of_chunk; | 1396 | char* end_of_chunk; |
1397 | long size_of_chunk; | 1397 | long size_of_chunk; |
@@ -1885,7 +1885,7 @@ print_usage (void) | |||
1885 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); | 1885 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); |
1886 | printf (" [-J <client certificate file>] [-K <private key>]\n"); | 1886 | printf (" [-J <client certificate file>] [-K <private key>]\n"); |
1887 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); | 1887 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); |
1888 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); | 1888 | printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport>]\n"); |
1889 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 1889 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
1890 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 1890 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
1891 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); | 1891 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 845a4f5..a1bfe1b 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
@@ -222,7 +222,7 @@ main (int argc, char *argv[]) | |||
222 | /* reset the alarm handler */ | 222 | /* reset the alarm handler */ |
223 | alarm (0); | 223 | alarm (0); |
224 | 224 | ||
225 | /* calcutate the elapsed time and compare to thresholds */ | 225 | /* calculate the elapsed time and compare to thresholds */ |
226 | 226 | ||
227 | microsec = deltime (tv); | 227 | microsec = deltime (tv); |
228 | elapsed_time = (double)microsec / 1.0e6; | 228 | elapsed_time = (double)microsec / 1.0e6; |
diff --git a/plugins/check_load.c b/plugins/check_load.c index 00f7c87..313df8a 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -107,7 +107,7 @@ main (int argc, char **argv) | |||
107 | int i; | 107 | int i; |
108 | long numcpus; | 108 | long numcpus; |
109 | 109 | ||
110 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */ | 110 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */ |
111 | #ifndef HAVE_GETLOADAVG | 111 | #ifndef HAVE_GETLOADAVG |
112 | char input_buffer[MAX_INPUT_BUFFER]; | 112 | char input_buffer[MAX_INPUT_BUFFER]; |
113 | # ifdef HAVE_PROC_LOADAVG | 113 | # ifdef HAVE_PROC_LOADAVG |
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 0cba50e..7d85554 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -34,7 +34,7 @@ const char *progname = "check_mysql"; | |||
34 | const char *copyright = "1999-2011"; | 34 | const char *copyright = "1999-2011"; |
35 | const char *email = "devel@monitoring-plugins.org"; | 35 | const char *email = "devel@monitoring-plugins.org"; |
36 | 36 | ||
37 | #define SLAVERESULTSIZE 70 | 37 | #define SLAVERESULTSIZE 96 |
38 | 38 | ||
39 | #include "common.h" | 39 | #include "common.h" |
40 | #include "utils.h" | 40 | #include "utils.h" |
@@ -89,6 +89,8 @@ static const char *metric_counter[LENGTH_METRIC_COUNTER] = { | |||
89 | "Uptime" | 89 | "Uptime" |
90 | }; | 90 | }; |
91 | 91 | ||
92 | #define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'" | ||
93 | |||
92 | thresholds *my_threshold = NULL; | 94 | thresholds *my_threshold = NULL; |
93 | 95 | ||
94 | int process_arguments (int, char **); | 96 | int process_arguments (int, char **); |
@@ -108,7 +110,7 @@ main (int argc, char **argv) | |||
108 | 110 | ||
109 | char *result = NULL; | 111 | char *result = NULL; |
110 | char *error = NULL; | 112 | char *error = NULL; |
111 | char slaveresult[SLAVERESULTSIZE]; | 113 | char slaveresult[SLAVERESULTSIZE] = { 0 }; |
112 | char* perf; | 114 | char* perf; |
113 | 115 | ||
114 | perf = strdup (""); | 116 | perf = strdup (""); |
@@ -138,7 +140,10 @@ main (int argc, char **argv) | |||
138 | mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers); | 140 | mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers); |
139 | /* establish a connection to the server and error checking */ | 141 | /* establish a connection to the server and error checking */ |
140 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { | 142 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { |
141 | if (ignore_auth && mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR) | 143 | /* Depending on internally-selected auth plugin MySQL might return */ |
144 | /* ER_ACCESS_DENIED_NO_PASSWORD_ERROR or ER_ACCESS_DENIED_ERROR. */ | ||
145 | /* Semantically these errors are the same. */ | ||
146 | if (ignore_auth && (mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR || mysql_errno (&mysql) == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)) | ||
142 | { | 147 | { |
143 | printf("MySQL OK - Version: %s (protocol %d)\n", | 148 | printf("MySQL OK - Version: %s (protocol %d)\n", |
144 | mysql_get_server_info(&mysql), | 149 | mysql_get_server_info(&mysql), |
@@ -275,11 +280,30 @@ main (int argc, char **argv) | |||
275 | /* Save slave status in slaveresult */ | 280 | /* Save slave status in slaveresult */ |
276 | snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown"); | 281 | snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown"); |
277 | 282 | ||
278 | /* Raise critical error if SQL THREAD or IO THREAD are stopped */ | 283 | /* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no mysqldump threads running */ |
279 | if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { | 284 | if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { |
280 | mysql_free_result (res); | 285 | MYSQL_RES *res_mysqldump; |
281 | mysql_close (&mysql); | 286 | MYSQL_ROW row_mysqldump; |
282 | die (STATE_CRITICAL, "%s\n", slaveresult); | 287 | unsigned int mysqldump_threads = 0; |
288 | |||
289 | if (mysql_query (&mysql, MYSQLDUMP_THREADS_QUERY) == 0) { | ||
290 | /* store the result */ | ||
291 | if ( (res_mysqldump = mysql_store_result (&mysql)) != NULL) { | ||
292 | if (mysql_num_rows(res_mysqldump) == 1) { | ||
293 | if ( (row_mysqldump = mysql_fetch_row (res_mysqldump)) != NULL) { | ||
294 | mysqldump_threads = atoi(row_mysqldump[0]); | ||
295 | } | ||
296 | } | ||
297 | /* free the result */ | ||
298 | mysql_free_result (res_mysqldump); | ||
299 | } | ||
300 | mysql_close (&mysql); | ||
301 | } | ||
302 | if (mysqldump_threads == 0) { | ||
303 | die (STATE_CRITICAL, "%s\n", slaveresult); | ||
304 | } else { | ||
305 | strncat(slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE-1); | ||
306 | } | ||
283 | } | 307 | } |
284 | 308 | ||
285 | if (verbose >=3) { | 309 | if (verbose >=3) { |
@@ -291,7 +315,7 @@ main (int argc, char **argv) | |||
291 | } | 315 | } |
292 | 316 | ||
293 | /* Check Seconds Behind against threshold */ | 317 | /* Check Seconds Behind against threshold */ |
294 | if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) { | 318 | if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL && strcmp (row[seconds_behind_field], "NULL") != 0)) { |
295 | double value = atof(row[seconds_behind_field]); | 319 | double value = atof(row[seconds_behind_field]); |
296 | int status; | 320 | int status; |
297 | 321 | ||
@@ -551,7 +575,7 @@ print_help (void) | |||
551 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); | 575 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); |
552 | printf (" %s\n", _("behind master")); | 576 | printf (" %s\n", _("behind master")); |
553 | printf (" %s\n", "-l, --ssl"); | 577 | printf (" %s\n", "-l, --ssl"); |
554 | printf (" %s\n", _("Use ssl encryptation")); | 578 | printf (" %s\n", _("Use ssl encryption")); |
555 | printf (" %s\n", "-C, --ca-cert=STRING"); | 579 | printf (" %s\n", "-C, --ca-cert=STRING"); |
556 | printf (" %s\n", _("Path to CA signing the cert")); | 580 | printf (" %s\n", _("Path to CA signing the cert")); |
557 | printf (" %s\n", "-a, --cert=STRING"); | 581 | printf (" %s\n", "-a, --cert=STRING"); |
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 59c135d..d73d83c 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -341,7 +341,7 @@ int main(int argc, char **argv){ | |||
341 | 341 | ||
342 | 2) If the counter you're going to measure is percent-based, the code will detect | 342 | 2) If the counter you're going to measure is percent-based, the code will detect |
343 | the percent sign in its name and will attribute minimum (0%) and maximum (100%) | 343 | the percent sign in its name and will attribute minimum (0%) and maximum (100%) |
344 | values automagically, as well the ¨%" sign to graph units. | 344 | values automagically, as well the "%" sign to graph units. |
345 | 345 | ||
346 | 3) OTOH, if the counter is "absolute", you'll have to provide the following | 346 | 3) OTOH, if the counter is "absolute", you'll have to provide the following |
347 | the counter unit - that is, the dimensions of the counter you're getting. Examples: | 347 | the counter unit - that is, the dimensions of the counter you're getting. Examples: |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 8b776ba..3614650 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * | 10 | * |
11 | * This file contains the check_ntp plugin | 11 | * This file contains the check_ntp plugin |
12 | * | 12 | * |
13 | * This plugin to check ntp servers independant of any commandline | 13 | * This plugin to check ntp servers independent of any commandline |
14 | * programs or external libraries. | 14 | * programs or external libraries. |
15 | * | 15 | * |
16 | * | 16 | * |
@@ -79,7 +79,7 @@ typedef struct { | |||
79 | /* this structure holds data about results from querying offset from a peer */ | 79 | /* this structure holds data about results from querying offset from a peer */ |
80 | typedef struct { | 80 | typedef struct { |
81 | time_t waiting; /* ts set when we started waiting for a response */ | 81 | time_t waiting; /* ts set when we started waiting for a response */ |
82 | int num_responses; /* number of successfully recieved responses */ | 82 | int num_responses; /* number of successfully received responses */ |
83 | uint8_t stratum; /* copied verbatim from the ntp_message */ | 83 | uint8_t stratum; /* copied verbatim from the ntp_message */ |
84 | double rtdelay; /* converted from the ntp_message */ | 84 | double rtdelay; /* converted from the ntp_message */ |
85 | double rtdisp; /* converted from the ntp_message */ | 85 | double rtdisp; /* converted from the ntp_message */ |
@@ -100,7 +100,7 @@ typedef struct { | |||
100 | /* NB: not necessarily NULL terminated! */ | 100 | /* NB: not necessarily NULL terminated! */ |
101 | } ntp_control_message; | 101 | } ntp_control_message; |
102 | 102 | ||
103 | /* this is an association/status-word pair found in control packet reponses */ | 103 | /* this is an association/status-word pair found in control packet responses */ |
104 | typedef struct { | 104 | typedef struct { |
105 | uint16_t assoc; | 105 | uint16_t assoc; |
106 | uint16_t status; | 106 | uint16_t status; |
@@ -575,7 +575,7 @@ double jitter_request(int *status){ | |||
575 | } | 575 | } |
576 | } | 576 | } |
577 | } | 577 | } |
578 | if(verbose) printf("%d candiate peers available\n", num_candidates); | 578 | if(verbose) printf("%d candidate peers available\n", num_candidates); |
579 | if(verbose && syncsource_found) printf("synchronization source found\n"); | 579 | if(verbose && syncsource_found) printf("synchronization source found\n"); |
580 | if(! syncsource_found){ | 580 | if(! syncsource_found){ |
581 | *status = STATE_UNKNOWN; | 581 | *status = STATE_UNKNOWN; |
@@ -597,7 +597,7 @@ double jitter_request(int *status){ | |||
597 | /* By spec, putting the variable name "jitter" in the request | 597 | /* By spec, putting the variable name "jitter" in the request |
598 | * should cause the server to provide _only_ the jitter value. | 598 | * should cause the server to provide _only_ the jitter value. |
599 | * thus reducing net traffic, guaranteeing us only a single | 599 | * thus reducing net traffic, guaranteeing us only a single |
600 | * datagram in reply, and making intepretation much simpler | 600 | * datagram in reply, and making interpretation much simpler |
601 | */ | 601 | */ |
602 | /* Older servers doesn't know what jitter is, so if we get an | 602 | /* Older servers doesn't know what jitter is, so if we get an |
603 | * error on the first pass we redo it with "dispersion" */ | 603 | * error on the first pass we redo it with "dispersion" */ |
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index 6842842..49cb100 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
@@ -86,7 +86,7 @@ typedef struct { | |||
86 | /* NB: not necessarily NULL terminated! */ | 86 | /* NB: not necessarily NULL terminated! */ |
87 | } ntp_control_message; | 87 | } ntp_control_message; |
88 | 88 | ||
89 | /* this is an association/status-word pair found in control packet reponses */ | 89 | /* this is an association/status-word pair found in control packet responses */ |
90 | typedef struct { | 90 | typedef struct { |
91 | uint16_t assoc; | 91 | uint16_t assoc; |
92 | uint16_t status; | 92 | uint16_t status; |
@@ -189,7 +189,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | |||
189 | } | 189 | } |
190 | 190 | ||
191 | /* This function does all the actual work; roughly here's what it does | 191 | /* This function does all the actual work; roughly here's what it does |
192 | * beside setting the offest, jitter and stratum passed as argument: | 192 | * beside setting the offset, jitter and stratum passed as argument: |
193 | * - offset can be negative, so if it cannot get the offset, offset_result | 193 | * - offset can be negative, so if it cannot get the offset, offset_result |
194 | * is set to UNKNOWN, otherwise OK. | 194 | * is set to UNKNOWN, otherwise OK. |
195 | * - jitter and stratum are set to -1 if they cannot be retrieved so any | 195 | * - jitter and stratum are set to -1 if they cannot be retrieved so any |
@@ -199,7 +199,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | |||
199 | * status is pretty much useless as syncsource_found is a global variable | 199 | * status is pretty much useless as syncsource_found is a global variable |
200 | * used later in main to check is the server was synchronized. It works | 200 | * used later in main to check is the server was synchronized. It works |
201 | * so I left it alone */ | 201 | * so I left it alone */ |
202 | int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum, int *num_truechimers){ | 202 | int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum, int *num_truechimers){ |
203 | int conn=-1, i, npeers=0, num_candidates=0; | 203 | int conn=-1, i, npeers=0, num_candidates=0; |
204 | double tmp_offset = 0; | 204 | double tmp_offset = 0; |
205 | int min_peer_sel=PEER_INCLUDED; | 205 | int min_peer_sel=PEER_INCLUDED; |
@@ -306,7 +306,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
306 | /* Putting the wanted variable names in the request | 306 | /* Putting the wanted variable names in the request |
307 | * cause the server to provide _only_ the requested values. | 307 | * cause the server to provide _only_ the requested values. |
308 | * thus reducing net traffic, guaranteeing us only a single | 308 | * thus reducing net traffic, guaranteeing us only a single |
309 | * datagram in reply, and making intepretation much simpler | 309 | * datagram in reply, and making interpretation much simpler |
310 | */ | 310 | */ |
311 | /* Older servers doesn't know what jitter is, so if we get an | 311 | /* Older servers doesn't know what jitter is, so if we get an |
312 | * error on the first pass we redo it with "dispersion" */ | 312 | * error on the first pass we redo it with "dispersion" */ |
@@ -585,8 +585,8 @@ int main(int argc, char *argv[]){ | |||
585 | /* set socket timeout */ | 585 | /* set socket timeout */ |
586 | alarm (socket_timeout); | 586 | alarm (socket_timeout); |
587 | 587 | ||
588 | /* This returns either OK or WARNING (See comment preceeding ntp_request) */ | 588 | /* This returns either OK or WARNING (See comment preceding ntp_request) */ |
589 | result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &num_truechimers); | 589 | result = ntp_request(&offset, &offset_result, &jitter, &stratum, &num_truechimers); |
590 | 590 | ||
591 | if(offset_result == STATE_UNKNOWN) { | 591 | if(offset_result == STATE_UNKNOWN) { |
592 | /* if there's no sync peer (this overrides ntp_request output): */ | 592 | /* if there's no sync peer (this overrides ntp_request output): */ |
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 391b2df..46cc604 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
@@ -81,7 +81,7 @@ typedef struct { | |||
81 | /* this structure holds data about results from querying offset from a peer */ | 81 | /* this structure holds data about results from querying offset from a peer */ |
82 | typedef struct { | 82 | typedef struct { |
83 | time_t waiting; /* ts set when we started waiting for a response */ | 83 | time_t waiting; /* ts set when we started waiting for a response */ |
84 | int num_responses; /* number of successfully recieved responses */ | 84 | int num_responses; /* number of successfully received responses */ |
85 | uint8_t stratum; /* copied verbatim from the ntp_message */ | 85 | uint8_t stratum; /* copied verbatim from the ntp_message */ |
86 | double rtdelay; /* converted from the ntp_message */ | 86 | double rtdelay; /* converted from the ntp_message */ |
87 | double rtdisp; /* converted from the ntp_message */ | 87 | double rtdisp; /* converted from the ntp_message */ |
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index e7e8de0..3c9d23e 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c | |||
@@ -1668,7 +1668,7 @@ void print_help(void) | |||
1668 | 1668 | ||
1669 | printf ("\n"); | 1669 | printf ("\n"); |
1670 | printf ("%s\n", _("Notes:")); | 1670 | printf ("%s\n", _("Notes:")); |
1671 | printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG")); | 1671 | printf (" %s\n", _("- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG")); |
1672 | printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check.")); | 1672 | printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check.")); |
1673 | printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)")); | 1673 | printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)")); |
1674 | printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds")); | 1674 | printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds")); |
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index c26cd43..6199033 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -93,7 +93,7 @@ int verbose = 0; | |||
93 | 93 | ||
94 | /****************************************************************************** | 94 | /****************************************************************************** |
95 | 95 | ||
96 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | 96 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ |
97 | tags in the comments. With in the tags, the XML is assembled sequentially. | 97 | tags in the comments. With in the tags, the XML is assembled sequentially. |
98 | You can define entities in tags. You also have all the #defines available as | 98 | You can define entities in tags. You also have all the #defines available as |
99 | entities. | 99 | entities. |
@@ -517,7 +517,10 @@ print_help (void) | |||
517 | printf (" %s\n", _("connecting to the server. The result from the query has to be numeric.")); | 517 | printf (" %s\n", _("connecting to the server. The result from the query has to be numeric.")); |
518 | printf (" %s\n", _("Multiple SQL commands, separated by semicolon, are allowed but the result ")); | 518 | printf (" %s\n", _("Multiple SQL commands, separated by semicolon, are allowed but the result ")); |
519 | printf (" %s\n", _("of the last command is taken into account only. The value of the first")); | 519 | printf (" %s\n", _("of the last command is taken into account only. The value of the first")); |
520 | printf (" %s\n\n", _("column in the first row is used as the check result.")); | 520 | printf (" %s\n", _("column in the first row is used as the check result. If a second column is")); |
521 | printf (" %s\n", _("present in the result set, this is added to the plugin output with a")); | ||
522 | printf (" %s\n", _("prefix of \"Extra Info:\". This information can be displayed in the system")); | ||
523 | printf (" %s\n\n", _("executing the plugin.")); | ||
521 | 524 | ||
522 | printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual")); | 525 | printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual")); |
523 | printf (" %s\n\n", _("for details about how to access internal statistics of the database server.")); | 526 | printf (" %s\n\n", _("for details about how to access internal statistics of the database server.")); |
@@ -557,6 +560,7 @@ do_query (PGconn *conn, char *query) | |||
557 | PGresult *res; | 560 | PGresult *res; |
558 | 561 | ||
559 | char *val_str; | 562 | char *val_str; |
563 | char *extra_info; | ||
560 | double value; | 564 | double value; |
561 | 565 | ||
562 | char *endptr = NULL; | 566 | char *endptr = NULL; |
@@ -621,6 +625,12 @@ do_query (PGconn *conn, char *query) | |||
621 | printf ("|query=%f;%s;%s;;\n", value, | 625 | printf ("|query=%f;%s;%s;;\n", value, |
622 | query_warning ? query_warning : "", | 626 | query_warning ? query_warning : "", |
623 | query_critical ? query_critical : ""); | 627 | query_critical ? query_critical : ""); |
628 | if (PQnfields (res) > 1) { | ||
629 | extra_info = PQgetvalue (res, 0, 1); | ||
630 | if (extra_info != NULL) { | ||
631 | printf ("Extra Info: %s\n", extra_info); | ||
632 | } | ||
633 | } | ||
624 | return my_status; | 634 | return my_status; |
625 | } | 635 | } |
626 | 636 | ||
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index a025ee8..c17c699 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -70,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */ | |||
70 | #define PCPU 256 | 70 | #define PCPU 256 |
71 | #define ELAPSED 512 | 71 | #define ELAPSED 512 |
72 | #define EREG_ARGS 1024 | 72 | #define EREG_ARGS 1024 |
73 | #define EXCLUDE_PROGS 2048 | ||
73 | 74 | ||
74 | #define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads: | 75 | #define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads: |
75 | ppid of procs are compared to pid of this proc*/ | 76 | ppid of procs are compared to pid of this proc*/ |
@@ -93,6 +94,9 @@ int rss; | |||
93 | float pcpu; | 94 | float pcpu; |
94 | char *statopts; | 95 | char *statopts; |
95 | char *prog; | 96 | char *prog; |
97 | char *exclude_progs; | ||
98 | char **exclude_progs_arr = NULL; | ||
99 | char exclude_progs_counter = 0; | ||
96 | char *args; | 100 | char *args; |
97 | char *input_filename = NULL; | 101 | char *input_filename = NULL; |
98 | regex_t re_args; | 102 | regex_t re_args; |
@@ -250,7 +254,26 @@ main (int argc, char **argv) | |||
250 | continue; | 254 | continue; |
251 | } | 255 | } |
252 | 256 | ||
253 | /* filter kernel threads (childs of KTHREAD_PARENT)*/ | 257 | /* Ignore excluded processes by name */ |
258 | if(options & EXCLUDE_PROGS) { | ||
259 | int found = 0; | ||
260 | int i = 0; | ||
261 | |||
262 | for(i=0; i < (exclude_progs_counter); i++) { | ||
263 | if(!strcmp(procprog, exclude_progs_arr[i])) { | ||
264 | found = 1; | ||
265 | } | ||
266 | } | ||
267 | if(found == 0) { | ||
268 | resultsum |= EXCLUDE_PROGS; | ||
269 | } else | ||
270 | { | ||
271 | if(verbose >= 3) | ||
272 | printf("excluding - by ignorelist\n"); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | /* filter kernel threads (children of KTHREAD_PARENT)*/ | ||
254 | /* TODO adapt for other OSes than GNU/Linux | 277 | /* TODO adapt for other OSes than GNU/Linux |
255 | sorry for not doing that, but I've no other OSes to test :-( */ | 278 | sorry for not doing that, but I've no other OSes to test :-( */ |
256 | if (kthread_filter == 1) { | 279 | if (kthread_filter == 1) { |
@@ -409,6 +432,7 @@ process_arguments (int argc, char **argv) | |||
409 | {"input-file", required_argument, 0, CHAR_MAX+2}, | 432 | {"input-file", required_argument, 0, CHAR_MAX+2}, |
410 | {"no-kthreads", required_argument, 0, 'k'}, | 433 | {"no-kthreads", required_argument, 0, 'k'}, |
411 | {"traditional-filter", no_argument, 0, 'T'}, | 434 | {"traditional-filter", no_argument, 0, 'T'}, |
435 | {"exclude-process", required_argument, 0, 'X'}, | ||
412 | {0, 0, 0, 0} | 436 | {0, 0, 0, 0} |
413 | }; | 437 | }; |
414 | 438 | ||
@@ -417,7 +441,7 @@ process_arguments (int argc, char **argv) | |||
417 | strcpy (argv[c], "-t"); | 441 | strcpy (argv[c], "-t"); |
418 | 442 | ||
419 | while (1) { | 443 | while (1) { |
420 | c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T", | 444 | c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:", |
421 | longopts, &option); | 445 | longopts, &option); |
422 | 446 | ||
423 | if (c == -1 || c == EOF) | 447 | if (c == -1 || c == EOF) |
@@ -490,6 +514,23 @@ process_arguments (int argc, char **argv) | |||
490 | prog); | 514 | prog); |
491 | options |= PROG; | 515 | options |= PROG; |
492 | break; | 516 | break; |
517 | case 'X': | ||
518 | if(exclude_progs) | ||
519 | break; | ||
520 | else | ||
521 | exclude_progs = optarg; | ||
522 | xasprintf (&fmt, _("%s%sexclude progs '%s'"), (fmt ? fmt : ""), (options ? ", " : ""), | ||
523 | exclude_progs); | ||
524 | char *p = strtok(exclude_progs, ","); | ||
525 | |||
526 | while(p){ | ||
527 | exclude_progs_arr = realloc(exclude_progs_arr, sizeof(char*) * ++exclude_progs_counter); | ||
528 | exclude_progs_arr[exclude_progs_counter-1] = p; | ||
529 | p = strtok(NULL, ","); | ||
530 | } | ||
531 | |||
532 | options |= EXCLUDE_PROGS; | ||
533 | break; | ||
493 | case 'a': /* args (full path name with args) */ | 534 | case 'a': /* args (full path name with args) */ |
494 | /* TODO: allow this to be passed in with --metric */ | 535 | /* TODO: allow this to be passed in with --metric */ |
495 | if (args) | 536 | if (args) |
@@ -745,6 +786,8 @@ print_help (void) | |||
745 | printf (" %s\n", _("Only scan for processes with args that contain the regex STRING.")); | 786 | printf (" %s\n", _("Only scan for processes with args that contain the regex STRING.")); |
746 | printf (" %s\n", "-C, --command=COMMAND"); | 787 | printf (" %s\n", "-C, --command=COMMAND"); |
747 | printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); | 788 | printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); |
789 | printf (" %s\n", "-X, --exclude-process"); | ||
790 | printf (" %s\n", _("Exclude processes which match this comma separated list")); | ||
748 | printf (" %s\n", "-k, --no-kthreads"); | 791 | printf (" %s\n", "-k, --no-kthreads"); |
749 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); | 792 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); |
750 | 793 | ||
@@ -786,5 +829,5 @@ print_usage (void) | |||
786 | printf ("%s\n", _("Usage:")); | 829 | printf ("%s\n", _("Usage:")); |
787 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); | 830 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); |
788 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); | 831 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); |
789 | printf (" [-C command] [-k] [-t timeout] [-v]\n"); | 832 | printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n"); |
790 | } | 833 | } |
diff --git a/plugins/check_radius.c b/plugins/check_radius.c index be1001b..b1b4938 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
@@ -97,7 +97,7 @@ int verbose = FALSE; | |||
97 | 97 | ||
98 | /****************************************************************************** | 98 | /****************************************************************************** |
99 | 99 | ||
100 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | 100 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ |
101 | tags in the comments. With in the tags, the XML is assembled sequentially. | 101 | tags in the comments. With in the tags, the XML is assembled sequentially. |
102 | You can define entities in tags. You also have all the #defines available as | 102 | You can define entities in tags. You also have all the #defines available as |
103 | entities. | 103 | entities. |
@@ -155,7 +155,11 @@ main (int argc, char **argv) | |||
155 | { | 155 | { |
156 | struct sockaddr_storage ss; | 156 | struct sockaddr_storage ss; |
157 | char name[HOST_NAME_MAX]; | 157 | char name[HOST_NAME_MAX]; |
158 | #ifdef RC_BUFFER_LEN | ||
159 | char msg[RC_BUFFER_LEN]; | ||
160 | #else | ||
158 | char msg[BUFFER_LEN]; | 161 | char msg[BUFFER_LEN]; |
162 | #endif | ||
159 | SEND_DATA data; | 163 | SEND_DATA data; |
160 | int result = STATE_UNKNOWN; | 164 | int result = STATE_UNKNOWN; |
161 | uint32_t client_id, service; | 165 | uint32_t client_id, service; |
@@ -377,7 +381,7 @@ print_help (void) | |||
377 | printf ("\n"); | 381 | printf ("\n"); |
378 | printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections.")); | 382 | printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections.")); |
379 | printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user")); | 383 | printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user")); |
380 | printf ("%s\n", _("name and password. A configuration file may also be present. The format of")); | 384 | printf ("%s\n", _("name and password. A configuration file must be present. The format of")); |
381 | printf ("%s\n", _("the configuration file is described in the radiusclient library sources.")); | 385 | printf ("%s\n", _("the configuration file is described in the radiusclient library sources.")); |
382 | printf ("%s\n", _("The password option presents a substantial security issue because the")); | 386 | printf ("%s\n", _("The password option presents a substantial security issue because the")); |
383 | printf ("%s\n", _("password can possibly be determined by careful watching of the command line")); | 387 | printf ("%s\n", _("password can possibly be determined by careful watching of the command line")); |
diff --git a/plugins/check_real.c b/plugins/check_real.c index 0f1a1ba..fbdb70f 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
@@ -178,7 +178,7 @@ main (int argc, char **argv) | |||
178 | 178 | ||
179 | /* watch for the REAL connection string */ | 179 | /* watch for the REAL connection string */ |
180 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | 180 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); |
181 | buffer[result] = '\0'; /* null terminate recieved buffer */ | 181 | buffer[result] = '\0'; /* null terminate received buffer */ |
182 | 182 | ||
183 | /* return a CRITICAL status if we couldn't read any data */ | 183 | /* return a CRITICAL status if we couldn't read any data */ |
184 | if (result == -1) { | 184 | if (result == -1) { |
@@ -436,7 +436,7 @@ print_help (void) | |||
436 | 436 | ||
437 | printf ("\n"); | 437 | printf ("\n"); |
438 | printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); | 438 | printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); |
439 | printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); | 439 | printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); |
440 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); | 440 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); |
441 | printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); | 441 | printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); |
442 | printf ("%s\n", _("values.")); | 442 | printf ("%s\n", _("values.")); |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index c1e92df..fc0ae2c 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Monitoring check_smtp plugin | 3 | * Monitoring check_smtp plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2023 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
@@ -42,16 +42,18 @@ const char *email = "devel@monitoring-plugins.org"; | |||
42 | #ifdef HAVE_SSL | 42 | #ifdef HAVE_SSL |
43 | int check_cert = FALSE; | 43 | int check_cert = FALSE; |
44 | int days_till_exp_warn, days_till_exp_crit; | 44 | int days_till_exp_warn, days_till_exp_crit; |
45 | # define my_recv(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) | 45 | # define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) |
46 | # define my_send(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) | 46 | # define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) |
47 | #else /* ifndef HAVE_SSL */ | 47 | #else /* ifndef HAVE_SSL */ |
48 | # define my_recv(buf, len) read(sd, buf, len) | 48 | # define my_recv(buf, len) read(sd, buf, len) |
49 | # define my_send(buf, len) send(sd, buf, len, 0) | 49 | # define my_send(buf, len) send(sd, buf, len, 0) |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | enum { | 52 | enum { |
53 | SMTP_PORT = 25 | 53 | SMTP_PORT = 25, |
54 | SMTPS_PORT = 465 | ||
54 | }; | 55 | }; |
56 | #define PROXY_PREFIX "PROXY TCP4 0.0.0.0 0.0.0.0 25 25\r\n" | ||
55 | #define SMTP_EXPECT "220" | 57 | #define SMTP_EXPECT "220" |
56 | #define SMTP_HELO "HELO " | 58 | #define SMTP_HELO "HELO " |
57 | #define SMTP_EHLO "EHLO " | 59 | #define SMTP_EHLO "EHLO " |
@@ -82,6 +84,7 @@ int eflags = 0; | |||
82 | int errcode, excode; | 84 | int errcode, excode; |
83 | 85 | ||
84 | int server_port = SMTP_PORT; | 86 | int server_port = SMTP_PORT; |
87 | int server_port_option = 0; | ||
85 | char *server_address = NULL; | 88 | char *server_address = NULL; |
86 | char *server_expect = NULL; | 89 | char *server_expect = NULL; |
87 | char *mail_command = NULL; | 90 | char *mail_command = NULL; |
@@ -102,6 +105,9 @@ double critical_time = 0; | |||
102 | int check_critical_time = FALSE; | 105 | int check_critical_time = FALSE; |
103 | int verbose = 0; | 106 | int verbose = 0; |
104 | int use_ssl = FALSE; | 107 | int use_ssl = FALSE; |
108 | int use_starttls = FALSE; | ||
109 | int use_sni = FALSE; | ||
110 | short use_proxy_prefix = FALSE; | ||
105 | short use_ehlo = FALSE; | 111 | short use_ehlo = FALSE; |
106 | short use_lhlo = FALSE; | 112 | short use_lhlo = FALSE; |
107 | short ssl_established = 0; | 113 | short ssl_established = 0; |
@@ -183,6 +189,26 @@ main (int argc, char **argv) | |||
183 | result = my_tcp_connect (server_address, server_port, &sd); | 189 | result = my_tcp_connect (server_address, server_port, &sd); |
184 | 190 | ||
185 | if (result == STATE_OK) { /* we connected */ | 191 | if (result == STATE_OK) { /* we connected */ |
192 | /* If requested, send PROXY header */ | ||
193 | if (use_proxy_prefix) { | ||
194 | if (verbose) | ||
195 | printf ("Sending header %s\n", PROXY_PREFIX); | ||
196 | my_send(PROXY_PREFIX, strlen(PROXY_PREFIX)); | ||
197 | } | ||
198 | |||
199 | #ifdef HAVE_SSL | ||
200 | if (use_ssl) { | ||
201 | result = np_net_ssl_init_with_hostname(sd, (use_sni ? server_address : NULL)); | ||
202 | if (result != STATE_OK) { | ||
203 | printf (_("CRITICAL - Cannot create SSL context.\n")); | ||
204 | close(sd); | ||
205 | np_net_ssl_cleanup(); | ||
206 | return STATE_CRITICAL; | ||
207 | } else { | ||
208 | ssl_established = 1; | ||
209 | } | ||
210 | } | ||
211 | #endif | ||
186 | 212 | ||
187 | /* watch for the SMTP connection string and */ | 213 | /* watch for the SMTP connection string and */ |
188 | /* return a WARNING status if we couldn't read any data */ | 214 | /* return a WARNING status if we couldn't read any data */ |
@@ -195,7 +221,7 @@ main (int argc, char **argv) | |||
195 | xasprintf(&server_response, "%s", buffer); | 221 | xasprintf(&server_response, "%s", buffer); |
196 | 222 | ||
197 | /* send the HELO/EHLO command */ | 223 | /* send the HELO/EHLO command */ |
198 | send(sd, helocmd, strlen(helocmd), 0); | 224 | my_send(helocmd, strlen(helocmd)); |
199 | 225 | ||
200 | /* allow for response to helo command to reach us */ | 226 | /* allow for response to helo command to reach us */ |
201 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { | 227 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { |
@@ -208,14 +234,14 @@ main (int argc, char **argv) | |||
208 | } | 234 | } |
209 | } | 235 | } |
210 | 236 | ||
211 | if(use_ssl && ! supports_tls){ | 237 | if(use_starttls && ! supports_tls){ |
212 | printf(_("WARNING - TLS not supported by server\n")); | 238 | printf(_("WARNING - TLS not supported by server\n")); |
213 | smtp_quit(); | 239 | smtp_quit(); |
214 | return STATE_WARNING; | 240 | return STATE_WARNING; |
215 | } | 241 | } |
216 | 242 | ||
217 | #ifdef HAVE_SSL | 243 | #ifdef HAVE_SSL |
218 | if(use_ssl) { | 244 | if(use_starttls) { |
219 | /* send the STARTTLS command */ | 245 | /* send the STARTTLS command */ |
220 | send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0); | 246 | send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0); |
221 | 247 | ||
@@ -225,7 +251,7 @@ main (int argc, char **argv) | |||
225 | smtp_quit(); | 251 | smtp_quit(); |
226 | return STATE_UNKNOWN; | 252 | return STATE_UNKNOWN; |
227 | } | 253 | } |
228 | result = np_net_ssl_init(sd); | 254 | result = np_net_ssl_init_with_hostname(sd, (use_sni ? server_address : NULL)); |
229 | if(result != STATE_OK) { | 255 | if(result != STATE_OK) { |
230 | printf (_("CRITICAL - Cannot create SSL context.\n")); | 256 | printf (_("CRITICAL - Cannot create SSL context.\n")); |
231 | close(sd); | 257 | close(sd); |
@@ -454,6 +480,10 @@ process_arguments (int argc, char **argv) | |||
454 | int c; | 480 | int c; |
455 | char* temp; | 481 | char* temp; |
456 | 482 | ||
483 | enum { | ||
484 | SNI_OPTION | ||
485 | }; | ||
486 | |||
457 | int option = 0; | 487 | int option = 0; |
458 | static struct option longopts[] = { | 488 | static struct option longopts[] = { |
459 | {"hostname", required_argument, 0, 'H'}, | 489 | {"hostname", required_argument, 0, 'H'}, |
@@ -475,9 +505,13 @@ process_arguments (int argc, char **argv) | |||
475 | {"use-ipv6", no_argument, 0, '6'}, | 505 | {"use-ipv6", no_argument, 0, '6'}, |
476 | {"help", no_argument, 0, 'h'}, | 506 | {"help", no_argument, 0, 'h'}, |
477 | {"lmtp", no_argument, 0, 'L'}, | 507 | {"lmtp", no_argument, 0, 'L'}, |
508 | {"ssl", no_argument, 0, 's'}, | ||
509 | {"tls", no_argument, 0, 's'}, | ||
478 | {"starttls",no_argument,0,'S'}, | 510 | {"starttls",no_argument,0,'S'}, |
511 | {"sni", no_argument, 0, SNI_OPTION}, | ||
479 | {"certificate",required_argument,0,'D'}, | 512 | {"certificate",required_argument,0,'D'}, |
480 | {"ignore-quit-failure",no_argument,0,'q'}, | 513 | {"ignore-quit-failure",no_argument,0,'q'}, |
514 | {"proxy",no_argument,0,'r'}, | ||
481 | {0, 0, 0, 0} | 515 | {0, 0, 0, 0} |
482 | }; | 516 | }; |
483 | 517 | ||
@@ -494,7 +528,7 @@ process_arguments (int argc, char **argv) | |||
494 | } | 528 | } |
495 | 529 | ||
496 | while (1) { | 530 | while (1) { |
497 | c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", | 531 | c = getopt_long (argc, argv, "+hVv46Lrt:p:f:e:c:w:H:C:R:sSD:F:A:U:P:q", |
498 | longopts, &option); | 532 | longopts, &option); |
499 | 533 | ||
500 | if (c == -1 || c == EOF) | 534 | if (c == -1 || c == EOF) |
@@ -511,7 +545,7 @@ process_arguments (int argc, char **argv) | |||
511 | break; | 545 | break; |
512 | case 'p': /* port */ | 546 | case 'p': /* port */ |
513 | if (is_intpos (optarg)) | 547 | if (is_intpos (optarg)) |
514 | server_port = atoi (optarg); | 548 | server_port_option = atoi (optarg); |
515 | else | 549 | else |
516 | usage4 (_("Port must be a positive integer")); | 550 | usage4 (_("Port must be a positive integer")); |
517 | break; | 551 | break; |
@@ -616,11 +650,26 @@ process_arguments (int argc, char **argv) | |||
616 | #else | 650 | #else |
617 | usage (_("SSL support not available - install OpenSSL and recompile")); | 651 | usage (_("SSL support not available - install OpenSSL and recompile")); |
618 | #endif | 652 | #endif |
653 | case 's': | ||
654 | /* ssl */ | ||
655 | use_ssl = TRUE; | ||
656 | server_port = SMTPS_PORT; | ||
657 | break; | ||
619 | case 'S': | 658 | case 'S': |
620 | /* starttls */ | 659 | /* starttls */ |
621 | use_ssl = TRUE; | 660 | use_starttls = TRUE; |
622 | use_ehlo = TRUE; | 661 | use_ehlo = TRUE; |
623 | break; | 662 | break; |
663 | case SNI_OPTION: | ||
664 | #ifdef HAVE_SSL | ||
665 | use_sni = TRUE; | ||
666 | #else | ||
667 | usage (_("SSL support not available - install OpenSSL and recompile")); | ||
668 | #endif | ||
669 | break; | ||
670 | case 'r': | ||
671 | use_proxy_prefix = TRUE; | ||
672 | break; | ||
624 | case 'L': | 673 | case 'L': |
625 | use_lhlo = TRUE; | 674 | use_lhlo = TRUE; |
626 | break; | 675 | break; |
@@ -667,6 +716,14 @@ process_arguments (int argc, char **argv) | |||
667 | if (from_arg==NULL) | 716 | if (from_arg==NULL) |
668 | from_arg = strdup(" "); | 717 | from_arg = strdup(" "); |
669 | 718 | ||
719 | if (use_starttls && use_ssl) { | ||
720 | usage4 (_("Set either -s/--ssl/--tls or -S/--starttls")); | ||
721 | } | ||
722 | |||
723 | if (server_port_option != 0) { | ||
724 | server_port = server_port_option; | ||
725 | } | ||
726 | |||
670 | return validate_arguments (); | 727 | return validate_arguments (); |
671 | } | 728 | } |
672 | 729 | ||
@@ -819,11 +876,18 @@ print_help (void) | |||
819 | printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), | 876 | printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), |
820 | printf (" %s\n", "-F, --fqdn=STRING"); | 877 | printf (" %s\n", "-F, --fqdn=STRING"); |
821 | printf (" %s\n", _("FQDN used for HELO")); | 878 | printf (" %s\n", _("FQDN used for HELO")); |
879 | printf (" %s\n", "-r, --proxy"); | ||
880 | printf (" %s\n", _("Use PROXY protocol prefix for the connection.")); | ||
822 | #ifdef HAVE_SSL | 881 | #ifdef HAVE_SSL |
823 | printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]"); | 882 | printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]"); |
824 | printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); | 883 | printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); |
884 | printf (" %s\n", "-s, --ssl, --tls"); | ||
885 | printf (" %s\n", _("Use SSL/TLS for the connection.")); | ||
886 | printf (_(" Sets default port to %d.\n"), SMTPS_PORT); | ||
825 | printf (" %s\n", "-S, --starttls"); | 887 | printf (" %s\n", "-S, --starttls"); |
826 | printf (" %s\n", _("Use STARTTLS for the connection.")); | 888 | printf (" %s\n", _("Use STARTTLS for the connection.")); |
889 | printf (" %s\n", "--sni"); | ||
890 | printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); | ||
827 | #endif | 891 | #endif |
828 | 892 | ||
829 | printf (" %s\n", "-A, --authtype=STRING"); | 893 | printf (" %s\n", "-A, --authtype=STRING"); |
@@ -844,7 +908,7 @@ print_help (void) | |||
844 | printf (UT_VERBOSE); | 908 | printf (UT_VERBOSE); |
845 | 909 | ||
846 | printf("\n"); | 910 | printf("\n"); |
847 | printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); | 911 | printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); |
848 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful")); | 912 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful")); |
849 | printf ("%s\n", _("connects, but incorrect response messages from the host result in")); | 913 | printf ("%s\n", _("connects, but incorrect response messages from the host result in")); |
850 | printf ("%s\n", _("STATE_WARNING return values.")); | 914 | printf ("%s\n", _("STATE_WARNING return values.")); |
@@ -860,6 +924,6 @@ print_usage (void) | |||
860 | printf ("%s\n", _("Usage:")); | 924 | printf ("%s\n", _("Usage:")); |
861 | printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname); | 925 | printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname); |
862 | printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n"); | 926 | printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n"); |
863 | printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-v] \n"); | 927 | printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-r] [--sni] [-v] \n"); |
864 | } | 928 | } |
865 | 929 | ||
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index d3968a2..56a586a 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | #define DEFAULT_PRIV_PROTOCOL "DES" | 46 | #define DEFAULT_PRIV_PROTOCOL "DES" |
47 | #define DEFAULT_DELIMITER "=" | 47 | #define DEFAULT_DELIMITER "=" |
48 | #define DEFAULT_OUTPUT_DELIMITER " " | 48 | #define DEFAULT_OUTPUT_DELIMITER " " |
49 | #define DEFAULT_BUFFER_SIZE 100 | ||
49 | 50 | ||
50 | #define mark(a) ((a)!=0?"*":"") | 51 | #define mark(a) ((a)!=0?"*":"") |
51 | 52 | ||
@@ -64,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
64 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | 65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 |
65 | #define L_INVERT_SEARCH CHAR_MAX+3 | 66 | #define L_INVERT_SEARCH CHAR_MAX+3 |
66 | #define L_OFFSET CHAR_MAX+4 | 67 | #define L_OFFSET CHAR_MAX+4 |
68 | #define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 | ||
67 | 69 | ||
68 | /* Gobble to string - stop incrementing c when c[0] match one of the | 70 | /* Gobble to string - stop incrementing c when c[0] match one of the |
69 | * characters in s */ | 71 | * characters in s */ |
@@ -157,6 +159,9 @@ int perf_labels = 1; | |||
157 | char* ip_version = ""; | 159 | char* ip_version = ""; |
158 | double multiplier = 1.0; | 160 | double multiplier = 1.0; |
159 | char *fmtstr = ""; | 161 | char *fmtstr = ""; |
162 | bool fmtstr_set = false; | ||
163 | char buffer[DEFAULT_BUFFER_SIZE]; | ||
164 | bool ignore_mib_parsing_errors = false; | ||
160 | 165 | ||
161 | static char *fix_snmp_range(char *th) | 166 | static char *fix_snmp_range(char *th) |
162 | { | 167 | { |
@@ -304,42 +309,55 @@ main (int argc, char **argv) | |||
304 | } | 309 | } |
305 | 310 | ||
306 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 311 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
307 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 312 | |
308 | command_line[0] = snmpcmd; | 313 | unsigned index = 0; |
309 | command_line[1] = strdup ("-Le"); | 314 | command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
310 | command_line[2] = strdup ("-t"); | 315 | |
311 | xasprintf (&command_line[3], "%d", timeout_interval); | 316 | command_line[index++] = snmpcmd; |
312 | command_line[4] = strdup ("-r"); | 317 | command_line[index++] = strdup ("-Le"); |
313 | xasprintf (&command_line[5], "%d", retries); | 318 | command_line[index++] = strdup ("-t"); |
314 | command_line[6] = strdup ("-m"); | 319 | xasprintf (&command_line[index++], "%d", timeout_interval); |
315 | command_line[7] = strdup (miblist); | 320 | command_line[index++] = strdup ("-r"); |
316 | command_line[8] = "-v"; | 321 | xasprintf (&command_line[index++], "%d", retries); |
317 | command_line[9] = strdup (proto); | 322 | command_line[index++] = strdup ("-m"); |
323 | command_line[index++] = strdup (miblist); | ||
324 | command_line[index++] = "-v"; | ||
325 | command_line[index++] = strdup (proto); | ||
326 | |||
327 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", | ||
328 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); | ||
329 | |||
330 | if (ignore_mib_parsing_errors) { | ||
331 | command_line[index++] = "-Pe"; | ||
332 | xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); | ||
333 | } | ||
334 | |||
318 | 335 | ||
319 | for (i = 0; i < numcontext; i++) { | 336 | for (i = 0; i < numcontext; i++) { |
320 | command_line[10 + i] = contextargs[i]; | 337 | command_line[index++] = contextargs[i]; |
321 | } | 338 | } |
322 | 339 | ||
323 | for (i = 0; i < numauthpriv; i++) { | 340 | for (i = 0; i < numauthpriv; i++) { |
324 | command_line[10 + numcontext + i] = authpriv[i]; | 341 | command_line[index++] = authpriv[i]; |
325 | } | 342 | } |
326 | 343 | ||
327 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); | 344 | xasprintf (&command_line[index++], "%s:%s", server_address, port); |
328 | 345 | ||
329 | /* This is just for display purposes, so it can remain a string */ | 346 | xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", |
330 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", | 347 | cl_hidden_auth, |
331 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", | 348 | server_address, |
332 | server_address, port); | 349 | port); |
333 | 350 | ||
334 | for (i = 0; i < numoids; i++) { | 351 | for (i = 0; i < numoids; i++) { |
335 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; | 352 | command_line[index++] = oids[i]; |
336 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 353 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
337 | } | 354 | } |
338 | 355 | ||
339 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; | 356 | command_line[index++] = NULL; |
340 | 357 | ||
341 | if (verbose) | 358 | if (verbose) { |
342 | printf ("%s\n", cl_hidden_auth); | 359 | printf ("%s\n", cl_hidden_auth); |
360 | } | ||
343 | 361 | ||
344 | /* Set signal handling and alarm */ | 362 | /* Set signal handling and alarm */ |
345 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { | 363 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
@@ -420,7 +438,8 @@ main (int argc, char **argv) | |||
420 | } | 438 | } |
421 | else if (strstr (response, "INTEGER: ")) { | 439 | else if (strstr (response, "INTEGER: ")) { |
422 | show = multiply (strstr (response, "INTEGER: ") + 9); | 440 | show = multiply (strstr (response, "INTEGER: ") + 9); |
423 | if (fmtstr != "") { | 441 | |
442 | if (fmtstr_set) { | ||
424 | conv = fmtstr; | 443 | conv = fmtstr; |
425 | } | 444 | } |
426 | } | 445 | } |
@@ -594,8 +613,9 @@ main (int argc, char **argv) | |||
594 | len = sizeof(perfstr)-strlen(perfstr)-1; | 613 | len = sizeof(perfstr)-strlen(perfstr)-1; |
595 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 614 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
596 | 615 | ||
597 | if (type) | 616 | if (strcmp(type, "") != 0) { |
598 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | 617 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); |
618 | } | ||
599 | 619 | ||
600 | if (warning_thresholds) { | 620 | if (warning_thresholds) { |
601 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 621 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
@@ -706,6 +726,7 @@ process_arguments (int argc, char **argv) | |||
706 | {"ipv6", no_argument, 0, '6'}, | 726 | {"ipv6", no_argument, 0, '6'}, |
707 | {"multiplier", required_argument, 0, 'M'}, | 727 | {"multiplier", required_argument, 0, 'M'}, |
708 | {"fmtstr", required_argument, 0, 'f'}, | 728 | {"fmtstr", required_argument, 0, 'f'}, |
729 | {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, | ||
709 | {0, 0, 0, 0} | 730 | {0, 0, 0, 0} |
710 | }; | 731 | }; |
711 | 732 | ||
@@ -853,6 +874,7 @@ process_arguments (int argc, char **argv) | |||
853 | break; | 874 | break; |
854 | case 'R': /* regex */ | 875 | case 'R': /* regex */ |
855 | cflags = REG_ICASE; | 876 | cflags = REG_ICASE; |
877 | // fall through | ||
856 | case 'r': /* regex */ | 878 | case 'r': /* regex */ |
857 | cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; | 879 | cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; |
858 | strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); | 880 | strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); |
@@ -969,8 +991,11 @@ process_arguments (int argc, char **argv) | |||
969 | case 'f': | 991 | case 'f': |
970 | if (multiplier != 1.0) { | 992 | if (multiplier != 1.0) { |
971 | fmtstr=optarg; | 993 | fmtstr=optarg; |
994 | fmtstr_set = true; | ||
972 | } | 995 | } |
973 | break; | 996 | break; |
997 | case L_IGNORE_MIB_PARSING_ERRORS: | ||
998 | ignore_mib_parsing_errors = true; | ||
974 | } | 999 | } |
975 | } | 1000 | } |
976 | 1001 | ||
@@ -1169,33 +1194,33 @@ multiply (char *str) | |||
1169 | double val; | 1194 | double val; |
1170 | char *conv = "%f"; | 1195 | char *conv = "%f"; |
1171 | 1196 | ||
1197 | if(multiplier == 1) | ||
1198 | return(str); | ||
1199 | |||
1172 | if(verbose>2) | 1200 | if(verbose>2) |
1173 | printf(" multiply input: %s\n", str); | 1201 | printf(" multiply input: %s\n", str); |
1174 | 1202 | ||
1175 | val = strtod (str, &endptr); | 1203 | val = strtod (str, &endptr); |
1176 | if ((val == 0.0) && (endptr == str)) { | 1204 | if ((val == 0.0) && (endptr == str)) { |
1177 | if(multiplier != 1) { | 1205 | die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); |
1178 | die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); | ||
1179 | } | ||
1180 | return str; | ||
1181 | } | 1206 | } |
1182 | 1207 | ||
1183 | if(verbose>2) | 1208 | if(verbose>2) |
1184 | printf(" multiply extracted double: %f\n", val); | 1209 | printf(" multiply extracted double: %f\n", val); |
1185 | val *= multiplier; | 1210 | val *= multiplier; |
1186 | if (fmtstr != "") { | 1211 | if (fmtstr_set) { |
1187 | conv = fmtstr; | 1212 | conv = fmtstr; |
1188 | } | 1213 | } |
1189 | if (val == (int)val) { | 1214 | if (val == (int)val) { |
1190 | sprintf(str, "%.0f", val); | 1215 | snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val); |
1191 | } else { | 1216 | } else { |
1192 | if(verbose>2) | 1217 | if(verbose>2) |
1193 | printf(" multiply using format: %s\n", conv); | 1218 | printf(" multiply using format: %s\n", conv); |
1194 | sprintf(str, conv, val); | 1219 | snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val); |
1195 | } | 1220 | } |
1196 | if(verbose>2) | 1221 | if(verbose>2) |
1197 | printf(" multiply result: %s\n", str); | 1222 | printf(" multiply result: %s\n", buffer); |
1198 | return str; | 1223 | return buffer; |
1199 | } | 1224 | } |
1200 | 1225 | ||
1201 | 1226 | ||
@@ -1272,7 +1297,7 @@ print_help (void) | |||
1272 | printf (" %s\n", "--rate-multiplier"); | 1297 | printf (" %s\n", "--rate-multiplier"); |
1273 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); | 1298 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); |
1274 | printf (" %s\n", "--offset=OFFSET"); | 1299 | printf (" %s\n", "--offset=OFFSET"); |
1275 | printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data")); | 1300 | printf (" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data")); |
1276 | 1301 | ||
1277 | /* Tests Against Strings */ | 1302 | /* Tests Against Strings */ |
1278 | printf (" %s\n", "-s, --string=STRING"); | 1303 | printf (" %s\n", "-s, --string=STRING"); |
@@ -1304,6 +1329,9 @@ print_help (void) | |||
1304 | printf (" %s\n", "-O, --perf-oids"); | 1329 | printf (" %s\n", "-O, --perf-oids"); |
1305 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1330 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
1306 | 1331 | ||
1332 | printf (" %s\n", "--ignore-mib-parsing-errors"); | ||
1333 | printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); | ||
1334 | |||
1307 | printf (UT_VERBOSE); | 1335 | printf (UT_VERBOSE); |
1308 | 1336 | ||
1309 | printf ("\n"); | 1337 | printf ("\n"); |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index a607da1..cd965e3 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -34,9 +34,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
34 | #include "common.h" | 34 | #include "common.h" |
35 | #include "popen.h" | 35 | #include "popen.h" |
36 | #include "utils.h" | 36 | #include "utils.h" |
37 | #include <string.h> | ||
38 | #include <math.h> | ||
39 | #include <libintl.h> | ||
40 | 37 | ||
41 | #ifdef HAVE_DECL_SWAPCTL | 38 | #ifdef HAVE_DECL_SWAPCTL |
42 | # ifdef HAVE_SYS_PARAM_H | 39 | # ifdef HAVE_SYS_PARAM_H |
@@ -181,7 +178,7 @@ main (int argc, char **argv) | |||
181 | # ifdef _AIX | 178 | # ifdef _AIX |
182 | if (!allswaps) { | 179 | if (!allswaps) { |
183 | xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); | 180 | xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); |
184 | xasprintf(&swap_format, "%s", "%f%*s %f"); | 181 | xasprintf(&swap_format, "%s", "%lu%*s %lu"); |
185 | conv_factor = 1; | 182 | conv_factor = 1; |
186 | } | 183 | } |
187 | # endif | 184 | # endif |
@@ -208,9 +205,9 @@ main (int argc, char **argv) | |||
208 | temp_buffer = strtok (input_buffer, " \n"); | 205 | temp_buffer = strtok (input_buffer, " \n"); |
209 | while (temp_buffer) { | 206 | while (temp_buffer) { |
210 | if (strstr (temp_buffer, "blocks")) | 207 | if (strstr (temp_buffer, "blocks")) |
211 | sprintf (str, "%s %s", str, "%f"); | 208 | sprintf (str, "%s %s", str, "%lu"); |
212 | else if (strstr (temp_buffer, "dskfree")) | 209 | else if (strstr (temp_buffer, "dskfree")) |
213 | sprintf (str, "%s %s", str, "%f"); | 210 | sprintf (str, "%s %s", str, "%lu"); |
214 | else | 211 | else |
215 | sprintf (str, "%s %s", str, "%*s"); | 212 | sprintf (str, "%s %s", str, "%*s"); |
216 | temp_buffer = strtok (NULL, " \n"); | 213 | temp_buffer = strtok (NULL, " \n"); |
@@ -555,7 +552,7 @@ validate_arguments (void) | |||
555 | } | 552 | } |
556 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { | 553 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { |
557 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage | 554 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage |
558 | * and crit is absolut. We cannot determine the condition at this point since we | 555 | * and crit is absolute. We cannot determine the condition at this point since we |
559 | * dont know the value of total swap yet | 556 | * dont know the value of total swap yet |
560 | */ | 557 | */ |
561 | usage4(_("Warning should be more than critical")); | 558 | usage4(_("Warning should be more than critical")); |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 1365b9c..1d307cf 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -128,7 +128,7 @@ main (int argc, char **argv) | |||
128 | SERVICE[i] = toupper(SERVICE[i]); | 128 | SERVICE[i] = toupper(SERVICE[i]); |
129 | } | 129 | } |
130 | 130 | ||
131 | /* set up a resonable buffer at first (will be realloc()'ed if | 131 | /* set up a reasonable buffer at first (will be realloc()'ed if |
132 | * user specifies other options) */ | 132 | * user specifies other options) */ |
133 | server_expect = calloc(sizeof(char *), 2); | 133 | server_expect = calloc(sizeof(char *), 2); |
134 | 134 | ||
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 0de37a2..68737c4 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -89,7 +89,7 @@ char *ups_status; | |||
89 | int temp_output_c = 0; | 89 | int temp_output_c = 0; |
90 | 90 | ||
91 | int determine_status (void); | 91 | int determine_status (void); |
92 | int get_ups_variable (const char *, char *, size_t); | 92 | int get_ups_variable (const char *, char *); |
93 | 93 | ||
94 | int process_arguments (int, char **); | 94 | int process_arguments (int, char **); |
95 | int validate_arguments (void); | 95 | int validate_arguments (void); |
@@ -189,7 +189,7 @@ main (int argc, char **argv) | |||
189 | } | 189 | } |
190 | 190 | ||
191 | /* get the ups utility voltage if possible */ | 191 | /* get the ups utility voltage if possible */ |
192 | res=get_ups_variable ("input.voltage", temp_buffer, sizeof (temp_buffer)); | 192 | res=get_ups_variable ("input.voltage", temp_buffer); |
193 | if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY; | 193 | if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY; |
194 | else if (res != OK) | 194 | else if (res != OK) |
195 | return STATE_CRITICAL; | 195 | return STATE_CRITICAL; |
@@ -224,7 +224,7 @@ main (int argc, char **argv) | |||
224 | } | 224 | } |
225 | 225 | ||
226 | /* get the ups battery percent if possible */ | 226 | /* get the ups battery percent if possible */ |
227 | res=get_ups_variable ("battery.charge", temp_buffer, sizeof (temp_buffer)); | 227 | res=get_ups_variable ("battery.charge", temp_buffer); |
228 | if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT; | 228 | if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT; |
229 | else if ( res != OK) | 229 | else if ( res != OK) |
230 | return STATE_CRITICAL; | 230 | return STATE_CRITICAL; |
@@ -253,7 +253,7 @@ main (int argc, char **argv) | |||
253 | } | 253 | } |
254 | 254 | ||
255 | /* get the ups load percent if possible */ | 255 | /* get the ups load percent if possible */ |
256 | res=get_ups_variable ("ups.load", temp_buffer, sizeof (temp_buffer)); | 256 | res=get_ups_variable ("ups.load", temp_buffer); |
257 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT; | 257 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT; |
258 | else if ( res != OK) | 258 | else if ( res != OK) |
259 | return STATE_CRITICAL; | 259 | return STATE_CRITICAL; |
@@ -282,7 +282,7 @@ main (int argc, char **argv) | |||
282 | } | 282 | } |
283 | 283 | ||
284 | /* get the ups temperature if possible */ | 284 | /* get the ups temperature if possible */ |
285 | res=get_ups_variable ("ups.temperature", temp_buffer, sizeof (temp_buffer)); | 285 | res=get_ups_variable ("ups.temperature", temp_buffer); |
286 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP; | 286 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP; |
287 | else if ( res != OK) | 287 | else if ( res != OK) |
288 | return STATE_CRITICAL; | 288 | return STATE_CRITICAL; |
@@ -342,7 +342,7 @@ determine_status (void) | |||
342 | char *ptr; | 342 | char *ptr; |
343 | int res; | 343 | int res; |
344 | 344 | ||
345 | res=get_ups_variable ("ups.status", recv_buffer, sizeof (recv_buffer)); | 345 | res=get_ups_variable ("ups.status", recv_buffer); |
346 | if (res == NOSUCHVAR) return OK; | 346 | if (res == NOSUCHVAR) return OK; |
347 | if (res != STATE_OK) { | 347 | if (res != STATE_OK) { |
348 | printf ("%s\n", _("Invalid response received from host")); | 348 | printf ("%s\n", _("Invalid response received from host")); |
@@ -388,7 +388,7 @@ determine_status (void) | |||
388 | 388 | ||
389 | /* gets a variable value for a specific UPS */ | 389 | /* gets a variable value for a specific UPS */ |
390 | int | 390 | int |
391 | get_ups_variable (const char *varname, char *buf, size_t buflen) | 391 | get_ups_variable (const char *varname, char *buf) |
392 | { | 392 | { |
393 | /* char command[MAX_INPUT_BUFFER]; */ | 393 | /* char command[MAX_INPUT_BUFFER]; */ |
394 | char temp_buffer[MAX_INPUT_BUFFER]; | 394 | char temp_buffer[MAX_INPUT_BUFFER]; |
@@ -507,7 +507,7 @@ process_arguments (int argc, char **argv) | |||
507 | usage2 (_("Invalid hostname/address"), optarg); | 507 | usage2 (_("Invalid hostname/address"), optarg); |
508 | } | 508 | } |
509 | break; | 509 | break; |
510 | case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Farenheit) */ | 510 | case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Fahrenheit) */ |
511 | temp_output_c = 1; | 511 | temp_output_c = 1; |
512 | break; | 512 | break; |
513 | case 'u': /* ups name */ | 513 | case 'u': /* ups name */ |
diff --git a/plugins/check_users.c b/plugins/check_users.c index f6f4b36..2a9ee98 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
@@ -1,33 +1,33 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_users plugin | 3 | * Monitoring check_users plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2012 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2012 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_users plugin | 10 | * This file contains the check_users plugin |
11 | * | 11 | * |
12 | * This plugin checks the number of users currently logged in on the local | 12 | * This plugin checks the number of users currently logged in on the local |
13 | * system and generates an error if the number exceeds the thresholds | 13 | * system and generates an error if the number exceeds the thresholds |
14 | * specified. | 14 | * specified. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | * This program is free software: you can redistribute it and/or modify | 17 | * This program is free software: you can redistribute it and/or modify |
18 | * it under the terms of the GNU General Public License as published by | 18 | * it under the terms of the GNU General Public License as published by |
19 | * the Free Software Foundation, either version 3 of the License, or | 19 | * the Free Software Foundation, either version 3 of the License, or |
20 | * (at your option) any later version. | 20 | * (at your option) any later version. |
21 | * | 21 | * |
22 | * This program is distributed in the hope that it will be useful, | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 | * GNU General Public License for more details. | 25 | * GNU General Public License for more details. |
26 | * | 26 | * |
27 | * You should have received a copy of the GNU General Public License | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 28 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
29 | * | 29 | * |
30 | * | 30 | * |
31 | *****************************************************************************/ | 31 | *****************************************************************************/ |
32 | 32 | ||
33 | const char *progname = "check_users"; | 33 | const char *progname = "check_users"; |
@@ -48,6 +48,11 @@ const char *email = "devel@monitoring-plugins.org"; | |||
48 | # include "popen.h" | 48 | # include "popen.h" |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #ifdef HAVE_LIBSYSTEMD | ||
52 | #include <systemd/sd-daemon.h> | ||
53 | #include <systemd/sd-login.h> | ||
54 | #endif | ||
55 | |||
51 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) | 56 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) |
52 | 57 | ||
53 | int process_arguments (int, char **); | 58 | int process_arguments (int, char **); |
@@ -85,6 +90,11 @@ main (int argc, char **argv) | |||
85 | 90 | ||
86 | users = 0; | 91 | users = 0; |
87 | 92 | ||
93 | #ifdef HAVE_LIBSYSTEMD | ||
94 | if (sd_booted () > 0) | ||
95 | users = sd_get_sessions (NULL); | ||
96 | else { | ||
97 | #endif | ||
88 | #if HAVE_WTSAPI32_H | 98 | #if HAVE_WTSAPI32_H |
89 | if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, | 99 | if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, |
90 | 0, 1, &wtsinfo, &wtscount)) { | 100 | 0, 1, &wtsinfo, &wtscount)) { |
@@ -156,6 +166,9 @@ main (int argc, char **argv) | |||
156 | if (spclose (child_process)) | 166 | if (spclose (child_process)) |
157 | result = possibly_set (result, STATE_UNKNOWN); | 167 | result = possibly_set (result, STATE_UNKNOWN); |
158 | #endif | 168 | #endif |
169 | #ifdef HAVE_LIBSYSTEMD | ||
170 | } | ||
171 | #endif | ||
159 | 172 | ||
160 | /* check the user count against warning and critical thresholds */ | 173 | /* check the user count against warning and critical thresholds */ |
161 | result = get_status((double)users, thlds); | 174 | result = get_status((double)users, thlds); |
@@ -163,7 +176,7 @@ main (int argc, char **argv) | |||
163 | if (result == STATE_UNKNOWN) | 176 | if (result == STATE_UNKNOWN) |
164 | printf ("%s\n", _("Unable to read output")); | 177 | printf ("%s\n", _("Unable to read output")); |
165 | else { | 178 | else { |
166 | printf (_("USERS %s - %d users currently logged in |%s\n"), | 179 | printf (_("USERS %s - %d users currently logged in |%s\n"), |
167 | state_text(result), users, | 180 | state_text(result), users, |
168 | sperfdata_int("users", users, "", warning_range, | 181 | sperfdata_int("users", users, "", warning_range, |
169 | critical_range, TRUE, 0, FALSE, 0)); | 182 | critical_range, TRUE, 0, FALSE, 0)); |
diff --git a/plugins/picohttpparser/picohttpparser.c b/plugins/picohttpparser/picohttpparser.c index d9680b7..d0bfac6 100644 --- a/plugins/picohttpparser/picohttpparser.c +++ b/plugins/picohttpparser/picohttpparser.c | |||
@@ -400,7 +400,7 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si | |||
400 | *num_headers = 0; | 400 | *num_headers = 0; |
401 | 401 | ||
402 | /* if last_len != 0, check if the request is complete (a fast countermeasure | 402 | /* if last_len != 0, check if the request is complete (a fast countermeasure |
403 | againt slowloris */ | 403 | against slowloris */ |
404 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { | 404 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { |
405 | return r; | 405 | return r; |
406 | } | 406 | } |
@@ -435,7 +435,7 @@ static const char *parse_response(const char *buf, const char *buf_end, int *maj | |||
435 | } | 435 | } |
436 | PARSE_INT_3(status); | 436 | PARSE_INT_3(status); |
437 | 437 | ||
438 | /* get message includig preceding space */ | 438 | /* get message including preceding space */ |
439 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { | 439 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { |
440 | return NULL; | 440 | return NULL; |
441 | } | 441 | } |
diff --git a/plugins/popen.c b/plugins/popen.c index 9eb49b6..723817d 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -14,7 +14,7 @@ | |||
14 | * FILE * spopen(const char *); | 14 | * FILE * spopen(const char *); |
15 | * int spclose(FILE *); | 15 | * int spclose(FILE *); |
16 | * | 16 | * |
17 | * Code taken with liitle modification from "Advanced Programming for the Unix | 17 | * Code taken with little modification from "Advanced Programming for the Unix |
18 | * Environment" by W. Richard Stevens | 18 | * Environment" by W. Richard Stevens |
19 | * | 19 | * |
20 | * This is considered safe in that no shell is spawned, and the environment | 20 | * This is considered safe in that no shell is spawned, and the environment |
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index a7155d2..102191e 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -44,6 +44,8 @@ | |||
44 | # include <sys/wait.h> | 44 | # include <sys/wait.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #include "./utils.h" | ||
48 | |||
47 | /** macros **/ | 49 | /** macros **/ |
48 | #ifndef WEXITSTATUS | 50 | #ifndef WEXITSTATUS |
49 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) | 51 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) |
@@ -114,10 +116,6 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
114 | env[0] = strdup("LC_ALL=C"); | 116 | env[0] = strdup("LC_ALL=C"); |
115 | env[1] = '\0'; | 117 | env[1] = '\0'; |
116 | 118 | ||
117 | /* if no command was passed, return with no error */ | ||
118 | if (cmdstring == NULL) | ||
119 | return -1; | ||
120 | |||
121 | /* make copy of command string so strtok() doesn't silently modify it */ | 119 | /* make copy of command string so strtok() doesn't silently modify it */ |
122 | /* (the calling program may want to access it later) */ | 120 | /* (the calling program may want to access it later) */ |
123 | cmdlen = strlen(cmdstring); | 121 | cmdlen = strlen(cmdstring); |
@@ -203,7 +201,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
203 | } | 201 | } |
204 | 202 | ||
205 | /* parent picks up execution here */ | 203 | /* parent picks up execution here */ |
206 | /* close childs descriptors in our address space */ | 204 | /* close children descriptors in our address space */ |
207 | close(pfd[1]); | 205 | close(pfd[1]); |
208 | close(pfderr[1]); | 206 | close(pfderr[1]); |
209 | 207 | ||
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t index 1d2939e..b6479f1 100644 --- a/plugins/t/check_by_ssh.t +++ b/plugins/t/check_by_ssh.t | |||
@@ -19,19 +19,19 @@ plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_servic | |||
19 | plan tests => 42; | 19 | plan tests => 42; |
20 | 20 | ||
21 | # Some random check strings/response | 21 | # Some random check strings/response |
22 | my @responce = ('OK: Everything is fine', | 22 | my @response = ('OK: Everything is fine', |
23 | 'WARNING: Hey, pick me, pick me', | 23 | 'WARNING: Hey, pick me, pick me', |
24 | 'CRITICAL: Shit happens', | 24 | 'CRITICAL: Shit happens', |
25 | 'UNKNOWN: What can I do for ya', | 25 | 'UNKNOWN: What can I do for ya', |
26 | 'WOOPS: What did I smoke', | 26 | 'WOOPS: What did I smoke', |
27 | ); | 27 | ); |
28 | my @responce_re; | 28 | my @response_re; |
29 | my @check; | 29 | my @check; |
30 | for (@responce) { | 30 | for (@response) { |
31 | push(@check, "echo $_"); | 31 | push(@check, "echo $_"); |
32 | my $re_str = $_; | 32 | my $re_str = $_; |
33 | $re_str =~ s{(.)} { "\Q$1" }ge; | 33 | $re_str =~ s{(.)} { "\Q$1" }ge; |
34 | push(@responce_re, $re_str); | 34 | push(@response_re, $re_str); |
35 | } | 35 | } |
36 | 36 | ||
37 | my $result; | 37 | my $result; |
@@ -47,7 +47,7 @@ for (my $i=0; $i<4; $i++) { | |||
47 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'" | 47 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'" |
48 | ); | 48 | ); |
49 | cmp_ok($result->return_code, '==', $i, "Exit with return code $i"); | 49 | cmp_ok($result->return_code, '==', $i, "Exit with return code $i"); |
50 | is($result->output, $responce[$i], "Status text is correct for check $i"); | 50 | is($result->output, $response[$i], "Status text is correct for check $i"); |
51 | } | 51 | } |
52 | 52 | ||
53 | $result = NPTest->testCmd( | 53 | $result = NPTest->testCmd( |
@@ -84,7 +84,7 @@ $result = NPTest->testCmd( | |||
84 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'" | 84 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'" |
85 | ); | 85 | ); |
86 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); | 86 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); |
87 | is($result->output, $responce[4], "Return proper status text even with unknown status codes"); | 87 | is($result->output, $response[4], "Return proper status text even with unknown status codes"); |
88 | 88 | ||
89 | $result = NPTest->testCmd( | 89 | $result = NPTest->testCmd( |
90 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" | 90 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" |
@@ -108,7 +108,7 @@ my %linemap = ( | |||
108 | foreach my $line (0, 2, 4, 6) { | 108 | foreach my $line (0, 2, 4, 6) { |
109 | my $code = $linemap{$line}; | 109 | my $code = $linemap{$line}; |
110 | my $statline = $line+1; | 110 | my $statline = $line+1; |
111 | is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line"); | 111 | is($lines[$line], "$response[$code]", "multiple checks status text is correct for line $line"); |
112 | is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); | 112 | is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); |
113 | } | 113 | } |
114 | 114 | ||
@@ -124,7 +124,7 @@ close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!"); | |||
124 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); | 124 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); |
125 | for (0) { | 125 | for (0) { |
126 | if ($pasv[$_]) { | 126 | if ($pasv[$_]) { |
127 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check'); | 127 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $response_re[2] . '$/', 'proper result for passive check'); |
128 | } else { | 128 | } else { |
129 | fail('proper result for passive check'); | 129 | fail('proper result for passive check'); |
130 | } | 130 | } |
@@ -144,7 +144,7 @@ for (0, 1, 2, 3, 4) { | |||
144 | if ($pasv[$_]) { | 144 | if ($pasv[$_]) { |
145 | my $ret = $_; | 145 | my $ret = $_; |
146 | $ret = 9 if ($_ == 4); | 146 | $ret = 9 if ($_ == 4); |
147 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_"); | 147 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $response_re[$_] . '$/', "proper result for passive check $_"); |
148 | } else { | 148 | } else { |
149 | fail("proper result for passive check $_"); | 149 | fail("proper result for passive check $_"); |
150 | } | 150 | } |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index c8f08f5..ca035ce 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -326,19 +326,19 @@ cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free meg | |||
326 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); | 326 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); |
327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); | 327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); |
328 | 328 | ||
329 | # regex: exit unknown if given regex is not compileable | 329 | # regex: exit unknown if given regex is not compilable |
330 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" ); | 330 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" ); |
331 | cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable"); | 331 | cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compilable"); |
332 | 332 | ||
333 | # ignore: exit unknown, if all pathes are deselected using -i | 333 | # ignore: exit unknown, if all paths are deselected using -i |
334 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" ); | 334 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" ); |
335 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)"); | 335 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)"); |
336 | 336 | ||
337 | # ignore: exit unknown, if all pathes are deselected using -I | 337 | # ignore: exit unknown, if all paths are deselected using -I |
338 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" ); | 338 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" ); |
339 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)"); | 339 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)"); |
340 | 340 | ||
341 | # ignore: exit unknown, if all pathes are deselected using -i | 341 | # ignore: exit unknown, if all paths are deselected using -i |
342 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" ); | 342 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" ); |
343 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'"); | 343 | cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'"); |
344 | 344 | ||
@@ -347,7 +347,7 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mo | |||
347 | like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it"); | 347 | like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it"); |
348 | unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it"); | 348 | unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it"); |
349 | 349 | ||
350 | # ignore: test if all pathes are listed when ignore regex doesn't match | 350 | # ignore: test if all paths are listed when ignore regex doesn't match |
351 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'"); | 351 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'"); |
352 | like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match"); | 352 | like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match"); |
353 | like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match"); | 353 | like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match"); |
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 1ca52f6..1f2fbdf 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -178,13 +178,13 @@ SKIP: { | |||
178 | 178 | ||
179 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); | 179 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); |
180 | is( $res->return_code, 0, "Proxy HTTP works"); | 180 | is( $res->return_code, 0, "Proxy HTTP works"); |
181 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent"); | 181 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficient"); |
182 | 182 | ||
183 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); | 183 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); |
184 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); | 184 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); |
185 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | 185 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficient"); |
186 | 186 | ||
187 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); | 187 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); |
188 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); | 188 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); |
189 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | 189 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficient"); |
190 | } | 190 | } |
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index e426bf5..baf3acc 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t | |||
@@ -5,7 +5,7 @@ | |||
5 | # | 5 | # |
6 | # | 6 | # |
7 | # These are the database permissions required for this test: | 7 | # These are the database permissions required for this test: |
8 | # GRANT SELECT ON $db.* TO $user@$host INDENTIFIED BY '$password'; | 8 | # GRANT SELECT ON $db.* TO $user@$host IDENTIFIED BY '$password'; |
9 | # GRANT SUPER, REPLICATION CLIENT ON *.* TO $user@$host; | 9 | # GRANT SUPER, REPLICATION CLIENT ON *.* TO $user@$host; |
10 | # Check with: | 10 | # Check with: |
11 | # mysql -u$user -p$password -h$host $db | 11 | # mysql -u$user -p$password -h$host $db |
@@ -23,9 +23,9 @@ plan tests => 15; | |||
23 | my $bad_login_output = '/Access denied for user /'; | 23 | my $bad_login_output = '/Access denied for user /'; |
24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); | 24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); |
25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup"); | 25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup"); |
26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privleges)", "-u test -ptest"); | 26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privileges)", "-u test -ptest"); |
27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); | 27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); |
28 | my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privleges)", $mysql_login_details || "-u test -ptest"); | 28 | my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privileges)", $mysql_login_details || "-u test -ptest"); |
29 | 29 | ||
30 | my $result; | 30 | my $result; |
31 | 31 | ||
diff --git a/plugins/t/check_mysql_query.t b/plugins/t/check_mysql_query.t index 96899ac..c30245b 100644 --- a/plugins/t/check_mysql_query.t +++ b/plugins/t/check_mysql_query.t | |||
@@ -31,7 +31,7 @@ $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver $ | |||
31 | cmp_ok( $result->return_code, '==', 0, "Can run query"); | 31 | cmp_ok( $result->return_code, '==', 0, "Can run query"); |
32 | 32 | ||
33 | $result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details"); | 33 | $result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details"); |
34 | cmp_ok( $result->return_code, '==', 3, "Missing query parmeter"); | 34 | cmp_ok( $result->return_code, '==', 3, "Missing query parameter"); |
35 | like( $result->output, "/Must specify a SQL query to run/", "Missing query error message"); | 35 | like( $result->output, "/Must specify a SQL query to run/", "Missing query error message"); |
36 | 36 | ||
37 | $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy -d mysql"); | 37 | $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy -d mysql"); |
diff --git a/plugins/t/check_nagios.t b/plugins/t/check_nagios.t index 81fc24d..f38f5e9 100644 --- a/plugins/t/check_nagios.t +++ b/plugins/t/check_nagios.t | |||
@@ -36,7 +36,7 @@ cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" ); | |||
36 | like ( $result->output, $warningOutput, "Output for warning correct" ); | 36 | like ( $result->output, $warningOutput, "Output for warning correct" ); |
37 | 37 | ||
38 | my $now = time; | 38 | my $now = time; |
39 | # This substitution is dependant on the testcase | 39 | # This substitution is dependent on the testcase |
40 | system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; | 40 | system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; |
41 | 41 | ||
42 | $result = NPTest->testCmd( | 42 | $result = NPTest->testCmd( |
diff --git a/plugins/t/check_smtp.t b/plugins/t/check_smtp.t index aa6dae4..1a1ebe3 100644 --- a/plugins/t/check_smtp.t +++ b/plugins/t/check_smtp.t | |||
@@ -8,12 +8,14 @@ use strict; | |||
8 | use Test::More; | 8 | use Test::More; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP", | 11 | my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP", |
12 | "A host providing an SMTP Service (a mail server)", "mailhost"); | 12 | "A host providing an SMTP Service (a mail server)", "mailhost"); |
13 | my $host_tcp_smtp_tls = getTestParameter( "NP_HOST_TCP_SMTP_TLS", | 13 | my $host_tcp_smtp_starttls = getTestParameter( "NP_HOST_TCP_SMTP_STARTTLS", |
14 | "A host providing SMTP with STARTTLS", $host_tcp_smtp); | ||
15 | my $host_tcp_smtp_nostarttls = getTestParameter( "NP_HOST_TCP_SMTP_NOSTARTTLS", | ||
16 | "A host providing SMTP without STARTTLS", ""); | ||
17 | my $host_tcp_smtp_tls = getTestParameter( "NP_HOST_TCP_SMTP_TLS", | ||
14 | "A host providing SMTP with TLS", $host_tcp_smtp); | 18 | "A host providing SMTP with TLS", $host_tcp_smtp); |
15 | my $host_tcp_smtp_notls = getTestParameter( "NP_HOST_TCP_SMTP_NOTLS", | ||
16 | "A host providing SMTP without TLS", ""); | ||
17 | 19 | ||
18 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | 20 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", |
19 | "The hostname of system not responsive to network requests", "10.0.0.1" ); | 21 | "The hostname of system not responsive to network requests", "10.0.0.1" ); |
@@ -22,7 +24,7 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | |||
22 | "An invalid (not known to DNS) hostname", "nosuchhost" ); | 24 | "An invalid (not known to DNS) hostname", "nosuchhost" ); |
23 | my $res; | 25 | my $res; |
24 | 26 | ||
25 | plan tests => 10; | 27 | plan tests => 16; |
26 | 28 | ||
27 | SKIP: { | 29 | SKIP: { |
28 | skip "No SMTP server defined", 4 unless $host_tcp_smtp; | 30 | skip "No SMTP server defined", 4 unless $host_tcp_smtp; |
@@ -42,22 +44,38 @@ SKIP: { | |||
42 | local $TODO = "Output is over two lines"; | 44 | local $TODO = "Output is over two lines"; |
43 | like ( $res->output, qr/^SMTP WARNING/, "Correct error message" ); | 45 | like ( $res->output, qr/^SMTP WARNING/, "Correct error message" ); |
44 | } | 46 | } |
47 | |||
48 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp --ssl -p 25" ); | ||
49 | is ($res->return_code, 2, "Check rc of connecting to $host_tcp_smtp with TLS on standard SMTP port" ); | ||
50 | like ($res->output, qr/^CRITICAL - Cannot make SSL connection\./, "Check output of connecting to $host_tcp_smtp with TLS on standard SMTP port"); | ||
45 | } | 51 | } |
46 | 52 | ||
47 | SKIP: { | 53 | SKIP: { |
48 | skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls; | 54 | skip "No SMTP server with STARTTLS defined", 1 unless $host_tcp_smtp_starttls; |
49 | # SSL connection for TLS | 55 | # SSL connection for STARTTLS |
50 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p 25 -S" ); | 56 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_starttls -p 25 -S" ); |
51 | is ($res->return_code, 0, "OK, with STARTTLS" ); | 57 | is ($res->return_code, 0, "OK, with STARTTLS" ); |
52 | } | 58 | } |
53 | 59 | ||
54 | SKIP: { | 60 | SKIP: { |
55 | skip "No SMTP server without TLS defined", 2 unless $host_tcp_smtp_notls; | 61 | skip "No SMTP server without STARTTLS defined", 2 unless $host_tcp_smtp_nostarttls; |
56 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_notls -p 25 -S" ); | 62 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_nostarttls -p 25 -S" ); |
57 | is ($res->return_code, 1, "OK, got warning from server without TLS"); | 63 | is ($res->return_code, 1, "OK, got warning from server without STARTTLS"); |
58 | is ($res->output, "WARNING - TLS not supported by server", "Right error message" ); | 64 | is ($res->output, "WARNING - TLS not supported by server", "Right error message" ); |
59 | } | 65 | } |
60 | 66 | ||
67 | SKIP: { | ||
68 | skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls; | ||
69 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls --ssl" ); | ||
70 | is ($res->return_code, 0, "Check rc of connecting to $host_tcp_smtp_tls with TLS" ); | ||
71 | like ($res->output, qr/^SMTP OK - /, "Check output of connecting to $host_tcp_smtp_tls with TLS" ); | ||
72 | |||
73 | my $unused_port = 4465; | ||
74 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p $unused_port --ssl" ); | ||
75 | is ($res->return_code, 2, "Check rc of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port" ); | ||
76 | like ($res->output, qr/^connect to address $host_tcp_smtp_tls and port $unused_port: Connection refused/, "Check output of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port"); | ||
77 | } | ||
78 | |||
61 | $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" ); | 79 | $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" ); |
62 | is ($res->return_code, 2, "CRITICAL - host non responding" ); | 80 | is ($res->return_code, 2, "CRITICAL - host non responding" ); |
63 | 81 | ||
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index f2f218f..576cc50 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -26,22 +26,22 @@ $res = NPTest->testCmd( "./check_snmp -t 1" ); | |||
26 | is( $res->return_code, 3, "No host name" ); | 26 | is( $res->return_code, 3, "No host name" ); |
27 | is( $res->output, "No host specified" ); | 27 | is( $res->output, "No host specified" ); |
28 | 28 | ||
29 | $res = NPTest->testCmd( "./check_snmp -H fakehostname" ); | 29 | $res = NPTest->testCmd( "./check_snmp -H fakehostname --ignore-mib-parsing-errors" ); |
30 | is( $res->return_code, 3, "No OIDs specified" ); | 30 | is( $res->return_code, 3, "No OIDs specified" ); |
31 | is( $res->output, "No OIDs specified" ); | 31 | is( $res->output, "No OIDs specified" ); |
32 | 32 | ||
33 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 -U not_a_user --seclevel=rubbish" ); | 33 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3 -U not_a_user --seclevel=rubbish" ); |
34 | is( $res->return_code, 3, "Invalid seclevel" ); | 34 | is( $res->return_code, 3, "Invalid seclevel" ); |
35 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); | 35 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); |
36 | 36 | ||
37 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" ); | 37 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3c" ); |
38 | is( $res->return_code, 3, "Invalid protocol" ); | 38 | is( $res->return_code, 3, "Invalid protocol" ); |
39 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | 39 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); |
40 | 40 | ||
41 | SKIP: { | 41 | SKIP: { |
42 | skip "no snmp host defined", 50 if ( ! $host_snmp ); | 42 | skip "no snmp host defined", 50 if ( ! $host_snmp ); |
43 | 43 | ||
44 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 44 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
45 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 45 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
46 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); | 46 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); |
47 | $res->output =~ /^SNMP OK - (\d+)/; | 47 | $res->output =~ /^SNMP OK - (\d+)/; |
@@ -51,111 +51,111 @@ SKIP: { | |||
51 | 51 | ||
52 | 52 | ||
53 | # some more threshold tests | 53 | # some more threshold tests |
54 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1"); | 54 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1"); |
55 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); | 55 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); |
56 | 56 | ||
57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:"); | 57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:"); |
58 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); | 58 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); |
59 | 59 | ||
60 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1"); | 60 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c ~:1"); |
61 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); | 61 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); |
62 | 62 | ||
63 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10"); | 63 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:10"); |
64 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); | 64 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); |
65 | 65 | ||
66 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10"); | 66 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c \@1:10"); |
67 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); | 67 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); |
68 | 68 | ||
69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1"); | 69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 10:1"); |
70 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" ); | 70 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" ); |
71 | 71 | ||
72 | 72 | ||
73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); | 73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); |
74 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); | 74 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); |
75 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | 75 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); |
76 | 76 | ||
77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); | 77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0"); |
78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | 78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); |
79 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); | 79 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); |
80 | 80 | ||
81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); | 81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); |
82 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); | 82 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); |
83 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 83 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
84 | 84 | ||
85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); | 85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); |
86 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); | 86 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); |
87 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 87 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
88 | 88 | ||
89 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); | 89 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); |
90 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); | 90 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); |
91 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); | 91 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); |
92 | 92 | ||
93 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); | 93 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); |
94 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); | 94 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); |
95 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); | 95 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); |
96 | 96 | ||
97 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | 97 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); |
98 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | 98 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); |
99 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); | 99 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); |
100 | 100 | ||
101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | 101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); |
102 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); | 102 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); |
103 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); | 103 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); |
104 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | 104 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); |
105 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | 105 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); |
106 | 106 | ||
107 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); | 107 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); |
108 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); | 108 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); |
109 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); | 109 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); |
110 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | 110 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); |
111 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | 111 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); |
112 | 112 | ||
113 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); | 113 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); |
114 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); | 114 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); |
115 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); | 115 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); |
116 | 116 | ||
117 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); | 117 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); |
118 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); | 118 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); |
119 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); | 119 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); |
120 | 120 | ||
121 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); | 121 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); |
122 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; | 122 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; |
123 | my $lower = $1 - 0.05; | 123 | my $lower = $1 - 0.05; |
124 | my $higher = $1 + 0.05; | 124 | my $higher = $1 + 0.05; |
125 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); | 125 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); |
126 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); | 126 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); |
127 | 127 | ||
128 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2"); | 128 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2"); |
129 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); | 129 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); |
130 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); | 130 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); |
131 | 131 | ||
132 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); | 132 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); |
133 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); | 133 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); |
134 | 134 | ||
135 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); | 135 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); |
136 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); | 136 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); |
137 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); | 137 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); |
138 | 138 | ||
139 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); | 139 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); |
140 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); | 140 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); |
141 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); | 141 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); |
142 | 142 | ||
143 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); | 143 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); |
144 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); | 144 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); |
145 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); | 145 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); |
146 | 146 | ||
147 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | 147 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0"); |
148 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | 148 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); |
149 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | 149 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); |
150 | 150 | ||
151 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1"); | 151 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1"); |
152 | cmp_ok( $res->return_code, '==', 0, "snmp response without datatype"); | 152 | cmp_ok( $res->return_code, '==', 0, "snmp response without datatype"); |
153 | like( $res->output, '/^SNMP OK - "(systemd|init)" \| $/', "snmp response without datatype" ); | 153 | like( $res->output, '/^SNMP OK - "(systemd|init)" \| $/', "snmp response without datatype" ); |
154 | } | 154 | } |
155 | 155 | ||
156 | SKIP: { | 156 | SKIP: { |
157 | skip "no SNMP user defined", 1 if ( ! $user_snmp ); | 157 | skip "no SNMP user defined", 1 if ( ! $user_snmp ); |
158 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv"); | 158 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv"); |
159 | like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" ); | 159 | like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" ); |
160 | } | 160 | } |
161 | 161 | ||
@@ -163,14 +163,14 @@ SKIP: { | |||
163 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway | 163 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway |
164 | SKIP: { | 164 | SKIP: { |
165 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | 165 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
166 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 166 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
167 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); | 167 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); |
168 | like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); | 168 | like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); |
169 | } | 169 | } |
170 | 170 | ||
171 | SKIP: { | 171 | SKIP: { |
172 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | 172 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); |
173 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 173 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
174 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 174 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
175 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); | 175 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host).*/s', "String matches invalid host"); |
176 | } | 176 | } |
diff --git a/plugins/t/negate.t b/plugins/t/negate.t index d96a109..5ec1c84 100644 --- a/plugins/t/negate.t +++ b/plugins/t/negate.t | |||
@@ -84,7 +84,7 @@ foreach my $current_state (keys(%state)) { | |||
84 | foreach my $new_state (keys(%state)) { | 84 | foreach my $new_state (keys(%state)) { |
85 | $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); | 85 | $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); |
86 | is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" ); | 86 | is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" ); |
87 | is( $res->output, uc($new_state).": Fake $new_state", "Substitued fake $new_state output"); | 87 | is( $res->output, uc($new_state).": Fake $new_state", "Substituted fake $new_state output"); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 3af218f..b3a0a30 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t | |||
@@ -8,7 +8,7 @@ use Test::More; | |||
8 | use NPTest; | 8 | use NPTest; |
9 | 9 | ||
10 | if (-x "./check_procs") { | 10 | if (-x "./check_procs") { |
11 | plan tests => 52; | 11 | plan tests => 54; |
12 | } else { | 12 | } else { |
13 | plan skip_all => "No check_procs compiled"; | 13 | plan skip_all => "No check_procs compiled"; |
14 | } | 14 | } |
@@ -34,9 +34,13 @@ is( $result->return_code, 0, "Checking no threshold breeched" ); | |||
34 | is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" ); | 34 | is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" ); |
35 | 35 | ||
36 | $result = NPTest->testCmd( "$command -C launchd -c 5" ); | 36 | $result = NPTest->testCmd( "$command -C launchd -c 5" ); |
37 | is( $result->return_code, 2, "Checking processes filtered by command name" ); | 37 | is( $result->return_code, 2, "Checking processes matched by command name" ); |
38 | is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" ); | 38 | is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" ); |
39 | 39 | ||
40 | $result = NPTest->testCmd( "$command -X bash -c 5" ); | ||
41 | is( $result->return_code, 2, "Checking processes excluded by command name" ); | ||
42 | is( $result->output, "PROCS CRITICAL: 95 processes with exclude progs 'bash' | procs=95;;5;0;", "Output correct" ); | ||
43 | |||
40 | SKIP: { | 44 | SKIP: { |
41 | skip 'user with uid 501 required', 4 unless getpwuid(501); | 45 | skip 'user with uid 501 required', 4 unless getpwuid(501); |
42 | 46 | ||
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index bc03ec6..bfe42e1 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -53,7 +53,7 @@ if ($pid) { | |||
53 | #print "child\n"; | 53 | #print "child\n"; |
54 | 54 | ||
55 | print "Please contact SNMP at: $port_snmp\n"; | 55 | print "Please contact SNMP at: $port_snmp\n"; |
56 | close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK) | 56 | close(STDERR); # Comment out to debug snmpd problems (most errors sent there are OK) |
57 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); | 57 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); |
58 | } | 58 | } |
59 | 59 | ||
@@ -227,7 +227,7 @@ is($res->output, 'SNMP OK - "555\"I said\"" | ', "Check string with a double quo | |||
227 | 227 | ||
228 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" ); | 228 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" ); |
229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); | 229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); |
230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check witn numbers returns whole string"); | 230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check with numbers returns whole string"); |
231 | 231 | ||
232 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 232 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
233 | is($res->return_code, 0, "Negative integer check OK" ); | 233 | is($res->return_code, 0, "Negative integer check OK" ); |
diff --git a/plugins/utils.h b/plugins/utils.h index 5b54da3..c76b321 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -7,7 +7,7 @@ | |||
7 | /* The purpose of this package is to provide safer alternatives to C | 7 | /* The purpose of this package is to provide safer alternatives to C |
8 | functions that might otherwise be vulnerable to hacking. This | 8 | functions that might otherwise be vulnerable to hacking. This |
9 | currently includes a standard suite of validation routines to be sure | 9 | currently includes a standard suite of validation routines to be sure |
10 | that an string argument acually converts to its intended type and a | 10 | that an string argument actually converts to its intended type and a |
11 | suite of string handling routine that do their own memory management | 11 | suite of string handling routine that do their own memory management |
12 | in order to resist overflow attacks. In addition, a few functions are | 12 | in order to resist overflow attacks. In addition, a few functions are |
13 | provided to standardize version and error reporting across the entire | 13 | provided to standardize version and error reporting across the entire |