[nagiosplug] Added calculate location directory

Ton Voon tonvoon at users.sourceforge.net
Mon Jun 21 14:08:07 CEST 2010


 Module: nagiosplug
 Branch: ton/state
 Commit: 17f96bc1455acaf3015e337f99aaac7b58c55dbb
 Author: Ton Voon <ton.voon at opsera.com>
   Date: Thu Jun 17 11:11:57 2010 +0100
    URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=17f96bc

Added calculate location directory

---

 lib/tests/test_utils.c |    6 ++++++
 lib/utils_base.c       |    8 +++++++-
 lib/utils_base.h       |    1 +
 3 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 057c484..763392a 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -32,6 +32,7 @@ main (int argc, char **argv)
 	state_key *temp_state_key = NULL;
 	state_data *temp_state_data;
 	time_t	current_time;
+	char 	*temp_filename;
 
 	plan_tests(81+23);
 
@@ -259,10 +260,15 @@ main (int argc, char **argv)
 	temp_string = np_state_generate_key(argv);
 	ok(!strcmp(temp_string, "Ahash"), "Got hash" );
 	
+	temp_string = _np_state_calculate_location_prefix();
+	ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory" );
+
 	ok(temp_state_key==NULL, "temp_state_key initially empty");
 	temp_state_key = np_state_init("check_test", temp_string, 54);
 	ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
 	ok( !strcmp(temp_state_key->name, temp_string), "Got key name" );
+	printf("Filename=%s\n", temp_state_key->_filename);
+
 	ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" );
 	ok( temp_state_key->data_version==54, "Version set" );
 
diff --git a/lib/utils_base.c b/lib/utils_base.c
index fb44240..b717a99 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -321,6 +321,10 @@ char *np_state_generate_key(char **argv) {
 	return "Ahash";
 }
 
+char* _np_state_calculate_location_prefix(){
+	return NP_SHAREDSTATE_DIR;
+}
+
 /*
  * Initiatializer for state routines.
  * Sets variables. Generates filename. Returns np_state_key. die with
@@ -328,6 +332,7 @@ char *np_state_generate_key(char **argv) {
  */
 state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_version) {
 	state_key *this_state = NULL;
+	char *temp_filename = NULL;
 
 	this_state = (state_key *) malloc(sizeof(state_key));
 	
@@ -339,7 +344,8 @@ state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_ver
 	this_state->data_version=expected_data_version;
 
 	/* Calculate filename */
-	this_state->_filename="Tobedone";
+	asprintf(&temp_filename, "%s/%s", _np_state_calculate_location_prefix(), plugin_name);
+	this_state->_filename=temp_filename;
 
 	return this_state;
 }
diff --git a/lib/utils_base.h b/lib/utils_base.h
index bec6c66..b6eb57e 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -28,6 +28,7 @@ typedef struct thresholds_struct {
 	range	*critical;
 	} thresholds;
 
+#define NP_SHAREDSTATE_DIR "/tmp"
 #define STATE_FORMAT_VERSION "1"
 
 typedef struct state_data_struct {





More information about the Commits mailing list