diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/Makefile.am | 2 | ||||
| -rw-r--r-- | plugins/check_curl.c | 256 | ||||
| -rw-r--r-- | plugins/check_dbi.c | 14 | ||||
| -rw-r--r-- | plugins/check_fping.c | 1 | ||||
| -rw-r--r-- | plugins/check_hpjd.c | 1 | ||||
| -rw-r--r-- | plugins/check_http.c | 1 | ||||
| -rw-r--r-- | plugins/check_ntp_peer.c | 6 | ||||
| -rw-r--r-- | plugins/check_radius.c | 2 | ||||
| -rw-r--r-- | plugins/check_smtp.c | 56 | ||||
| -rw-r--r-- | plugins/check_snmp.c | 64 | ||||
| -rw-r--r-- | plugins/check_swap.c | 6 | ||||
| -rw-r--r-- | plugins/check_ups.c | 14 | ||||
| -rw-r--r-- | plugins/check_users.c | 37 | ||||
| -rw-r--r-- | plugins/t/check_smtp.t | 40 | ||||
| -rw-r--r-- | plugins/t/check_snmp.t | 68 |
15 files changed, 391 insertions, 177 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ab59eb73..49086b7a 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 100a97aa..d0871c48 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -244,7 +244,7 @@ void curlhelp_freewritebuffer (curlhelp_write_curlbuf*); | |||
| 244 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); | 244 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); |
| 245 | int curlhelp_buffer_read_callback (void *, size_t , size_t , void *); | 245 | int curlhelp_buffer_read_callback (void *, size_t , size_t , void *); |
| 246 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); | 246 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); |
| 247 | curlhelp_ssl_library curlhelp_get_ssl_library (CURL*); | 247 | curlhelp_ssl_library curlhelp_get_ssl_library (); |
| 248 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); | 248 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); |
| 249 | int net_noopenssl_check_certificate (cert_ptr_union*, int, int); | 249 | int net_noopenssl_check_certificate (cert_ptr_union*, int, int); |
| 250 | 250 | ||
| @@ -297,6 +297,7 @@ main (int argc, char **argv) | |||
| 297 | 297 | ||
| 298 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | 298 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) |
| 299 | { | 299 | { |
| 300 | (void) preverify_ok; | ||
| 300 | /* TODO: we get all certificates of the chain, so which ones | 301 | /* TODO: we get all certificates of the chain, so which ones |
| 301 | * should we test? | 302 | * should we test? |
| 302 | * TODO: is the last certificate always the server certificate? | 303 | * TODO: is the last certificate always the server certificate? |
| @@ -321,6 +322,8 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | |||
| 321 | 322 | ||
| 322 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) | 323 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) |
| 323 | { | 324 | { |
| 325 | (void) curl; // ignore unused parameter | ||
| 326 | (void) parm; // ignore unused parameter | ||
| 324 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); | 327 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); |
| 325 | 328 | ||
| 326 | return CURLE_OK; | 329 | return CURLE_OK; |
| @@ -375,8 +378,12 @@ void | |||
| 375 | handle_curl_option_return_code (CURLcode res, const char* option) | 378 | handle_curl_option_return_code (CURLcode res, const char* option) |
| 376 | { | 379 | { |
| 377 | if (res != CURLE_OK) { | 380 | if (res != CURLE_OK) { |
| 378 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Error while setting cURL option '%s': cURL returned %d - %s"), | 381 | snprintf (msg, |
| 379 | 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)); | ||
| 380 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 387 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
| 381 | } | 388 | } |
| 382 | } | 389 | } |
| @@ -516,9 +523,13 @@ check_http (void) | |||
| 516 | // 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 |
| 517 | if(use_ssl && host_name != NULL) { | 524 | if(use_ssl && host_name != NULL) { |
| 518 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { | 525 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { |
| 519 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), | 526 | snprintf (msg, |
| 520 | server_address, res, gai_strerror (res)); | 527 | DEFAULT_BUFFER_SIZE, |
| 521 | 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); | ||
| 522 | } | 533 | } |
| 523 | 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); |
| 524 | host = curl_slist_append(NULL, dnscache); | 535 | host = curl_slist_append(NULL, dnscache); |
| @@ -646,7 +657,7 @@ check_http (void) | |||
| 646 | } | 657 | } |
| 647 | 658 | ||
| 648 | /* detect SSL library used by libcurl */ | 659 | /* detect SSL library used by libcurl */ |
| 649 | ssl_library = curlhelp_get_ssl_library (curl); | 660 | ssl_library = curlhelp_get_ssl_library (); |
| 650 | 661 | ||
| 651 | /* try hard to get a stack of certificates to verify against */ | 662 | /* try hard to get a stack of certificates to verify against */ |
| 652 | if (check_cert) { | 663 | if (check_cert) { |
| @@ -816,9 +827,13 @@ check_http (void) | |||
| 816 | 827 | ||
| 817 | /* Curl errors, result in critical Nagios state */ | 828 | /* Curl errors, result in critical Nagios state */ |
| 818 | if (res != CURLE_OK) { | 829 | if (res != CURLE_OK) { |
| 819 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), | 830 | snprintf (msg, |
| 820 | server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res)); | 831 | DEFAULT_BUFFER_SIZE, |
| 821 | 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); | ||
| 822 | } | 837 | } |
| 823 | 838 | ||
| 824 | /* certificate checks */ | 839 | /* certificate checks */ |
| @@ -861,15 +876,19 @@ check_http (void) | |||
| 861 | } | 876 | } |
| 862 | GOT_FIRST_CERT: | 877 | GOT_FIRST_CERT: |
| 863 | if (!raw_cert) { | 878 | if (!raw_cert) { |
| 864 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot retrieve certificates from CERTINFO information - certificate data was empty")); | 879 | snprintf (msg, |
| 865 | 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); | ||
| 866 | } | 883 | } |
| 867 | BIO* cert_BIO = BIO_new (BIO_s_mem()); | 884 | BIO* cert_BIO = BIO_new (BIO_s_mem()); |
| 868 | BIO_write (cert_BIO, raw_cert, strlen(raw_cert)); | 885 | BIO_write (cert_BIO, raw_cert, strlen(raw_cert)); |
| 869 | cert = PEM_read_bio_X509 (cert_BIO, NULL, NULL, NULL); | 886 | cert = PEM_read_bio_X509 (cert_BIO, NULL, NULL, NULL); |
| 870 | if (!cert) { | 887 | if (!cert) { |
| 871 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot read certificate from CERTINFO information - BIO error")); | 888 | snprintf (msg, |
| 872 | 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); | ||
| 873 | } | 892 | } |
| 874 | BIO_free (cert_BIO); | 893 | BIO_free (cert_BIO); |
| 875 | 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); |
| @@ -886,9 +905,12 @@ GOT_FIRST_CERT: | |||
| 886 | } | 905 | } |
| 887 | #endif /* USE_OPENSSL */ | 906 | #endif /* USE_OPENSSL */ |
| 888 | } else { | 907 | } else { |
| 889 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot retrieve certificates - cURL returned %d - %s"), | 908 | snprintf (msg, |
| 890 | res, curl_easy_strerror(res)); | 909 | DEFAULT_BUFFER_SIZE, |
| 891 | 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); | ||
| 892 | } | 914 | } |
| 893 | } | 915 | } |
| 894 | } | 916 | } |
| @@ -927,8 +949,11 @@ GOT_FIRST_CERT: | |||
| 927 | 949 | ||
| 928 | /* get status line of answer, check sanity of HTTP code */ | 950 | /* get status line of answer, check sanity of HTTP code */ |
| 929 | if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { | 951 | if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { |
| 930 | snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n", | 952 | snprintf (msg, |
| 931 | total_time, perfstring); | 953 | DEFAULT_BUFFER_SIZE, |
| 954 | "Unparsable status line in %.3g seconds response time|%s\n", | ||
| 955 | total_time, | ||
| 956 | perfstring); | ||
| 932 | /* 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 */ |
| 933 | 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); |
| 934 | } | 959 | } |
| @@ -948,9 +973,16 @@ GOT_FIRST_CERT: | |||
| 948 | /* 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 */ |
| 949 | if (!expected_statuscode(status_line.first_line, server_expect)) { | 974 | if (!expected_statuscode(status_line.first_line, server_expect)) { |
| 950 | if (server_port == HTTP_PORT) | 975 | if (server_port == HTTP_PORT) |
| 951 | 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); | ||
| 952 | else | 980 | else |
| 953 | 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); | ||
| 954 | die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg, | 986 | die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg, |
| 955 | show_body ? "\n" : "", | 987 | show_body ? "\n" : "", |
| 956 | show_body ? body_buf.buf : ""); | 988 | show_body ? body_buf.buf : ""); |
| @@ -1023,23 +1055,55 @@ GOT_FIRST_CERT: | |||
| 1023 | 1055 | ||
| 1024 | if (strlen (header_expect)) { | 1056 | if (strlen (header_expect)) { |
| 1025 | if (!strstr (header_buf.buf, header_expect)) { | 1057 | if (!strstr (header_buf.buf, header_expect)) { |
| 1058 | |||
| 1026 | strncpy(&output_header_search[0],header_expect,sizeof(output_header_search)); | 1059 | strncpy(&output_header_search[0],header_expect,sizeof(output_header_search)); |
| 1060 | |||
| 1027 | if(output_header_search[sizeof(output_header_search)-1]!='\0') { | 1061 | if(output_header_search[sizeof(output_header_search)-1]!='\0') { |
| 1028 | bcopy("...",&output_header_search[sizeof(output_header_search)-4],4); | 1062 | bcopy("...",&output_header_search[sizeof(output_header_search)-4],4); |
| 1029 | } | 1063 | } |
| 1030 | 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 | |
| 1031 | 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; | ||
| 1032 | } | 1080 | } |
| 1033 | } | 1081 | } |
| 1034 | 1082 | ||
| 1035 | if (strlen (string_expect)) { | 1083 | if (strlen (string_expect)) { |
| 1036 | if (!strstr (body_buf.buf, string_expect)) { | 1084 | if (!strstr (body_buf.buf, string_expect)) { |
| 1085 | |||
| 1037 | strncpy(&output_string_search[0],string_expect,sizeof(output_string_search)); | 1086 | strncpy(&output_string_search[0],string_expect,sizeof(output_string_search)); |
| 1087 | |||
| 1038 | if(output_string_search[sizeof(output_string_search)-1]!='\0') { | 1088 | if(output_string_search[sizeof(output_string_search)-1]!='\0') { |
| 1039 | bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); | 1089 | bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); |
| 1040 | } | 1090 | } |
| 1041 | 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 | |
| 1042 | 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; | ||
| 1043 | } | 1107 | } |
| 1044 | } | 1108 | } |
| 1045 | 1109 | ||
| @@ -1050,27 +1114,48 @@ GOT_FIRST_CERT: | |||
| 1050 | result = max_state_alt(STATE_OK, result); | 1114 | result = max_state_alt(STATE_OK, result); |
| 1051 | } | 1115 | } |
| 1052 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { | 1116 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { |
| 1053 | if (!invert_regex) | 1117 | if (!invert_regex) { |
| 1054 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); | 1118 | char tmp[DEFAULT_BUFFER_SIZE]; |
| 1055 | else | 1119 | |
| 1056 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); | 1120 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); |
| 1057 | result = STATE_CRITICAL; | 1121 | strcpy(msg, tmp); |
| 1058 | } | 1122 | |
| 1059 | else { | 1123 | } else { |
| 1060 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1124 | char tmp[DEFAULT_BUFFER_SIZE]; |
| 1061 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sExecute Error: %s, "), msg, errbuf); | 1125 | |
| 1062 | result = STATE_UNKNOWN; | 1126 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); |
| 1063 | } | 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 | } | ||
| 1064 | } | 1140 | } |
| 1065 | 1141 | ||
| 1066 | /* make sure the page is of an appropriate size */ | 1142 | /* make sure the page is of an appropriate size */ |
| 1067 | if ((max_page_len > 0) && (page_len > max_page_len)) { | 1143 | if ((max_page_len > 0) && (page_len > max_page_len)) { |
| 1068 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); | 1144 | char tmp[DEFAULT_BUFFER_SIZE]; |
| 1069 | result = max_state_alt(STATE_WARNING, result); | 1145 | |
| 1070 | } 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); |
| 1071 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too small, "), msg, page_len); | 1147 | |
| 1072 | result = max_state_alt(STATE_WARNING, result); | 1148 | strcpy(msg, tmp); |
| 1073 | } | 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 | } | ||
| 1074 | 1159 | ||
| 1075 | /* -w, -c: check warning and critical level */ | 1160 | /* -w, -c: check warning and critical level */ |
| 1076 | result = max_state_alt(get_status(total_time, thlds), result); | 1161 | result = max_state_alt(get_status(total_time, thlds), result); |
| @@ -1654,6 +1739,7 @@ process_arguments (int argc, char **argv) | |||
| 1654 | break; | 1739 | break; |
| 1655 | case 'R': /* regex */ | 1740 | case 'R': /* regex */ |
| 1656 | cflags |= REG_ICASE; | 1741 | cflags |= REG_ICASE; |
| 1742 | // fall through | ||
| 1657 | case 'r': /* regex */ | 1743 | case 'r': /* regex */ |
| 1658 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); | 1744 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); |
| 1659 | regexp[MAX_RE_SIZE - 1] = 0; | 1745 | regexp[MAX_RE_SIZE - 1] = 0; |
| @@ -2307,37 +2393,67 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA | |||
| 2307 | server_date = get_header_value (headers, nof_headers, "date"); | 2393 | server_date = get_header_value (headers, nof_headers, "date"); |
| 2308 | document_date = get_header_value (headers, nof_headers, "last-modified"); | 2394 | document_date = get_header_value (headers, nof_headers, "last-modified"); |
| 2309 | 2395 | ||
| 2310 | if (!server_date || !*server_date) { | 2396 | if (!server_date || !*server_date) { |
| 2311 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date unknown, "), *msg); | 2397 | char tmp[DEFAULT_BUFFER_SIZE]; |
| 2312 | date_result = max_state_alt(STATE_UNKNOWN, date_result); | 2398 | |
| 2313 | } else if (!document_date || !*document_date) { | 2399 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sServer date unknown, "), *msg); |
| 2314 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument modification date unknown, "), *msg); | 2400 | strcpy(*msg, tmp); |
| 2315 | 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 | |||
| 2316 | } else { | 2412 | } else { |
| 2317 | time_t srv_data = curl_getdate (server_date, NULL); | 2413 | time_t srv_data = curl_getdate (server_date, NULL); |
| 2318 | time_t doc_data = curl_getdate (document_date, NULL); | 2414 | time_t doc_data = curl_getdate (document_date, NULL); |
| 2319 | if (verbose >= 2) | 2415 | if (verbose >= 2) |
| 2320 | 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); |
| 2321 | if (srv_data <= 0) { | 2417 | if (srv_data <= 0) { |
| 2322 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); | 2418 | char tmp[DEFAULT_BUFFER_SIZE]; |
| 2323 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2419 | |
| 2324 | } else if (doc_data <= 0) { | 2420 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); |
| 2325 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); | 2421 | strcpy(*msg, tmp); |
| 2326 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2422 | |
| 2327 | } else if (doc_data > srv_data + 30) { | 2423 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
| 2328 | 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) { |
| 2329 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2425 | char tmp[DEFAULT_BUFFER_SIZE]; |
| 2330 | } else if (doc_data < srv_data - maximum_age) { | 2426 | |
| 2331 | int n = (srv_data - doc_data); | 2427 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); |
| 2332 | if (n > (60 * 60 * 24 * 2)) { | 2428 | strcpy(*msg, tmp); |
| 2333 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); | 2429 | |
| 2334 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2430 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
| 2335 | } else { | 2431 | } else if (doc_data > srv_data + 30) { |
| 2336 | 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]; |
| 2337 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 2433 | |
| 2338 | } | 2434 | snprintf (tmp, DEFAULT_BUFFER_SIZE, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); |
| 2339 | } | 2435 | strcpy(*msg, tmp); |
| 2340 | } | 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 | } | ||
| 2341 | 2457 | ||
| 2342 | if (server_date) free (server_date); | 2458 | if (server_date) free (server_date); |
| 2343 | if (document_date) free (document_date); | 2459 | if (document_date) free (document_date); |
| @@ -2379,7 +2495,7 @@ get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_wri | |||
| 2379 | 2495 | ||
| 2380 | /* 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? */ |
| 2381 | curlhelp_ssl_library | 2497 | curlhelp_ssl_library |
| 2382 | curlhelp_get_ssl_library (CURL* curl) | 2498 | curlhelp_get_ssl_library () |
| 2383 | { | 2499 | { |
| 2384 | curl_version_info_data* version_data; | 2500 | curl_version_info_data* version_data; |
| 2385 | char *ssl_version; | 2501 | char *ssl_version; |
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index ced13d05..c24ca248 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_fping.c b/plugins/check_fping.c index 6f5656ef..23a9e990 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
| @@ -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 c4b44178..c34bb082 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 6956a726..1288c415 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
| @@ -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; |
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index eafafdc0..49cb1008 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
| @@ -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; |
| @@ -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 proceeding 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_radius.c b/plugins/check_radius.c index 984aa37e..b1b4938c 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
| @@ -381,7 +381,7 @@ print_help (void) | |||
| 381 | printf ("\n"); | 381 | printf ("\n"); |
| 382 | 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.")); |
| 383 | 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")); |
| 384 | 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")); |
| 385 | 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.")); |
| 386 | 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")); |
| 387 | 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_smtp.c b/plugins/check_smtp.c index c0ab838a..fc0ae2c4 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
| @@ -42,15 +42,16 @@ 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 | }; |
| 55 | #define PROXY_PREFIX "PROXY TCP4 0.0.0.0 0.0.0.0 25 25\r\n" | 56 | #define PROXY_PREFIX "PROXY TCP4 0.0.0.0 0.0.0.0 25 25\r\n" |
| 56 | #define SMTP_EXPECT "220" | 57 | #define SMTP_EXPECT "220" |
| @@ -83,6 +84,7 @@ int eflags = 0; | |||
| 83 | int errcode, excode; | 84 | int errcode, excode; |
| 84 | 85 | ||
| 85 | int server_port = SMTP_PORT; | 86 | int server_port = SMTP_PORT; |
| 87 | int server_port_option = 0; | ||
| 86 | char *server_address = NULL; | 88 | char *server_address = NULL; |
| 87 | char *server_expect = NULL; | 89 | char *server_expect = NULL; |
| 88 | char *mail_command = NULL; | 90 | char *mail_command = NULL; |
| @@ -103,6 +105,7 @@ double critical_time = 0; | |||
| 103 | int check_critical_time = FALSE; | 105 | int check_critical_time = FALSE; |
| 104 | int verbose = 0; | 106 | int verbose = 0; |
| 105 | int use_ssl = FALSE; | 107 | int use_ssl = FALSE; |
| 108 | int use_starttls = FALSE; | ||
| 106 | int use_sni = FALSE; | 109 | int use_sni = FALSE; |
| 107 | short use_proxy_prefix = FALSE; | 110 | short use_proxy_prefix = FALSE; |
| 108 | short use_ehlo = FALSE; | 111 | short use_ehlo = FALSE; |
| @@ -186,14 +189,27 @@ main (int argc, char **argv) | |||
| 186 | result = my_tcp_connect (server_address, server_port, &sd); | 189 | result = my_tcp_connect (server_address, server_port, &sd); |
| 187 | 190 | ||
| 188 | if (result == STATE_OK) { /* we connected */ | 191 | if (result == STATE_OK) { /* we connected */ |
| 189 | |||
| 190 | /* If requested, send PROXY header */ | 192 | /* If requested, send PROXY header */ |
| 191 | if (use_proxy_prefix) { | 193 | if (use_proxy_prefix) { |
| 192 | if (verbose) | 194 | if (verbose) |
| 193 | printf ("Sending header %s\n", PROXY_PREFIX); | 195 | printf ("Sending header %s\n", PROXY_PREFIX); |
| 194 | send(sd, PROXY_PREFIX, strlen(PROXY_PREFIX), 0); | 196 | my_send(PROXY_PREFIX, strlen(PROXY_PREFIX)); |
| 195 | } | 197 | } |
| 196 | 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 | ||
| 212 | |||
| 197 | /* watch for the SMTP connection string and */ | 213 | /* watch for the SMTP connection string and */ |
| 198 | /* return a WARNING status if we couldn't read any data */ | 214 | /* return a WARNING status if we couldn't read any data */ |
| 199 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { | 215 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { |
| @@ -205,7 +221,7 @@ main (int argc, char **argv) | |||
| 205 | xasprintf(&server_response, "%s", buffer); | 221 | xasprintf(&server_response, "%s", buffer); |
| 206 | 222 | ||
| 207 | /* send the HELO/EHLO command */ | 223 | /* send the HELO/EHLO command */ |
| 208 | send(sd, helocmd, strlen(helocmd), 0); | 224 | my_send(helocmd, strlen(helocmd)); |
| 209 | 225 | ||
| 210 | /* allow for response to helo command to reach us */ | 226 | /* allow for response to helo command to reach us */ |
| 211 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { | 227 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { |
| @@ -218,14 +234,14 @@ main (int argc, char **argv) | |||
| 218 | } | 234 | } |
| 219 | } | 235 | } |
| 220 | 236 | ||
| 221 | if(use_ssl && ! supports_tls){ | 237 | if(use_starttls && ! supports_tls){ |
| 222 | printf(_("WARNING - TLS not supported by server\n")); | 238 | printf(_("WARNING - TLS not supported by server\n")); |
| 223 | smtp_quit(); | 239 | smtp_quit(); |
| 224 | return STATE_WARNING; | 240 | return STATE_WARNING; |
| 225 | } | 241 | } |
| 226 | 242 | ||
| 227 | #ifdef HAVE_SSL | 243 | #ifdef HAVE_SSL |
| 228 | if(use_ssl) { | 244 | if(use_starttls) { |
| 229 | /* send the STARTTLS command */ | 245 | /* send the STARTTLS command */ |
| 230 | send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0); | 246 | send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0); |
| 231 | 247 | ||
| @@ -489,6 +505,8 @@ process_arguments (int argc, char **argv) | |||
| 489 | {"use-ipv6", no_argument, 0, '6'}, | 505 | {"use-ipv6", no_argument, 0, '6'}, |
| 490 | {"help", no_argument, 0, 'h'}, | 506 | {"help", no_argument, 0, 'h'}, |
| 491 | {"lmtp", no_argument, 0, 'L'}, | 507 | {"lmtp", no_argument, 0, 'L'}, |
| 508 | {"ssl", no_argument, 0, 's'}, | ||
| 509 | {"tls", no_argument, 0, 's'}, | ||
| 492 | {"starttls",no_argument,0,'S'}, | 510 | {"starttls",no_argument,0,'S'}, |
| 493 | {"sni", no_argument, 0, SNI_OPTION}, | 511 | {"sni", no_argument, 0, SNI_OPTION}, |
| 494 | {"certificate",required_argument,0,'D'}, | 512 | {"certificate",required_argument,0,'D'}, |
| @@ -510,7 +528,7 @@ process_arguments (int argc, char **argv) | |||
| 510 | } | 528 | } |
| 511 | 529 | ||
| 512 | while (1) { | 530 | while (1) { |
| 513 | c = getopt_long (argc, argv, "+hVv46Lrt: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", |
| 514 | longopts, &option); | 532 | longopts, &option); |
| 515 | 533 | ||
| 516 | if (c == -1 || c == EOF) | 534 | if (c == -1 || c == EOF) |
| @@ -527,7 +545,7 @@ process_arguments (int argc, char **argv) | |||
| 527 | break; | 545 | break; |
| 528 | case 'p': /* port */ | 546 | case 'p': /* port */ |
| 529 | if (is_intpos (optarg)) | 547 | if (is_intpos (optarg)) |
| 530 | server_port = atoi (optarg); | 548 | server_port_option = atoi (optarg); |
| 531 | else | 549 | else |
| 532 | usage4 (_("Port must be a positive integer")); | 550 | usage4 (_("Port must be a positive integer")); |
| 533 | break; | 551 | break; |
| @@ -632,9 +650,14 @@ process_arguments (int argc, char **argv) | |||
| 632 | #else | 650 | #else |
| 633 | usage (_("SSL support not available - install OpenSSL and recompile")); | 651 | usage (_("SSL support not available - install OpenSSL and recompile")); |
| 634 | #endif | 652 | #endif |
| 653 | case 's': | ||
| 654 | /* ssl */ | ||
| 655 | use_ssl = TRUE; | ||
| 656 | server_port = SMTPS_PORT; | ||
| 657 | break; | ||
| 635 | case 'S': | 658 | case 'S': |
| 636 | /* starttls */ | 659 | /* starttls */ |
| 637 | use_ssl = TRUE; | 660 | use_starttls = TRUE; |
| 638 | use_ehlo = TRUE; | 661 | use_ehlo = TRUE; |
| 639 | break; | 662 | break; |
| 640 | case SNI_OPTION: | 663 | case SNI_OPTION: |
| @@ -693,6 +716,14 @@ process_arguments (int argc, char **argv) | |||
| 693 | if (from_arg==NULL) | 716 | if (from_arg==NULL) |
| 694 | from_arg = strdup(" "); | 717 | from_arg = strdup(" "); |
| 695 | 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 | |||
| 696 | return validate_arguments (); | 727 | return validate_arguments (); |
| 697 | } | 728 | } |
| 698 | 729 | ||
| @@ -850,6 +881,9 @@ print_help (void) | |||
| 850 | #ifdef HAVE_SSL | 881 | #ifdef HAVE_SSL |
| 851 | printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]"); | 882 | printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]"); |
| 852 | 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); | ||
| 853 | printf (" %s\n", "-S, --starttls"); | 887 | printf (" %s\n", "-S, --starttls"); |
| 854 | printf (" %s\n", _("Use STARTTLS for the connection.")); | 888 | printf (" %s\n", _("Use STARTTLS for the connection.")); |
| 855 | printf (" %s\n", "--sni"); | 889 | printf (" %s\n", "--sni"); |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index c425df3c..2acada22 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -65,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | 65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 |
| 66 | #define L_INVERT_SEARCH CHAR_MAX+3 | 66 | #define L_INVERT_SEARCH CHAR_MAX+3 |
| 67 | #define L_OFFSET CHAR_MAX+4 | 67 | #define L_OFFSET CHAR_MAX+4 |
| 68 | #define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 | ||
| 68 | 69 | ||
| 69 | /* 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 |
| 70 | * characters in s */ | 71 | * characters in s */ |
| @@ -159,6 +160,7 @@ char* ip_version = ""; | |||
| 159 | double multiplier = 1.0; | 160 | double multiplier = 1.0; |
| 160 | char *fmtstr = ""; | 161 | char *fmtstr = ""; |
| 161 | char buffer[DEFAULT_BUFFER_SIZE]; | 162 | char buffer[DEFAULT_BUFFER_SIZE]; |
| 163 | bool ignore_mib_parsing_errors = false; | ||
| 162 | 164 | ||
| 163 | static char *fix_snmp_range(char *th) | 165 | static char *fix_snmp_range(char *th) |
| 164 | { | 166 | { |
| @@ -306,42 +308,55 @@ main (int argc, char **argv) | |||
| 306 | } | 308 | } |
| 307 | 309 | ||
| 308 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 310 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
| 309 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 311 | |
| 310 | command_line[0] = snmpcmd; | 312 | unsigned index = 0; |
| 311 | command_line[1] = strdup ("-Le"); | 313 | command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
| 312 | command_line[2] = strdup ("-t"); | 314 | |
| 313 | xasprintf (&command_line[3], "%d", timeout_interval); | 315 | command_line[index++] = snmpcmd; |
| 314 | command_line[4] = strdup ("-r"); | 316 | command_line[index++] = strdup ("-Le"); |
| 315 | xasprintf (&command_line[5], "%d", retries); | 317 | command_line[index++] = strdup ("-t"); |
| 316 | command_line[6] = strdup ("-m"); | 318 | xasprintf (&command_line[index++], "%d", timeout_interval); |
| 317 | command_line[7] = strdup (miblist); | 319 | command_line[index++] = strdup ("-r"); |
| 318 | command_line[8] = "-v"; | 320 | xasprintf (&command_line[index++], "%d", retries); |
| 319 | command_line[9] = strdup (proto); | 321 | command_line[index++] = strdup ("-m"); |
| 322 | command_line[index++] = strdup (miblist); | ||
| 323 | command_line[index++] = "-v"; | ||
| 324 | command_line[index++] = strdup (proto); | ||
| 325 | |||
| 326 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", | ||
| 327 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); | ||
| 328 | |||
| 329 | if (ignore_mib_parsing_errors) { | ||
| 330 | command_line[index++] = "-Pe"; | ||
| 331 | xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); | ||
| 332 | } | ||
| 333 | |||
| 320 | 334 | ||
| 321 | for (i = 0; i < numcontext; i++) { | 335 | for (i = 0; i < numcontext; i++) { |
| 322 | command_line[10 + i] = contextargs[i]; | 336 | command_line[index++] = contextargs[i]; |
| 323 | } | 337 | } |
| 324 | 338 | ||
| 325 | for (i = 0; i < numauthpriv; i++) { | 339 | for (i = 0; i < numauthpriv; i++) { |
| 326 | command_line[10 + numcontext + i] = authpriv[i]; | 340 | command_line[index++] = authpriv[i]; |
| 327 | } | 341 | } |
| 328 | 342 | ||
| 329 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); | 343 | xasprintf (&command_line[index++], "%s:%s", server_address, port); |
| 330 | 344 | ||
| 331 | /* This is just for display purposes, so it can remain a string */ | 345 | xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", |
| 332 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", | 346 | cl_hidden_auth, |
| 333 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", | 347 | server_address, |
| 334 | server_address, port); | 348 | port); |
| 335 | 349 | ||
| 336 | for (i = 0; i < numoids; i++) { | 350 | for (i = 0; i < numoids; i++) { |
| 337 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; | 351 | command_line[index++] = oids[i]; |
| 338 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 352 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
| 339 | } | 353 | } |
| 340 | 354 | ||
| 341 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; | 355 | command_line[index++] = NULL; |
| 342 | 356 | ||
| 343 | if (verbose) | 357 | if (verbose) { |
| 344 | printf ("%s\n", cl_hidden_auth); | 358 | printf ("%s\n", cl_hidden_auth); |
| 359 | } | ||
| 345 | 360 | ||
| 346 | /* Set signal handling and alarm */ | 361 | /* Set signal handling and alarm */ |
| 347 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { | 362 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
| @@ -708,6 +723,7 @@ process_arguments (int argc, char **argv) | |||
| 708 | {"ipv6", no_argument, 0, '6'}, | 723 | {"ipv6", no_argument, 0, '6'}, |
| 709 | {"multiplier", required_argument, 0, 'M'}, | 724 | {"multiplier", required_argument, 0, 'M'}, |
| 710 | {"fmtstr", required_argument, 0, 'f'}, | 725 | {"fmtstr", required_argument, 0, 'f'}, |
| 726 | {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, | ||
| 711 | {0, 0, 0, 0} | 727 | {0, 0, 0, 0} |
| 712 | }; | 728 | }; |
| 713 | 729 | ||
| @@ -855,6 +871,7 @@ process_arguments (int argc, char **argv) | |||
| 855 | break; | 871 | break; |
| 856 | case 'R': /* regex */ | 872 | case 'R': /* regex */ |
| 857 | cflags = REG_ICASE; | 873 | cflags = REG_ICASE; |
| 874 | // fall through | ||
| 858 | case 'r': /* regex */ | 875 | case 'r': /* regex */ |
| 859 | cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; | 876 | cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; |
| 860 | strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); | 877 | strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); |
| @@ -973,6 +990,8 @@ process_arguments (int argc, char **argv) | |||
| 973 | fmtstr=optarg; | 990 | fmtstr=optarg; |
| 974 | } | 991 | } |
| 975 | break; | 992 | break; |
| 993 | case L_IGNORE_MIB_PARSING_ERRORS: | ||
| 994 | ignore_mib_parsing_errors = true; | ||
| 976 | } | 995 | } |
| 977 | } | 996 | } |
| 978 | 997 | ||
| @@ -1306,6 +1325,9 @@ print_help (void) | |||
| 1306 | printf (" %s\n", "-O, --perf-oids"); | 1325 | printf (" %s\n", "-O, --perf-oids"); |
| 1307 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1326 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
| 1308 | 1327 | ||
| 1328 | printf (" %s\n", "--ignore-mib-parsing-errors"); | ||
| 1329 | printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); | ||
| 1330 | |||
| 1309 | printf (UT_VERBOSE); | 1331 | printf (UT_VERBOSE); |
| 1310 | 1332 | ||
| 1311 | printf ("\n"); | 1333 | printf ("\n"); |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 05f19ad4..cd965e31 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
| @@ -178,7 +178,7 @@ main (int argc, char **argv) | |||
| 178 | # ifdef _AIX | 178 | # ifdef _AIX |
| 179 | if (!allswaps) { | 179 | if (!allswaps) { |
| 180 | xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); | 180 | xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); |
| 181 | xasprintf(&swap_format, "%s", "%f%*s %f"); | 181 | xasprintf(&swap_format, "%s", "%lu%*s %lu"); |
| 182 | conv_factor = 1; | 182 | conv_factor = 1; |
| 183 | } | 183 | } |
| 184 | # endif | 184 | # endif |
| @@ -205,9 +205,9 @@ main (int argc, char **argv) | |||
| 205 | temp_buffer = strtok (input_buffer, " \n"); | 205 | temp_buffer = strtok (input_buffer, " \n"); |
| 206 | while (temp_buffer) { | 206 | while (temp_buffer) { |
| 207 | if (strstr (temp_buffer, "blocks")) | 207 | if (strstr (temp_buffer, "blocks")) |
| 208 | sprintf (str, "%s %s", str, "%f"); | 208 | sprintf (str, "%s %s", str, "%lu"); |
| 209 | else if (strstr (temp_buffer, "dskfree")) | 209 | else if (strstr (temp_buffer, "dskfree")) |
| 210 | sprintf (str, "%s %s", str, "%f"); | 210 | sprintf (str, "%s %s", str, "%lu"); |
| 211 | else | 211 | else |
| 212 | sprintf (str, "%s %s", str, "%*s"); | 212 | sprintf (str, "%s %s", str, "%*s"); |
| 213 | temp_buffer = strtok (NULL, " \n"); | 213 | temp_buffer = strtok (NULL, " \n"); |
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 12bce217..68737c4b 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]; |
diff --git a/plugins/check_users.c b/plugins/check_users.c index f6f4b362..2a9ee986 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/t/check_smtp.t b/plugins/t/check_smtp.t index aa6dae45..1a1ebe3e 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 f2f218fd..576cc506 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 | } |
