diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ldap.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index adfa966..b21351b 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
@@ -29,7 +29,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
29 | #include <ldap.h> | 29 | #include <ldap.h> |
30 | 30 | ||
31 | enum { | 31 | enum { |
32 | UNDEFINED = -1, | 32 | UNDEFINED = 0, |
33 | #ifdef HAVE_LDAP_SET_OPTION | 33 | #ifdef HAVE_LDAP_SET_OPTION |
34 | DEFAULT_PROTOCOL = 2, | 34 | DEFAULT_PROTOCOL = 2, |
35 | #endif | 35 | #endif |
@@ -53,6 +53,7 @@ int ld_protocol = DEFAULT_PROTOCOL; | |||
53 | #endif | 53 | #endif |
54 | int warn_time = UNDEFINED; | 54 | int warn_time = UNDEFINED; |
55 | int crit_time = UNDEFINED; | 55 | int crit_time = UNDEFINED; |
56 | struct timeval tv; | ||
56 | 57 | ||
57 | int | 58 | int |
58 | main (int argc, char *argv[]) | 59 | main (int argc, char *argv[]) |
@@ -61,8 +62,9 @@ main (int argc, char *argv[]) | |||
61 | LDAP *ld; | 62 | LDAP *ld; |
62 | LDAPMessage *result; | 63 | LDAPMessage *result; |
63 | 64 | ||
64 | int t_diff; | 65 | int status; |
65 | time_t time0, time1; | 66 | long microsec; |
67 | double elapsed_time; | ||
66 | 68 | ||
67 | setlocale (LC_ALL, ""); | 69 | setlocale (LC_ALL, ""); |
68 | bindtextdomain (PACKAGE, LOCALEDIR); | 70 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -78,7 +80,7 @@ main (int argc, char *argv[]) | |||
78 | alarm (socket_timeout); | 80 | alarm (socket_timeout); |
79 | 81 | ||
80 | /* get the start time */ | 82 | /* get the start time */ |
81 | time (&time0); | 83 | gettimeofday (&tv, NULL); |
82 | 84 | ||
83 | /* initialize ldap */ | 85 | /* initialize ldap */ |
84 | if (!(ld = ldap_open (ld_host, ld_port))) { | 86 | if (!(ld = ldap_open (ld_host, ld_port))) { |
@@ -117,26 +119,28 @@ main (int argc, char *argv[]) | |||
117 | /* reset the alarm handler */ | 119 | /* reset the alarm handler */ |
118 | alarm (0); | 120 | alarm (0); |
119 | 121 | ||
120 | /* get the finish time */ | ||
121 | time (&time1); | ||
122 | |||
123 | /* calcutate the elapsed time and compare to thresholds */ | 122 | /* calcutate the elapsed time and compare to thresholds */ |
124 | t_diff = time1 - time0; | ||
125 | 123 | ||
126 | if (crit_time!=UNDEFINED && t_diff>=crit_time) { | 124 | microsec = deltime (tv); |
127 | printf (_("LDAP CRITICAL - %i seconds response time\n"), t_diff); | 125 | elapsed_time = (double)microsec / 1.0e6; |
128 | return STATE_CRITICAL; | ||
129 | } | ||
130 | 126 | ||
131 | if (warn_time!=UNDEFINED && t_diff>=warn_time) { | 127 | if (crit_time!=UNDEFINED && elapsed_time>crit_time) |
132 | printf (_("LDAP WARNING - %i seconds response time\n"), t_diff); | 128 | status = STATE_CRITICAL; |
133 | return STATE_WARNING; | 129 | else if (warn_time!=UNDEFINED && elapsed_time>warn_time) |
134 | } | 130 | status = STATE_WARNING; |
131 | else | ||
132 | status = STATE_OK; | ||
135 | 133 | ||
136 | /* print out the result */ | 134 | /* print out the result */ |
137 | printf (_("LDAP OK - %i seconds response time\n"), t_diff); | 135 | printf (_("LDAP %s - %.3f seconds response time|%s\n"), |
138 | 136 | state_text (status), | |
139 | return STATE_OK; | 137 | elapsed_time, |
138 | perfdata ("time", microsec, "us", | ||
139 | warn_time, warn_time, | ||
140 | crit_time, crit_time, | ||
141 | TRUE, 0, FALSE, 0)); | ||
142 | |||
143 | return status; | ||
140 | } | 144 | } |
141 | 145 | ||
142 | /* process command-line arguments */ | 146 | /* process command-line arguments */ |
@@ -256,10 +260,10 @@ process_arguments (int argc, char **argv) | |||
256 | int | 260 | int |
257 | validate_arguments () | 261 | validate_arguments () |
258 | { | 262 | { |
259 | if (strlen(ld_host) == 0) | 263 | if (ld_host==NULL || strlen(ld_host)==0) |
260 | usage (_("please specify the host name\n")); | 264 | usage (_("please specify the host name\n")); |
261 | 265 | ||
262 | if (strlen(ld_base) == 0) | 266 | if (ld_base==NULL || strlen(ld_base)==0) |
263 | usage (_("please specify the LDAP base\n")); | 267 | usage (_("please specify the LDAP base\n")); |
264 | 268 | ||
265 | return OK; | 269 | return OK; |