diff options
Diffstat (limited to 'plugins/check_ldap.c')
-rw-r--r-- | plugins/check_ldap.c | 104 |
1 files changed, 82 insertions, 22 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index c371be97..845a4f52 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -1,29 +1,29 @@ /***************************************************************************** -* +* * Monitoring check_ldap plugin -* +* * License: GPL * Copyright (c) 2000-2008 Monitoring Plugins Development Team -* +* * Description: -* +* * This file contains the check_ldap plugin -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* +* +* *****************************************************************************/ /* progname may be check_ldaps */ @@ -67,7 +67,10 @@ int ld_protocol = DEFAULT_PROTOCOL; #endif double warn_time = UNDEFINED; double crit_time = UNDEFINED; +thresholds *entries_thresholds = NULL; struct timeval tv; +char* warn_entries = NULL; +char* crit_entries = NULL; int starttls = FALSE; int ssl_on_connect = FALSE; int verbose = 0; @@ -94,6 +97,12 @@ main (int argc, char *argv[]) int tls; int version=3; + /* for entry counting */ + + LDAPMessage *next_entry; + int status_entries = STATE_OK; + int num_entries = 0; + setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); @@ -197,12 +206,14 @@ main (int argc, char *argv[]) } /* do a search of all objectclasses in the base dn */ - if (ldap_search_s (ld, ld_base, LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result) + if (ldap_search_s (ld, ld_base, (crit_entries!=NULL || warn_entries!=NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result) != LDAP_SUCCESS) { if (verbose) ldap_perror(ld, "ldap_search"); printf (_("Could not search/find objectclasses in %s\n"), ld_base); return STATE_CRITICAL; + } else if (crit_entries!=NULL || warn_entries!=NULL) { + num_entries = ldap_count_entries(ld, result); } /* unbind from the ldap server */ @@ -223,14 +234,42 @@ main (int argc, char *argv[]) else status = STATE_OK; + if(entries_thresholds != NULL) { + if (verbose) { + printf ("entries found: %d\n", num_entries); + print_thresholds("entry thresholds", entries_thresholds); + } + status_entries = get_status(num_entries, entries_thresholds); + if (status_entries == STATE_CRITICAL) { + status = STATE_CRITICAL; + } else if (status != STATE_CRITICAL) { + status = status_entries; + } + } + /* print out the result */ - printf (_("LDAP %s - %.3f seconds response time|%s\n"), - state_text (status), - elapsed_time, - fperfdata ("time", elapsed_time, "s", - (int)warn_time, warn_time, - (int)crit_time, crit_time, - TRUE, 0, FALSE, 0)); + if (crit_entries!=NULL || warn_entries!=NULL) { + printf (_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), + state_text (status), + num_entries, + elapsed_time, + fperfdata ("time", elapsed_time, "s", + (int)warn_time, warn_time, + (int)crit_time, crit_time, + TRUE, 0, FALSE, 0), + sperfdata ("entries", (double)num_entries, "", + warn_entries, + crit_entries, + TRUE, 0.0, FALSE, 0.0)); + } else { + printf (_("LDAP %s - %.3f seconds response time|%s\n"), + state_text (status), + elapsed_time, + fperfdata ("time", elapsed_time, "s", + (int)warn_time, warn_time, + (int)crit_time, crit_time, + TRUE, 0, FALSE, 0)); + } return status; } @@ -263,6 +302,8 @@ process_arguments (int argc, char **argv) {"port", required_argument, 0, 'p'}, {"warn", required_argument, 0, 'w'}, {"crit", required_argument, 0, 'c'}, + {"warn-entries", required_argument, 0, 'W'}, + {"crit-entries", required_argument, 0, 'C'}, {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; @@ -276,7 +317,7 @@ process_arguments (int argc, char **argv) } while (1) { - c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:", longopts, &option); + c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); if (c == -1 || c == EOF) break; @@ -284,10 +325,10 @@ process_arguments (int argc, char **argv) switch (c) { case 'h': /* help */ print_help (); - exit (STATE_OK); + exit (STATE_UNKNOWN); case 'V': /* version */ print_revision (progname, NP_VERSION); - exit (STATE_OK); + exit (STATE_UNKNOWN); case 't': /* timeout period */ if (!is_intnonneg (optarg)) usage2 (_("Timeout interval must be a positive integer"), optarg); @@ -318,6 +359,12 @@ process_arguments (int argc, char **argv) case 'c': crit_time = strtod (optarg, NULL); break; + case 'W': + warn_entries = optarg; + break; + case 'C': + crit_entries = optarg; + break; #ifdef HAVE_LDAP_SET_OPTION case '2': ld_protocol = 2; @@ -381,6 +428,13 @@ validate_arguments () if (ld_base==NULL) usage4 (_("Please specify the LDAP base\n")); + if (crit_entries!=NULL || warn_entries!=NULL) { + set_thresholds(&entries_thresholds, + warn_entries, crit_entries); + } + if (ld_passwd==NULL) + ld_passwd = getenv("LDAP_PASSWORD"); + return OK; } @@ -414,7 +468,7 @@ print_help (void) printf (" %s\n", "-D [--bind]"); printf (" %s\n", _("ldap bind DN (if required)")); printf (" %s\n", "-P [--pass]"); - printf (" %s\n", _("ldap password (if required)")); + printf (" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')")); printf (" %s\n", "-T [--starttls]"); printf (" %s\n", _("use starttls mechanism introduced in protocol version 3")); printf (" %s\n", "-S [--ssl]"); @@ -430,6 +484,11 @@ print_help (void) printf (UT_WARN_CRIT); + printf (" %s\n", "-W [--warn-entries]"); + printf (" %s\n", _("Number of found entries to result in warning status")); + printf (" %s\n", "-C [--crit-entries]"); + printf (" %s\n", _("Number of found entries to result in critical status")); + printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); printf (UT_VERBOSE); @@ -441,6 +500,7 @@ print_help (void) printf (" %s\n", _("'SSL on connect' will be used no matter how the plugin was called.")); printf (" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags")); printf (" %s\n", _("to define the behaviour explicitly instead.")); + printf (" %s\n", _("The parameters --warn-entries and --crit-entries are optional.")); printf (UT_SUPPORT); } |