From 3bb4b6b336b383c8f1686476cfb96ec674255683 Mon Sep 17 00:00:00 2001 From: Matthias Eble Date: Mon, 10 Dec 2007 00:19:27 +0000 Subject: Fixed check_load argument handling when passing non triplet thresholds. Thanks to Jonathan Kamens (bug #1831890) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1851 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_load.c | 4 +++- plugins/t/check_load.t | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/check_load.c b/plugins/check_load.c index 9de8ff78..5503204a 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -77,6 +77,7 @@ static void get_threshold(char *arg, double *th) { size_t i, n; + int valid = 0; char *str = arg, *p; n = strlen(arg); @@ -84,12 +85,13 @@ get_threshold(char *arg, double *th) th[i] = strtod(str, &p); if(p == str) break; + valid = 1; str = p + 1; if(n <= (size_t)(str - arg)) break; } /* empty argument or non-floatish, so warn about it and die */ - if(!i) usage (_("Warning threshold must be float or float triplet!\n")); + if(!i && !valid) usage (_("Warning threshold must be float or float triplet!\n")); if(i != 2) { /* one or more numbers were given, so fill array with last diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index da87d168..8987b84c 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t @@ -11,10 +11,11 @@ use NPTest; my $res; -my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; -my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; +my $loadValue = "[0-9]+\.?[0-9]+"; +my $successOutput = "/^OK - load average: $loadValue, $loadValue, $loadValue/"; +my $failureOutput = "/^CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; -plan tests => 6; +plan tests => 11; $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); @@ -28,3 +29,9 @@ $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); like( $res->output, $failureOutput, "Output OK"); +$res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); +cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); +like( $res->output, $successOutput, "Output OK"); +like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); +like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); +like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); -- cgit v1.2.3-74-g34f1