summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_users.c21
-rw-r--r--plugins/t/check_users.t5
2 files changed, 17 insertions, 9 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 7cf7a2cc..89b95369 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -227,18 +227,23 @@ process_arguments (int argc, char **argv)
227 } 227 }
228 228
229 c = optind; 229 c = optind;
230
230 if (warning_range == NULL && argc > c) 231 if (warning_range == NULL && argc > c)
231 warning_range = argv[c++]; 232 warning_range = argv[c++];
233
232 if (critical_range == NULL && argc > c) 234 if (critical_range == NULL && argc > c)
233 critical_range = argv[c++]; 235 critical_range = argv[c++];
234 236
235 /* this will abort in case of invalid ranges */ 237 /* this will abort in case of invalid ranges */
236 set_thresholds (&thlds, warning_range, critical_range); 238 set_thresholds (&thlds, warning_range, critical_range);
237 239
238 if (thlds->warning->end < 0) 240 if (!thlds->warning) {
239 usage4 (_("Warning threshold must be a positive integer")); 241 usage4 (_("Warning threshold must be a valid range expression"));
240 if (thlds->critical->end < 0) 242 }
241 usage4 (_("Critical threshold must be a positive integer")); 243
244 if (!thlds->critical) {
245 usage4 (_("Critical threshold must be a valid range expression"));
246 }
242 247
243 return OK; 248 return OK;
244} 249}
@@ -261,10 +266,10 @@ print_help (void)
261 printf (UT_HELP_VRSN); 266 printf (UT_HELP_VRSN);
262 printf (UT_EXTRA_OPTS); 267 printf (UT_EXTRA_OPTS);
263 268
264 printf (" %s\n", "-w, --warning=INTEGER"); 269 printf (" %s\n", "-w, --warning=RANGE_EXPRESSION");
265 printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in")); 270 printf (" %s\n", _("Set WARNING status if number of logged in users violates RANGE_EXPRESSION"));
266 printf (" %s\n", "-c, --critical=INTEGER"); 271 printf (" %s\n", "-c, --critical=RANGE_EXPRESSION");
267 printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in")); 272 printf (" %s\n", _("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION"));
268 273
269 printf (UT_SUPPORT); 274 printf (UT_SUPPORT);
270} 275}
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t
index 9ebc2fc6..21c3e53d 100644
--- a/plugins/t/check_users.t
+++ b/plugins/t/check_users.t
@@ -13,10 +13,11 @@ use Test;
13use NPTest; 13use NPTest;
14 14
15use vars qw($tests); 15use vars qw($tests);
16BEGIN {$tests = 8; plan tests => $tests} 16BEGIN {$tests = 12; plan tests => $tests}
17 17
18my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; 18my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/';
19my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; 19my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/';
20my $wrongOptionOutput = '/Usage:/';
20 21
21my $t; 22my $t;
22 23
@@ -24,6 +25,8 @@ $t += checkCmd( "./check_users 1000 1000", 0, $successOutput );
24$t += checkCmd( "./check_users 0 0", 2, $failureOutput ); 25$t += checkCmd( "./check_users 0 0", 2, $failureOutput );
25$t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); 26$t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput );
26$t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); 27$t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput );
28$t += checkCmd( "./check_users -w 0:1000", 3, $wrongOptionOutput);
29$t += checkCmd( "./check_users", 3, $wrongOptionOutput);
27 30
28exit(0) if defined($Test::Harness::VERSION); 31exit(0) if defined($Test::Harness::VERSION);
29exit($tests - $t); 32exit($tests - $t);