[monitoring-plugins] Rename ENV variable, keep backward compatibility
Git Repository
git at monitoring-plugins.org
Sat Jan 25 10:40:07 CET 2014
Module: monitoring-plugins
Branch: master
Commit: 4caf4ce4fe3a0f08f129a4537c4173d1e6b6d752
Author: Thomas Guyot-Sionnest <dermoth at aei.ca>
Date: Sat Jan 25 03:35:46 2014 -0500
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=4caf4ce
Rename ENV variable, keep backward compatibility
Rename NAGIOS_PLUGIN_STATE_DIRECTORY to MP_STATE_DIRECTORY
---
lib/tests/test_utils.c | 6 +++---
lib/utils_base.c | 6 ++++++
plugins/tests/check_snmp.t | 4 ++--
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 7a1a1fa..12252f4 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -304,15 +304,15 @@ main (int argc, char **argv)
temp_string = (char *) _np_state_generate_key();
ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" );
- unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY");
+ unsetenv("MP_STATE_DIRECTORY");
temp_string = (char *) _np_state_calculate_location_prefix();
ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" );
- setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1);
+ setenv("MP_STATE_DIRECTORY", "", 1);
temp_string = (char *) _np_state_calculate_location_prefix();
ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" );
- setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1);
+ setenv("MP_STATE_DIRECTORY", "/usr/local/nagios/var", 1);
temp_string = (char *) _np_state_calculate_location_prefix();
ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" );
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 57d01e2..304b732 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -415,9 +415,15 @@ void _cleanup_state_data() {
char* _np_state_calculate_location_prefix(){
char *env_dir;
+ /* FIXME: Undocumented */
+ env_dir = getenv("MP_STATE_DIRECTORY");
+ if(env_dir && env_dir[0] != '\0')
+ return env_dir;
+ /* This is the former ENV, for backward-compatibility */
env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY");
if(env_dir && env_dir[0] != '\0')
return env_dir;
+
return NP_STATE_DIR_PREFIX;
}
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index 1ef0b20..9a89607 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -59,7 +59,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
}
# We should merge that with $ENV{'NPTEST_CACHE'}, use one dir for all test data
-$ENV{'NAGIOS_PLUGIN_STATE_DIRECTORY'} ||= "/var/tmp";
+$ENV{'MP_STATE_DIRECTORY'} ||= "/var/tmp";
my $res;
@@ -109,7 +109,7 @@ like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C
"And now have fun with with this: \"C:\\\\\"
because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3");
-system("rm -f ".$ENV{'NAGIOS_PLUGIN_STATE_DIRECTORY'}."/check_snmp/*");
+system("rm -f ".$ENV{'MP_STATE_DIRECTORY'}."/check_snmp/*");
$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" );
is($res->return_code, 0, "Returns OK");
is($res->output, "No previous data to calculate rate - assume okay");
More information about the Commits
mailing list