diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-22 02:24:39 -0500 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-22 02:24:39 -0500 |
commit | 485f306868fa9c89b4f09e3b2b813d93ec64f0b4 (patch) | |
tree | 0431458903d177fee9633fdd23d7f1594c8bf70d /lib | |
parent | bf4abd539507e1194d836e6e818bda4807f497bf (diff) | |
download | monitoring-plugins-485f306868fa9c89b4f09e3b2b813d93ec64f0b4.tar.gz |
Return UNKNOWN if none of the default files can be found.
It makes no sense to return unknown if an implicit section is not found, but
go on if the file is missing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parse_ini.c | 3 | ||||
-rwxr-xr-x | lib/tests/test_opts3.t | 23 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index 1d64a506..004396fe 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c @@ -75,6 +75,9 @@ static void parse_locator(const char *locator, const char *def_stanza, np_ini_in /* if there is no @file part */ if(stanza_len==locator_len){ i->file=default_file(); + if(strcmp(i->file, "") == 0){ + die(STATE_UNKNOWN, _("Cannot find '%s' or '%s' in any standard location.\n"), NP_DEFAULT_INI_FILENAME1, NP_DEFAULT_INI_FILENAME2); + } } else { i->file=strdup(&(locator[stanza_len+1])); } diff --git a/lib/tests/test_opts3.t b/lib/tests/test_opts3.t index 47ec26b3..35b44687 100755 --- a/lib/tests/test_opts3.t +++ b/lib/tests/test_opts3.t @@ -8,15 +8,19 @@ if (! -e "./test_opts3") { } # array of argument arrays -# - first value is the NAGIOS_CONFIG_PATH -# - 2nd value is the plugin name -# - 3rc and up are arguments +# - First value is the expected return code +# - 2nd value is the NAGIOS_CONFIG_PATH +# TODO: looks like we look in default path after looking trough this variable - shall we? +# - 3rd value is the plugin name +# - 4th and up are arguments my @TESTS = ( - ['/nonexistent', 'prog_name', 'arg1', '--extra-opts', '--arg3', 'val2'], - ['.', 'prog_name', 'arg1', '--extra-opts=missing@./config-opts.ini', '--arg3', 'val2'], - ['.', 'prog_name', 'arg1', '--extra-opts', 'missing@./config-opts.ini', '--arg3', 'val2'], - ['.', 'check_missing', 'arg1', '--extra-opts=@./config-opts.ini', '--arg3', 'val2'], - ['.', 'check_missing', 'arg1', '--extra-opts', '--arg3', 'val2'], + [3, '/nonexistent', 'prog_name', 'arg1', '--extra-opts', '--arg3', 'val2'], + [3, '.', 'prog_name', 'arg1', '--extra-opts=missing@./config-opts.ini', '--arg3', 'val2'], + [3, '', 'prog_name', 'arg1', '--extra-opts', 'missing@./config-opts.ini', '--arg3', 'val2'], + [3, '.', 'check_missing', 'arg1', '--extra-opts=@./config-opts.ini', '--arg3', 'val2'], + [3, '.', 'check_missing', 'arg1', '--extra-opts', '--arg3', 'val2'], + [0, '/tmp:/var:/nonexistent:.', 'check_tcp', 'arg1', '--extra-opts', '--arg3', 'val2'], + [0, '/usr/local/nagios/etc:.:/etc', 'check_missing', 'arg1', '--extra-opts=check_tcp', '--arg3', 'val2'], ); plan tests => scalar(@TESTS); @@ -24,8 +28,9 @@ plan tests => scalar(@TESTS); my $count=1; foreach my $args (@TESTS) { + my $rc = shift(@$args); $ENV{"NAGIOS_CONFIG_PATH"} = shift(@$args); system {'./test_opts3'} @$args; - cmp_ok($?>>8, '==', 3, "Extra-opts die " . $count++); + cmp_ok($?>>8, '==', $rc, "Extra-opts die " . $count++); } |