summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_ldap.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 6491e5b..ac11c58 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -21,7 +21,7 @@
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23const char *progname = "check_ldap"; 23const char *progname = "check_ldap";
24#define REVISION "$Revision$" 24const char *revision = "$Revision$";
25 25
26#include "config.h" 26#include "config.h"
27#include "common.h" 27#include "common.h"
@@ -31,7 +31,10 @@ const char *progname = "check_ldap";
31#include <lber.h> 31#include <lber.h>
32#include <ldap.h> 32#include <ldap.h>
33 33
34#define UNKNOWN -1 34enum {
35 UNDEFINED = -1,
36 DEFAULT_PORT = 389
37};
35 38
36int process_arguments (int, char **); 39int process_arguments (int, char **);
37int validate_arguments (void); 40int validate_arguments (void);
@@ -40,9 +43,13 @@ void print_usage (void);
40 43
41char ld_defattr[] = "(objectclass=*)"; 44char ld_defattr[] = "(objectclass=*)";
42char *ld_attr = ld_defattr; 45char *ld_attr = ld_defattr;
43char *ld_host = NULL, *ld_base = NULL, *ld_passwd = NULL, *ld_binddn = NULL; 46char *ld_host = "";
44unsigned int ld_port = 389; 47char *ld_base = "";
45int warn_time = UNKNOWN, crit_time = UNKNOWN; 48char *ld_passwd = NULL;
49char *ld_binddn = NULL;
50unsigned int ld_port = DEFAULT_PORT;
51int warn_time = UNDEFINED;
52int crit_time = UNDEFINED;
46 53
47int 54int
48main (int argc, char *argv[]) 55main (int argc, char *argv[])
@@ -98,19 +105,19 @@ main (int argc, char *argv[])
98 /* get the finish time */ 105 /* get the finish time */
99 time (&time1); 106 time (&time1);
100 107
101 /* calcutate the elapsed time */ 108 /* calcutate the elapsed time and compare to thresholds */
102 t_diff = time1 - time0; 109 t_diff = time1 - time0;
103 110
104 /* check if warn_time or crit_time was exceeded */ 111 if (crit_time!=UNDEFINED && t_diff>=crit_time) {
105 if ((t_diff >= warn_time) && (t_diff < crit_time)) {
106 printf ("LDAP warning - %i seconds response time\n", t_diff);
107 return STATE_WARNING;
108 }
109 if (t_diff >= crit_time) {
110 printf ("LDAP critical - %i seconds response time\n", t_diff); 112 printf ("LDAP critical - %i seconds response time\n", t_diff);
111 return STATE_CRITICAL; 113 return STATE_CRITICAL;
112 } 114 }
113 115
116 if (warn_time!=UNDEFINED && t_diff>=warn_time) {
117 printf ("LDAP warning - %i seconds response time\n", t_diff);
118 return STATE_WARNING;
119 }
120
114 /* print out the result */ 121 /* print out the result */
115 printf ("LDAP ok - %i seconds response time\n", t_diff); 122 printf ("LDAP ok - %i seconds response time\n", t_diff);
116 123
@@ -165,11 +172,11 @@ process_arguments (int argc, char **argv)
165 print_help (); 172 print_help ();
166 exit (STATE_OK); 173 exit (STATE_OK);
167 case 'V': /* version */ 174 case 'V': /* version */
168 print_revision (progname, REVISION); 175 print_revision (progname, revision);
169 exit (STATE_OK); 176 exit (STATE_OK);
170 case 't': /* timeout period */ 177 case 't': /* timeout period */
171 if (!is_intnonneg (optarg)) 178 if (!is_intnonneg (optarg))
172 usage2 ("timeout interval must be an integer", optarg); 179 usage2 ("timeout interval must be a positive integer", optarg);
173 socket_timeout = atoi (optarg); 180 socket_timeout = atoi (optarg);
174 break; 181 break;
175 case 'H': 182 case 'H':
@@ -212,14 +219,15 @@ process_arguments (int argc, char **argv)
212int 219int
213validate_arguments () 220validate_arguments ()
214{ 221{
215 if (ld_host[0] == 0 || 222 if (strlen(ld_host) == 0)
216 ld_base[0] == 0 || 223 usage ("please specify the host name\n");
217 ld_port == UNKNOWN || warn_time == UNKNOWN || crit_time == UNKNOWN) { 224
218 return ERROR; 225 if (strlen(ld_base) == 0)
219 } 226 usage ("please specify the LDAP base\n");
220 else { 227
228 else
221 return OK; 229 return OK;
222 } 230
223} 231}
224 232
225 233
@@ -228,7 +236,7 @@ validate_arguments ()
228void 236void
229print_help () 237print_help ()
230{ 238{
231 print_revision (progname, REVISION); 239 print_revision (progname, revision);
232 printf 240 printf
233 ("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n" 241 ("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n"
234 "License: GPL\n" "\n"); 242 "License: GPL\n" "\n");
@@ -241,10 +249,10 @@ print_help ()
241 "\t-b [--base] ... ldap base (eg. ou=my unit, o=my org, c=at)\n" 249 "\t-b [--base] ... ldap base (eg. ou=my unit, o=my org, c=at)\n"
242 "\t-D [--bind] ... ldap bind DN (if required)\n" 250 "\t-D [--bind] ... ldap bind DN (if required)\n"
243 "\t-P [--pass] ... ldap password (if required)\n" 251 "\t-P [--pass] ... ldap password (if required)\n"
244 "\t-p [--port] ... ldap port (normaly 389)\n" 252 "\t-p [--port] ... ldap port (default: %d)\n"
245 "\t-w [--warn] ... time in secs. - if the exceeds <warn> the STATE_WARNING will be returned\n" 253 "\t-w [--warn] ... time in secs. - if the exceeds <warn> the STATE_WARNING will be returned\n"
246 "\t-c [--crit] ... time in secs. - if the exceeds <crit> the STATE_CRITICAL will be returned\n" 254 "\t-c [--crit] ... time in secs. - if the exceeds <crit> the STATE_CRITICAL will be returned\n"
247 "\n"); 255 "\n", DEFAULT_PORT);
248} 256}
249 257
250 258
@@ -252,7 +260,7 @@ void
252print_usage () 260print_usage ()
253{ 261{
254 printf 262 printf
255 ("Usage: %s -H <host> -b <base_dn> -p <port> [-a <attr>] [-D <binddn>]\n" 263 ("Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n"
256 " [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]\n" 264 " [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]\n"
257 "(Note: all times are in seconds.)\n", progname); 265 "(Note: all times are in seconds.)\n", progname);
258} 266}