summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-11-25 12:31:00 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-11-25 12:31:00 +0100
commit07d3eb9e2c729b6ab5effc0f664b6d5d9958fa72 (patch)
treecaf834fe566d59dd50481b1445be453076407583
parent983519d07d5ddf3e0cb99282fda6583bba2a6e96 (diff)
downloadmonitoring-plugins-07d3eb9e2c729b6ab5effc0f664b6d5d9958fa72.tar.gz
check_ldap: modern output implementation
-rw-r--r--plugins/check_ldap.c310
-rw-r--r--plugins/check_ldap.d/config.h18
-rw-r--r--plugins/t/check_ldap.t14
3 files changed, 207 insertions, 135 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 77a33304..f1380be4 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -27,12 +27,11 @@
27 *****************************************************************************/ 27 *****************************************************************************/
28 28
29/* progname may be check_ldaps */ 29/* progname may be check_ldaps */
30char *progname = "check_ldap"; 30#include "output.h"
31const char *copyright = "2000-2024";
32const char *email = "devel@monitoring-plugins.org";
33
34#include "common.h" 31#include "common.h"
35#include "netutils.h" 32#include "netutils.h"
33#include "perfdata.h"
34#include "thresholds.h"
36#include "utils.h" 35#include "utils.h"
37#include "check_ldap.d/config.h" 36#include "check_ldap.d/config.h"
38 37
@@ -41,6 +40,10 @@ const char *email = "devel@monitoring-plugins.org";
41#define LDAP_DEPRECATED 1 40#define LDAP_DEPRECATED 1
42#include <ldap.h> 41#include <ldap.h>
43 42
43char *progname = "check_ldap";
44const char *copyright = "2000-2024";
45const char *email = "devel@monitoring-plugins.org";
46
44enum { 47enum {
45 DEFAULT_PORT = 389 48 DEFAULT_PORT = 389
46}; 49};
@@ -89,101 +92,172 @@ int main(int argc, char *argv[]) {
89 struct timeval start_time; 92 struct timeval start_time;
90 gettimeofday(&start_time, NULL); 93 gettimeofday(&start_time, NULL);
91 94
95 mp_check overall = mp_check_init();
96
92 LDAP *ldap_connection; 97 LDAP *ldap_connection;
93 /* initialize ldap */ 98 /* initialize ldap */
99 {
94#ifdef HAVE_LDAP_INIT 100#ifdef HAVE_LDAP_INIT
95 if (!(ldap_connection = ldap_init(config.ld_host, config.ld_port))) { 101 mp_subcheck sc_ldap_init = mp_subcheck_init();
96 printf("Could not connect to the server at port %i\n", config.ld_port); 102 if (!(ldap_connection = ldap_init(config.ld_host, config.ld_port))) {
97 return STATE_CRITICAL; 103 xasprintf(&sc_ldap_init.output, "could not connect to the server at port %i",
98 } 104 config.ld_port);
105 sc_ldap_init = mp_set_subcheck_state(sc_ldap_init, STATE_CRITICAL);
106 mp_add_subcheck_to_check(&overall, sc_ldap_init);
107 mp_exit(overall);
108 } else {
109 xasprintf(&sc_ldap_init.output, "connected to the server at port %i", config.ld_port);
110 sc_ldap_init = mp_set_subcheck_state(sc_ldap_init, STATE_OK);
111 mp_add_subcheck_to_check(&overall, sc_ldap_init);
112 }
99#else 113#else
100 if (!(ld = ldap_open(config.ld_host, config.ld_port))) { 114 mp_subcheck sc_ldap_init = mp_subcheck_init();
101 if (verbose) { 115 if (!(ld = ldap_open(config.ld_host, config.ld_port))) {
102 ldap_perror(ldap_connection, "ldap_open"); 116 if (verbose) {
117 ldap_perror(ldap_connection, "ldap_open");
118 }
119 xasprintf(&sc_ldap_init.output, "Could not connect to the server at port %i"), config.ld_port);
120 sc_ldap_init = mp_set_subcheck_state(sc_ldap_init, STATE_CRITICAL);
121 mp_add_subcheck_to_check(&overall, sc_ldap_init);
122 mp_exit(overall);
123 } else {
124 xasprintf(&sc_ldap_init.output, "connected to the server at port %i", config.ld_port);
125 sc_ldap_init = mp_set_subcheck_state(sc_ldap_init, STATE_OK);
126 mp_add_subcheck_to_check(&overall, sc_ldap_init);
103 } 127 }
104 printf(_("Could not connect to the server at port %i\n"), config.ld_port);
105 return STATE_CRITICAL;
106 }
107#endif /* HAVE_LDAP_INIT */ 128#endif /* HAVE_LDAP_INIT */
129 }
108 130
109#ifdef HAVE_LDAP_SET_OPTION 131#ifdef HAVE_LDAP_SET_OPTION
110 /* set ldap options */ 132 /* set ldap options */
133 mp_subcheck sc_ldap_set_opts = mp_subcheck_init();
111 if (ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &config.ld_protocol) != 134 if (ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &config.ld_protocol) !=
112 LDAP_OPT_SUCCESS) { 135 LDAP_OPT_SUCCESS) {
113 printf(_("Could not set protocol version %d\n"), config.ld_protocol); 136 xasprintf(&sc_ldap_set_opts.output, "Could not set protocol version %d",
114 return STATE_CRITICAL; 137 config.ld_protocol);
138 sc_ldap_set_opts = mp_set_subcheck_state(sc_ldap_set_opts, STATE_CRITICAL);
139 mp_add_subcheck_to_check(&overall, sc_ldap_set_opts);
140 mp_exit(overall);
141 } else {
142 xasprintf(&sc_ldap_set_opts.output, "set protocol version %d", config.ld_protocol);
143 sc_ldap_set_opts = mp_set_subcheck_state(sc_ldap_set_opts, STATE_OK);
144 mp_add_subcheck_to_check(&overall, sc_ldap_set_opts);
115 } 145 }
116#endif 146#endif
117 147
118 int version = 3; 148 int version = 3;
119 int tls; 149 int tls;
120 if (config.ld_port == LDAPS_PORT || config.ssl_on_connect) { 150 {
151 if (config.ld_port == LDAPS_PORT || config.ssl_on_connect) {
121#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS) 152#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS)
122 /* ldaps: set option tls */ 153 /* ldaps: set option tls */
123 tls = LDAP_OPT_X_TLS_HARD; 154 tls = LDAP_OPT_X_TLS_HARD;
124 155
125 if (ldap_set_option(ldap_connection, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS) { 156 mp_subcheck sc_ldap_tls_init = mp_subcheck_init();
126 if (verbose) { 157 if (ldap_set_option(ldap_connection, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS) {
127 ldap_perror(ldap_connection, "ldaps_option"); 158 if (verbose) {
159 ldap_perror(ldap_connection, "ldaps_option");
160 }
161 xasprintf(&sc_ldap_tls_init.output, "could not init TLS at port %i!",
162 config.ld_port);
163 sc_ldap_tls_init = mp_set_subcheck_state(sc_ldap_tls_init, STATE_CRITICAL);
164 mp_add_subcheck_to_check(&overall, sc_ldap_tls_init);
165 mp_exit(overall);
166 } else {
167 xasprintf(&sc_ldap_tls_init.output, "initiated TLS at port %i!", config.ld_port);
168 sc_ldap_tls_init = mp_set_subcheck_state(sc_ldap_tls_init, STATE_OK);
169 mp_add_subcheck_to_check(&overall, sc_ldap_tls_init);
128 } 170 }
129 printf(_("Could not init TLS at port %i!\n"), config.ld_port);
130 return STATE_CRITICAL;
131 }
132#else 171#else
133 printf(_("TLS not supported by the libraries!\n")); 172 printf(_("TLS not supported by the libraries!\n"));
134 return STATE_CRITICAL; 173 exit(STATE_CRITICAL);
135#endif /* LDAP_OPT_X_TLS */ 174#endif /* LDAP_OPT_X_TLS */
136 } else if (config.starttls) { 175 } else if (config.starttls) {
137#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S) 176#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S)
138 /* ldap with startTLS: set option version */ 177 /* ldap with startTLS: set option version */
139 if (ldap_get_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version) == 178 if (ldap_get_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version) ==
140 LDAP_OPT_SUCCESS) { 179 LDAP_OPT_SUCCESS) {
141 if (version < LDAP_VERSION3) { 180 if (version < LDAP_VERSION3) {
142 version = LDAP_VERSION3; 181 version = LDAP_VERSION3;
143 ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version); 182 ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version);
183 }
144 } 184 }
145 } 185 /* call start_tls */
146 /* call start_tls */ 186 mp_subcheck sc_ldap_starttls = mp_subcheck_init();
147 if (ldap_start_tls_s(ldap_connection, NULL, NULL) != LDAP_SUCCESS) { 187 if (ldap_start_tls_s(ldap_connection, NULL, NULL) != LDAP_SUCCESS) {
148 if (verbose) { 188 if (verbose) {
149 ldap_perror(ldap_connection, "ldap_start_tls"); 189 ldap_perror(ldap_connection, "ldap_start_tls");
190 }
191 xasprintf(&sc_ldap_starttls.output, "could not init STARTTLS at port %i!",
192 config.ld_port);
193 sc_ldap_starttls = mp_set_subcheck_state(sc_ldap_starttls, STATE_CRITICAL);
194 mp_add_subcheck_to_check(&overall, sc_ldap_starttls);
195 mp_exit(overall);
196 } else {
197 xasprintf(&sc_ldap_starttls.output, "initiated STARTTLS at port %i!",
198 config.ld_port);
199 sc_ldap_starttls = mp_set_subcheck_state(sc_ldap_starttls, STATE_OK);
200 mp_add_subcheck_to_check(&overall, sc_ldap_starttls);
150 } 201 }
151 printf(_("Could not init startTLS at port %i!\n"), config.ld_port);
152 return STATE_CRITICAL;
153 }
154#else 202#else
155 printf(_("startTLS not supported by the library, needs LDAPv3!\n")); 203 printf(_("startTLS not supported by the library, needs LDAPv3!\n"));
156 return STATE_CRITICAL; 204 exit(STATE_CRITICAL);
157#endif /* HAVE_LDAP_START_TLS_S */ 205#endif /* HAVE_LDAP_START_TLS_S */
206 }
158 } 207 }
159 208
160 /* bind to the ldap server */ 209 /* bind to the ldap server */
161 if (ldap_bind_s(ldap_connection, config.ld_binddn, config.ld_passwd, LDAP_AUTH_SIMPLE) != 210 {
162 LDAP_SUCCESS) { 211 mp_subcheck sc_ldap_bind = mp_subcheck_init();
163 if (verbose) { 212 int ldap_error =
164 ldap_perror(ldap_connection, "ldap_bind"); 213 ldap_bind_s(ldap_connection, config.ld_binddn, config.ld_passwd, LDAP_AUTH_SIMPLE);
214 if (ldap_error != LDAP_SUCCESS) {
215 if (verbose) {
216 ldap_perror(ldap_connection, "ldap_bind");
217 }
218
219 xasprintf(&sc_ldap_bind.output, "could not bind to the LDAP server: %s",
220 ldap_err2string(ldap_error));
221 sc_ldap_bind = mp_set_subcheck_state(sc_ldap_bind, STATE_CRITICAL);
222 mp_add_subcheck_to_check(&overall, sc_ldap_bind);
223 mp_exit(overall);
224 } else {
225 xasprintf(&sc_ldap_bind.output, "execute bind to the LDAP server");
226 sc_ldap_bind = mp_set_subcheck_state(sc_ldap_bind, STATE_OK);
227 mp_add_subcheck_to_check(&overall, sc_ldap_bind);
165 } 228 }
166 printf(_("Could not bind to the LDAP server\n"));
167 return STATE_CRITICAL;
168 } 229 }
169 230
170 LDAPMessage *result; 231 LDAPMessage *result;
171 int num_entries = 0;
172 /* do a search of all objectclasses in the base dn */ 232 /* do a search of all objectclasses in the base dn */
173 if (ldap_search_s(ldap_connection, config.ld_base, 233 {
174 (config.crit_entries != NULL || config.warn_entries != NULL) 234 mp_subcheck sc_ldap_search = mp_subcheck_init();
175 ? LDAP_SCOPE_SUBTREE 235 int ldap_error = ldap_search_s(
176 : LDAP_SCOPE_BASE, 236 ldap_connection, config.ld_base,
177 config.ld_attr, NULL, 0, &result) != LDAP_SUCCESS) { 237 (config.entries_thresholds.warning_is_set || config.entries_thresholds.critical_is_set)
178 if (verbose) { 238 ? LDAP_SCOPE_SUBTREE
179 ldap_perror(ldap_connection, "ldap_search"); 239 : LDAP_SCOPE_BASE,
240 config.ld_attr, NULL, 0, &result);
241
242 if (ldap_error != LDAP_SUCCESS) {
243 if (verbose) {
244 ldap_perror(ldap_connection, "ldap_search");
245 }
246 xasprintf(&sc_ldap_search.output, "could not search/find objectclasses in %s: %s",
247 config.ld_base, ldap_err2string(ldap_error));
248 sc_ldap_search = mp_set_subcheck_state(sc_ldap_search, STATE_CRITICAL);
249 mp_add_subcheck_to_check(&overall, sc_ldap_search);
250 mp_exit(overall);
251 } else {
252 xasprintf(&sc_ldap_search.output, "search/find objectclasses in %s", config.ld_base);
253 sc_ldap_search = mp_set_subcheck_state(sc_ldap_search, STATE_OK);
254 mp_add_subcheck_to_check(&overall, sc_ldap_search);
180 } 255 }
181 printf(_("Could not search/find objectclasses in %s\n"), config.ld_base);
182 return STATE_CRITICAL;
183 } 256 }
184 257
185 if (config.crit_entries != NULL || config.warn_entries != NULL) { 258 int num_entries = ldap_count_entries(ldap_connection, result);
186 num_entries = ldap_count_entries(ldap_connection, result); 259 if (verbose) {
260 printf("entries found: %d\n", num_entries);
187 } 261 }
188 262
189 /* unbind from the ldap server */ 263 /* unbind from the ldap server */
@@ -193,46 +267,41 @@ int main(int argc, char *argv[]) {
193 alarm(0); 267 alarm(0);
194 268
195 /* calculate the elapsed time and compare to thresholds */ 269 /* calculate the elapsed time and compare to thresholds */
196
197 long microsec = deltime(start_time); 270 long microsec = deltime(start_time);
198 double elapsed_time = (double)microsec / 1.0e6; 271 double elapsed_time = (double)microsec / 1.0e6;
199 mp_state_enum status = STATE_UNKNOWN; 272 mp_perfdata pd_connection_time = perfdata_init();
200 if (config.crit_time_set && elapsed_time > config.crit_time) { 273 pd_connection_time.label = "time";
201 status = STATE_CRITICAL; 274 pd_connection_time.value = mp_create_pd_value(elapsed_time);
202 } else if (config.warn_time_set && elapsed_time > config.warn_time) { 275 pd_connection_time = mp_pd_set_thresholds(pd_connection_time, config.connection_time_threshold);
203 status = STATE_WARNING;
204 } else {
205 status = STATE_OK;
206 }
207 276
208 if (config.entries_thresholds != NULL) { 277 mp_subcheck sc_connection_time = mp_subcheck_init();
209 if (verbose) { 278 mp_add_perfdata_to_subcheck(&sc_connection_time, pd_connection_time);
210 printf("entries found: %d\n", num_entries); 279
211 print_thresholds("entry thresholds", config.entries_thresholds); 280 mp_state_enum connection_time_state = mp_get_pd_status(pd_connection_time);
212 } 281 sc_connection_time = mp_set_subcheck_state(sc_connection_time, connection_time_state);
213 mp_state_enum status_entries = get_status(num_entries, config.entries_thresholds);
214 if (status_entries == STATE_CRITICAL) {
215 status = STATE_CRITICAL;
216 } else if (status != STATE_CRITICAL) {
217 status = status_entries;
218 }
219 }
220 282
221 /* print out the result */ 283 if (connection_time_state == STATE_OK) {
222 if (config.crit_entries != NULL || config.warn_entries != NULL) { 284 xasprintf(&sc_connection_time.output, "connection time %.3fs is withing thresholds",
223 printf(_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), state_text(status), 285 elapsed_time);
224 num_entries, elapsed_time,
225 fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time,
226 config.crit_time_set, config.crit_time, true, 0, false, 0),
227 sperfdata("entries", (double)num_entries, "", config.warn_entries,
228 config.crit_entries, true, 0.0, false, 0.0));
229 } else { 286 } else {
230 printf(_("LDAP %s - %.3f seconds response time|%s\n"), state_text(status), elapsed_time, 287 xasprintf(&sc_connection_time.output, "connection time %.3fs is violating thresholds",
231 fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, 288 elapsed_time);
232 config.crit_time_set, config.crit_time, true, 0, false, 0));
233 } 289 }
234 290
235 exit(status); 291 mp_add_subcheck_to_check(&overall, sc_connection_time);
292
293 mp_perfdata pd_num_entries = perfdata_init();
294 pd_num_entries.label = "entries";
295 pd_num_entries.value = mp_create_pd_value(num_entries);
296 pd_num_entries = mp_pd_set_thresholds(pd_num_entries, config.entries_thresholds);
297
298 mp_subcheck sc_num_entries = mp_subcheck_init();
299 xasprintf(&sc_num_entries.output, "found %d entries", num_entries);
300 sc_num_entries = mp_set_subcheck_state(sc_num_entries, mp_get_pd_status(pd_num_entries));
301
302 mp_add_subcheck_to_check(&overall, sc_num_entries);
303
304 mp_exit(overall);
236} 305}
237 306
238/* process command-line arguments */ 307/* process command-line arguments */
@@ -319,20 +388,38 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
319 case 'P': 388 case 'P':
320 result.config.ld_passwd = optarg; 389 result.config.ld_passwd = optarg;
321 break; 390 break;
322 case 'w': 391 case 'w': {
323 result.config.warn_time_set = true; 392 mp_range_parsed tmp = mp_parse_range_string(optarg);
324 result.config.warn_time = strtod(optarg, NULL); 393 if (tmp.error != MP_PARSING_SUCCES) {
325 break; 394 die(STATE_UNKNOWN, "failed to parse warning connection time threshold");
326 case 'c': 395 }
327 result.config.crit_time_set = true; 396 result.config.connection_time_threshold =
328 result.config.crit_time = strtod(optarg, NULL); 397 mp_thresholds_set_warn(result.config.connection_time_threshold, tmp.range);
329 break; 398 } break;
330 case 'W': 399 case 'c': {
331 result.config.warn_entries = optarg; 400 mp_range_parsed tmp = mp_parse_range_string(optarg);
332 break; 401 if (tmp.error != MP_PARSING_SUCCES) {
333 case 'C': 402 die(STATE_UNKNOWN, "failed to parse critical connection time threshold");
334 result.config.crit_entries = optarg; 403 }
335 break; 404 result.config.connection_time_threshold =
405 mp_thresholds_set_crit(result.config.connection_time_threshold, tmp.range);
406 } break;
407 case 'W': {
408 mp_range_parsed tmp = mp_parse_range_string(optarg);
409 if (tmp.error != MP_PARSING_SUCCES) {
410 die(STATE_UNKNOWN, "failed to parse number of entries warning threshold");
411 }
412 result.config.connection_time_threshold =
413 mp_thresholds_set_warn(result.config.entries_thresholds, tmp.range);
414 } break;
415 case 'C': {
416 mp_range_parsed tmp = mp_parse_range_string(optarg);
417 if (tmp.error != MP_PARSING_SUCCES) {
418 die(STATE_UNKNOWN, "failed to parse number of entries critical threshold");
419 }
420 result.config.connection_time_threshold =
421 mp_thresholds_set_crit(result.config.entries_thresholds, tmp.range);
422 } break;
336#ifdef HAVE_LDAP_SET_OPTION 423#ifdef HAVE_LDAP_SET_OPTION
337 case '2': 424 case '2':
338 result.config.ld_protocol = 2; 425 result.config.ld_protocol = 2;
@@ -406,11 +493,6 @@ check_ldap_config_wrapper validate_arguments(check_ldap_config_wrapper config_wr
406 usage4(_("Please specify the LDAP base\n")); 493 usage4(_("Please specify the LDAP base\n"));
407 } 494 }
408 495
409 if (config_wrapper.config.crit_entries != NULL || config_wrapper.config.warn_entries != NULL) {
410 set_thresholds(&config_wrapper.config.entries_thresholds,
411 config_wrapper.config.warn_entries, config_wrapper.config.crit_entries);
412 }
413
414 if (config_wrapper.config.ld_passwd == NULL) { 496 if (config_wrapper.config.ld_passwd == NULL) {
415 config_wrapper.config.ld_passwd = getenv("LDAP_PASSWORD"); 497 config_wrapper.config.ld_passwd = getenv("LDAP_PASSWORD");
416 } 498 }
diff --git a/plugins/check_ldap.d/config.h b/plugins/check_ldap.d/config.h
index c8a40610..9e6bb845 100644
--- a/plugins/check_ldap.d/config.h
+++ b/plugins/check_ldap.d/config.h
@@ -25,13 +25,8 @@ typedef struct {
25 int ld_protocol; 25 int ld_protocol;
26#endif 26#endif
27 27
28 char *warn_entries; 28 mp_thresholds entries_thresholds;
29 char *crit_entries; 29 mp_thresholds connection_time_threshold;
30 thresholds *entries_thresholds;
31 bool warn_time_set;
32 double warn_time;
33 bool crit_time_set;
34 double crit_time;
35} check_ldap_config; 30} check_ldap_config;
36 31
37check_ldap_config check_ldap_config_init() { 32check_ldap_config check_ldap_config_init() {
@@ -48,13 +43,8 @@ check_ldap_config check_ldap_config_init() {
48 .ld_protocol = DEFAULT_PROTOCOL, 43 .ld_protocol = DEFAULT_PROTOCOL,
49#endif 44#endif
50 45
51 .warn_entries = NULL, 46 .entries_thresholds = mp_thresholds_init(),
52 .crit_entries = NULL, 47 .connection_time_threshold = mp_thresholds_init(),
53 .entries_thresholds = NULL,
54 .warn_time_set = false,
55 .warn_time = 0,
56 .crit_time_set = false,
57 .crit_time = 0,
58 }; 48 };
59 return tmp; 49 return tmp;
60} 50}
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t
index fcba0393..f3162ebb 100644
--- a/plugins/t/check_ldap.t
+++ b/plugins/t/check_ldap.t
@@ -32,7 +32,7 @@ SKIP: {
32 32
33 $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5"); 33 $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5");
34 is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" ); 34 is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" );
35 is( $result->output, 'Could not bind to the LDAP server', "output ok" ); 35 like( $result->output, '/could not bind to the LDAP server/', "output ok" );
36}; 36};
37 37
38SKIP: { 38SKIP: {
@@ -42,30 +42,30 @@ SKIP: {
42 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3"; 42 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3";
43 $result = NPTest->testCmd($cmd); 43 $result = NPTest->testCmd($cmd);
44 is( $result->return_code, 0, $cmd ); 44 is( $result->return_code, 0, $cmd );
45 like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" ); 45 like( $result->output, '/connection time \d+.\d+s/', "output ok" );
46 46
47 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001"; 47 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001";
48 $result = NPTest->testCmd($cmd); 48 $result = NPTest->testCmd($cmd);
49 is( $result->return_code, 0, $cmd ); 49 is( $result->return_code, 0, $cmd );
50 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000;10000001;0\.0+$/', "output ok" ); 50 like( $result->output, '/found \d+ entries/', "output ok" );
51 51
52 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:"; 52 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:";
53 $result = NPTest->testCmd($cmd); 53 $result = NPTest->testCmd($cmd);
54 is( $result->return_code, 2, $cmd ); 54 is( $result->return_code, 2, $cmd );
55 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001:;0\.0+$/', "output ok" ); 55 like( $result->output, '/found \d+ entries/', "output ok" );
56 56
57 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0"; 57 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0";
58 $result = NPTest->testCmd($cmd); 58 $result = NPTest->testCmd($cmd);
59 is( $result->return_code, 2, $cmd ); 59 is( $result->return_code, 2, $cmd );
60 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;0;0;0\.0+$/', "output ok" ); 60 like( $result->output, '/found \d+ entries/', "output ok" );
61 61
62 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001"; 62 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001";
63 $result = NPTest->testCmd($cmd); 63 $result = NPTest->testCmd($cmd);
64 is( $result->return_code, 1, $cmd ); 64 is( $result->return_code, 1, $cmd );
65 like( $result->output, '/^LDAP WARNING - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001;0\.0+$/', "output ok" ); 65 like( $result->output, '/found \d+ entries/', "output ok" );
66 66
67 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001"; 67 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001";
68 $result = NPTest->testCmd($cmd); 68 $result = NPTest->testCmd($cmd);
69 is( $result->return_code, 0, $cmd ); 69 is( $result->return_code, 0, $cmd );
70 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;;10000001;0\.0+$/', "output ok" ); 70 like( $result->output, '/found \d+ entries/', "output ok" );
71}; 71};