diff options
Diffstat (limited to 'plugins/check_users.c')
| -rw-r--r-- | plugins/check_users.c | 123 |
1 files changed, 54 insertions, 69 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c index 58e8c13b..50851075 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
| @@ -1,58 +1,48 @@ | |||
| 1 | /****************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | * |
| 3 | * CHECK_USERS.C | 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * | 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * Program: Current users plugin for Nagios | 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * License: GPL | 6 | * (at your option) any later version. |
| 7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | 7 | * |
| 8 | * | 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * Last Modified: $Date$ | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * Modifications: | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * | 11 | * GNU General Public License for more details. |
| 12 | * 1999-11-17 Karl DeBisschop | 12 | * |
| 13 | * - check stderr and status from spoen/spclose | 13 | * You should have received a copy of the GNU General Public License |
| 14 | * - reformat commenst to fit 80-cahr screen | 14 | * along with this program; if not, write to the Free Software |
| 15 | * - set default result to STATE_UNKNOWN | 15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 16 | * - initialize users at -1, eliminate 'found' variable | 16 | * |
| 17 | * | 17 | *****************************************************************************/ |
| 18 | * Command line: CHECK_USERS <wusers> <cusers> | ||
| 19 | * | ||
| 20 | * Description: | ||
| 21 | * | ||
| 22 | * This plugin will use the /usr/bin/who command to check the number | ||
| 23 | * of users currently logged into the system. If number of logged in | ||
| 24 | * user exceeds the number specified by the <cusers> option, a | ||
| 25 | * STATE_CRITICAL is return. It it exceeds <wusers>, a STATE_WARNING | ||
| 26 | * is returned. Errors reading the output from the who command result | ||
| 27 | * in a STATE_UNKNOWN error. | ||
| 28 | * | ||
| 29 | * License Information: | ||
| 30 | * | ||
| 31 | * This program is free software; you can redistribute it and/or modify | ||
| 32 | * it under the terms of the GNU General Public License as published by | ||
| 33 | * the Free Software Foundation; either version 2 of the License, or | ||
| 34 | * (at your option) any later version. | ||
| 35 | * | ||
| 36 | * This program is distributed in the hope that it will be useful, | ||
| 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 39 | * GNU General Public License for more details. | ||
| 40 | * | ||
| 41 | * You should have received a copy of the GNU General Public License | ||
| 42 | * along with this program; if not, write to the Free Software | ||
| 43 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 44 | * | ||
| 45 | *****************************************************************************/ | ||
| 46 | 18 | ||
| 47 | #include "common.h" | 19 | #include "common.h" |
| 48 | #include "popen.h" | 20 | #include "popen.h" |
| 49 | #include "utils.h" | 21 | #include "utils.h" |
| 50 | 22 | ||
| 51 | const char *progname = "check_users"; | 23 | const char *progname = "check_users"; |
| 52 | #define REVISION "$Revision$" | 24 | const char *revision = "$Revision$"; |
| 53 | #define COPYRIGHT "1999-2002" | 25 | const char *copyright = "2002-2003"; |
| 54 | #define AUTHOR "Ethan Galstad" | 26 | const char *authors = "Nagios Plugin Development Team"; |
| 55 | #define EMAIL "nagios@nagios.org" | 27 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
| 28 | |||
| 29 | const char *summary = "\ | ||
| 30 | This plugin checks the number of users currently logged in on the local\n\ | ||
| 31 | system and generates an error if the number exceeds the thresholds specified.\n"; | ||
| 32 | |||
| 33 | const char *option_summary = "-w <users> -c <users>"; | ||
| 34 | |||
| 35 | const char *options = "\ | ||
| 36 | -w, --warning=INTEGER\n\ | ||
| 37 | Set WARNING status if more than INTEGER users are logged in\n\ | ||
| 38 | -c, --critical=INTEGER\n\ | ||
| 39 | Set CRITICAL status if more than INTEGER users are logged in\n"; | ||
| 40 | |||
| 41 | const char *standard_options = "\ | ||
| 42 | -h, --help\n\ | ||
| 43 | Print detailed help screen\n\ | ||
| 44 | -V, --version\n\ | ||
| 45 | Print version information\n\n"; | ||
| 56 | 46 | ||
| 57 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) | 47 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) |
| 58 | 48 | ||
| @@ -163,7 +153,7 @@ process_arguments (int argc, char **argv) | |||
| 163 | print_help (); | 153 | print_help (); |
| 164 | exit (STATE_OK); | 154 | exit (STATE_OK); |
| 165 | case 'V': /* version */ | 155 | case 'V': /* version */ |
| 166 | print_revision (progname, REVISION); | 156 | print_revision (progname, revision); |
| 167 | exit (STATE_OK); | 157 | exit (STATE_OK); |
| 168 | case 'c': /* critical */ | 158 | case 'c': /* critical */ |
| 169 | if (!is_intnonneg (optarg)) | 159 | if (!is_intnonneg (optarg)) |
| @@ -193,15 +183,22 @@ process_arguments (int argc, char **argv) | |||
| 193 | 183 | ||
| 194 | return OK; | 184 | return OK; |
| 195 | } | 185 | } |
| 196 | 186 | ||
| 197 | 187 | ||
| 198 | 188 | ||
| 199 | 189 | ||
| 200 | 190 | ||
| 201 | void | 191 | void |
| 202 | print_usage (void) | 192 | print_help (void) |
| 203 | { | 193 | { |
| 204 | printf ("Usage: %s -w <users> -c <users>\n", progname); | 194 | print_revision (progname, revision); |
| 195 | printf ("Copyright (c) %s %s\n\t<%s>\n\n", copyright, authors, email); | ||
| 196 | printf (summary); | ||
| 197 | print_usage (); | ||
| 198 | printf ("\nOptions:\n"); | ||
| 199 | printf (options); | ||
| 200 | printf (standard_options); | ||
| 201 | support (); | ||
| 205 | } | 202 | } |
| 206 | 203 | ||
| 207 | 204 | ||
| @@ -209,21 +206,9 @@ print_usage (void) | |||
| 209 | 206 | ||
| 210 | 207 | ||
| 211 | void | 208 | void |
| 212 | print_help (void) | 209 | print_usage (void) |
| 213 | { | 210 | { |
| 214 | print_revision (progname, REVISION); | 211 | printf ("Usage: %s %s\n", progname, option_summary); |
| 215 | printf | 212 | printf (" %s (-h|--help)\n", progname); |
| 216 | ("Copyright (c) " COPYRIGHT " " AUTHOR "(" EMAIL ")\n\n" | 213 | printf (" %s (-V|--version)\n", progname); |
| 217 | "This plugin checks the number of users currently logged in on the local\n" | ||
| 218 | "system and generates an error if the number exceeds the thresholds specified.\n"); | ||
| 219 | print_usage (); | ||
| 220 | printf | ||
| 221 | ("Options:\n" | ||
| 222 | " -w, --warning=INTEGER\n" | ||
| 223 | " Set WARNING status if more than INTEGER users are logged in\n" | ||
| 224 | " -c, --critical=INTEGER\n" | ||
| 225 | " Set CRITICAL status if more than INTEGER users are logged in\n" | ||
| 226 | " -h, --help\n" | ||
| 227 | " Print detailed help screen\n" | ||
| 228 | " -V, --version\n" " Print version information\n"); | ||
| 229 | } | 214 | } |
