[icinga-checkins] icinga.org: icinga-core/rbartels/cgi-current: Removed usesless memory allocation and fixed a bug in avail. cgi and histogramm.cgi

git at icinga.org git at icinga.org
Fri Apr 1 13:49:14 CEST 2011


Module: icinga-core
Branch: rbartels/cgi-current
Commit: 0bc73b8bcc6a9e856ea47bd3a78ac1f3fcc55067
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=0bc73b8bcc6a9e856ea47bd3a78ac1f3fcc55067

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Fri Apr  1 13:45:46 2011 +0200

Removed usesless memory allocation and fixed a bug in avail.cgi and histogramm.cgi

There was a problem to recognize the UP HOST state correctly.

Removed the copying of log text to input var. We allready have the log text to compare state with.

---

 cgi/avail.c     |   31 ++++++++++++-------------------
 cgi/histogram.c |   35 +++++++++++++++++++++++------------
 2 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/cgi/avail.c b/cgi/avail.c
index 981cafd..0ba73ad 100644
--- a/cgi/avail.c
+++ b/cgi/avail.c
@@ -2794,7 +2794,6 @@ void read_archived_state_data(void){
 
 /* grabs archives state data from a log file */
 void scan_log_file_for_archived_state_data(char *filename){
-	char *input=NULL;
 	char entry_host_name[MAX_INPUT_BUFFER];
 	char entry_service_desc[MAX_INPUT_BUFFER];
 	char *plugin_output=NULL;
@@ -2809,11 +2808,6 @@ void scan_log_file_for_archived_state_data(char *filename){
 
 		for(temp_entry=next_log_entry();temp_entry!=NULL;temp_entry=next_log_entry()) {
 		
-			free(input);
-			input=NULL;
-			if((input=strdup(temp_entry->entry_text))==NULL)
-				continue;
-			
 			/* program starts/restarts */
 			if(temp_entry->type==LOGENTRY_STARTUP)
 				add_global_archived_state(AS_PROGRAM_START,AS_NO_DATA,temp_entry->timestamp,"Program start");
@@ -2850,12 +2844,12 @@ void scan_log_file_for_archived_state_data(char *filename){
 							break;
 
 						/* state types */
-						if(strstr(input,";SOFT;")){
+						if(strstr(temp_entry->entry_text,";SOFT;")){
 							if(include_soft_states==FALSE)
 								break;
 							state_type=AS_SOFT_STATE;
-						        }
-						if(strstr(input,";HARD;"))
+						}
+						if(strstr(temp_entry->entry_text,";HARD;"))
 							state_type=AS_HARD_STATE;
 
 						/* get the plugin output */
@@ -2864,11 +2858,11 @@ void scan_log_file_for_archived_state_data(char *filename){
 						temp_buffer=my_strtok(NULL,";");
 						plugin_output=my_strtok(NULL,"\n");
 
-						if(strstr(input,";DOWN;"))
+						if(strstr(temp_entry->entry_text,";DOWN;"))
 							add_archived_state(AS_HOST_DOWN,state_type,temp_entry->timestamp,plugin_output,temp_subject);
-						else if(strstr(input,";UNREACHABLE;"))
+						else if(strstr(temp_entry->entry_text,";UNREACHABLE;"))
 							add_archived_state(AS_HOST_UNREACHABLE,state_type,temp_entry->timestamp,plugin_output,temp_subject);
-						else if(strstr(input,";RECOVERY;") || strstr(input,";OK;"))
+						else if(strstr(temp_entry->entry_text,";RECOVERY;") || strstr(temp_entry->entry_text,";UP;"))
 							add_archived_state(AS_HOST_UP,state_type,temp_entry->timestamp,plugin_output,temp_subject);
 						else
 							add_archived_state(AS_NO_DATA,AS_NO_DATA,temp_entry->timestamp,plugin_output,temp_subject);
@@ -2933,12 +2927,12 @@ void scan_log_file_for_archived_state_data(char *filename){
 							break;
 
 						/* state types */
-						if(strstr(input,";SOFT;")){
+						if(strstr(temp_entry->entry_text,";SOFT;")){
 							if(include_soft_states==FALSE)
 								break;
 							state_type=AS_SOFT_STATE;
 						        }
-						if(strstr(input,";HARD;"))
+						if(strstr(temp_entry->entry_text,";HARD;"))
 							state_type=AS_HARD_STATE;
 
 						/* get the plugin output */
@@ -2947,13 +2941,13 @@ void scan_log_file_for_archived_state_data(char *filename){
 						temp_buffer=my_strtok(NULL,";");
 						plugin_output=my_strtok(NULL,"\n");
 
-						if(strstr(input,";CRITICAL;"))
+						if(strstr(temp_entry->entry_text,";CRITICAL;"))
 							add_archived_state(AS_SVC_CRITICAL,state_type,temp_entry->timestamp,plugin_output,temp_subject);
-						else if(strstr(input,";WARNING;"))
+						else if(strstr(temp_entry->entry_text,";WARNING;"))
 							add_archived_state(AS_SVC_WARNING,state_type,temp_entry->timestamp,plugin_output,temp_subject);
-						else if(strstr(input,";UNKNOWN;"))
+						else if(strstr(temp_entry->entry_text,";UNKNOWN;"))
 							add_archived_state(AS_SVC_UNKNOWN,state_type,temp_entry->timestamp,plugin_output,temp_subject);
-						else if(strstr(input,";RECOVERY;") || strstr(input,";OK;"))
+						else if(strstr(temp_entry->entry_text,";RECOVERY;") || strstr(temp_entry->entry_text,";OK;"))
 							add_archived_state(AS_SVC_OK,state_type,temp_entry->timestamp,plugin_output,temp_subject);
 						else
 							add_archived_state(AS_NO_DATA,AS_NO_DATA,temp_entry->timestamp,plugin_output,temp_subject);
@@ -3028,7 +3022,6 @@ void scan_log_file_for_archived_state_data(char *filename){
 			my_free(temp_entry);
 		}
 		free_log_entries();
-		free(input);
 	}
 	return;
 }
diff --git a/cgi/histogram.c b/cgi/histogram.c
index 5719391..208cc78 100644
--- a/cgi/histogram.c
+++ b/cgi/histogram.c
@@ -2117,7 +2117,6 @@ void read_archived_state_data(void){
 
 /* grabs archives state data from a log file */
 void scan_log_file_for_archived_state_data(char *filename){
-	char *input=NULL;
 	char entry_host_name[MAX_INPUT_BUFFER];
 	char entry_service_desc[MAX_INPUT_BUFFER];
 	char *temp_buffer;
@@ -2130,6 +2129,25 @@ void scan_log_file_for_archived_state_data(char *filename){
 		fflush(NULL);
 	}
 
+	/* Service filter */
+	add_log_filter(LOGENTRY_SERVICE_OK,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_SERVICE_WARNING,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_SERVICE_CRITICAL,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_SERVICE_UNKNOWN,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_SERVICE_RECOVERY,LOGFILTER_INCLUDE);
+
+	/* Host filter */
+	add_log_filter(LOGENTRY_HOST_UP,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_HOST_DOWN,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_HOST_UNREACHABLE,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_HOST_RECOVERY,LOGFILTER_INCLUDE);
+
+	/* system message */
+	add_log_filter(LOGENTRY_STARTUP,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_RESTART,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_SHUTDOWN,LOGFILTER_INCLUDE);
+	add_log_filter(LOGENTRY_BAILOUT,LOGFILTER_INCLUDE);
+
 	status = get_log_entries(filename,NULL,FALSE,t1-(60*60*24*backtrack_archives),t2);
 	
 	if (status!=READLOG_OK) {
@@ -2145,12 +2163,6 @@ void scan_log_file_for_archived_state_data(char *filename){
 
 		for(temp_entry=next_log_entry();temp_entry!=NULL;temp_entry=next_log_entry()) {
 
-			/* free memory */
-			free(input);
-			input=NULL;
-			if((input=strdup(temp_entry->entry_text))==NULL)
-				continue;
-
 			/* program starts/restarts */
 			if(temp_entry->type==LOGENTRY_STARTUP)
 				add_archived_state(AS_PROGRAM_START,temp_entry->timestamp);
@@ -2182,11 +2194,11 @@ void scan_log_file_for_archived_state_data(char *filename){
 							continue;
 
 						/* skip soft states if necessary */
-						if(!(graph_statetypes & GRAPH_SOFT_STATETYPES) && strstr(input,";SOFT;"))
+						if(!(graph_statetypes & GRAPH_SOFT_STATETYPES) && strstr(temp_entry->entry_text,";SOFT;"))
 							continue;
 
 						/* skip hard states if necessary */
-						if(!(graph_statetypes & GRAPH_HARD_STATETYPES) && strstr(input,";HARD;"))
+						if(!(graph_statetypes & GRAPH_HARD_STATETYPES) && strstr(temp_entry->entry_text,";HARD;"))
 							continue;
 
 						if(temp_entry->type==LOGENTRY_HOST_DOWN)
@@ -2228,11 +2240,11 @@ void scan_log_file_for_archived_state_data(char *filename){
 							continue;
 
 						/* skip soft states if necessary */
-						if(!(graph_statetypes & GRAPH_SOFT_STATETYPES) && strstr(input,";SOFT;"))
+						if(!(graph_statetypes & GRAPH_SOFT_STATETYPES) && strstr(temp_entry->entry_text,";SOFT;"))
 							continue;
 
 						/* skip hard states if necessary */
-						if(!(graph_statetypes & GRAPH_HARD_STATETYPES) && strstr(input,";HARD;"))
+						if(!(graph_statetypes & GRAPH_HARD_STATETYPES) && strstr(temp_entry->entry_text,";HARD;"))
 							continue;
 
 						if(temp_entry->type==LOGENTRY_SERVICE_CRITICAL)
@@ -2252,7 +2264,6 @@ void scan_log_file_for_archived_state_data(char *filename){
 	        }
 		/* free memory */
 		free_log_entries();
-		free(input);
 	}	
 	return;
 }





More information about the icinga-checkins mailing list