[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2140] nagiosplug/trunk/lib

dermoth at users.sourceforge.net dermoth at users.sourceforge.net
Thu Jan 22 08:28:16 CET 2009


Revision: 2140
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2140&view=rev
Author:   dermoth
Date:     2009-01-22 07:28:16 +0000 (Thu, 22 Jan 2009)

Log Message:
-----------
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

From: Thomas Guyot-Sionnest <dermoth at aei.ca>

Modified Paths:
--------------
    nagiosplug/trunk/lib/parse_ini.c
    nagiosplug/trunk/lib/tests/test_opts3.t

Modified: nagiosplug/trunk/lib/parse_ini.c
===================================================================
--- nagiosplug/trunk/lib/parse_ini.c	2009-01-22 07:08:45 UTC (rev 2139)
+++ nagiosplug/trunk/lib/parse_ini.c	2009-01-22 07:28:16 UTC (rev 2140)
@@ -75,6 +75,9 @@
 	/* 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]));
 	}

Modified: nagiosplug/trunk/lib/tests/test_opts3.t
===================================================================
--- nagiosplug/trunk/lib/tests/test_opts3.t	2009-01-22 07:08:45 UTC (rev 2139)
+++ nagiosplug/trunk/lib/tests/test_opts3.t	2009-01-22 07:28:16 UTC (rev 2140)
@@ -8,15 +8,19 @@
 }
 
 # 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 at ./config-opts.ini', '--arg3', 'val2'],
-	['.', 'prog_name', 'arg1', '--extra-opts', 'missing at ./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 at ./config-opts.ini', '--arg3', 'val2'],
+	[3, '', 'prog_name', 'arg1', '--extra-opts', 'missing at ./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 @@
 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++);
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list