[icinga-checkins] icinga.org: icinga-core/rbartels/cgi-current: Added parameter to get_log_entries() function to use beginning and end timestamp #1271

git at icinga.org git at icinga.org
Tue Mar 8 10:18:56 CET 2011


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

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Tue Mar  8 10:18:30 2011 +0100

Added parameter to get_log_entries() function to use beginning and end timestamp #1271

fixes: #1271

---

 Changelog           |    1 +
 cgi/avail.c         |    2 +-
 cgi/histogram.c     |    2 +-
 cgi/history.c       |    2 +-
 cgi/notifications.c |    2 +-
 cgi/readlogs.c      |    6 +++++-
 cgi/showlog.c       |    9 +--------
 cgi/summary.c       |    2 +-
 cgi/trends.c        |    2 +-
 include/readlogs.h  |    2 +-
 10 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/Changelog b/Changelog
index c211bec..f37ec5a 100644
--- a/Changelog
+++ b/Changelog
@@ -10,6 +10,7 @@ ENHANCEMENTS
 * classic ui: adding entry time of comments in tooltip's in status.cgi #1244
 * classic ui: Searching in the Icinga Logfile #516
 * classic ui: changed print_generic_error() function to support csv output #1270
+* classic ui: Added parameter to get_log_entries() function to use beginning and end timestamp #1271
 
 FIXES
 * core: fix flexible downtime on service hard state change doesn't get triggered/activated #1128
diff --git a/cgi/avail.c b/cgi/avail.c
index 84bfd05..59854ac 100644
--- a/cgi/avail.c
+++ b/cgi/avail.c
@@ -2821,7 +2821,7 @@ void scan_log_file_for_archived_state_data(char *filename){
 	logentry *temp_entry=NULL;
 	int state_type=0,status;
 
-	status = get_log_entries(filename,NULL,FALSE);
+	status = get_log_entries(filename,NULL,FALSE,t1-(60*60*24*backtrack_archives),t2);
 	
 	if (status==READLOG_OK) {
 
diff --git a/cgi/histogram.c b/cgi/histogram.c
index 73ce189..512f82f 100644
--- a/cgi/histogram.c
+++ b/cgi/histogram.c
@@ -2148,7 +2148,7 @@ void scan_log_file_for_archived_state_data(char *filename){
 		fflush(NULL);
 	}
 
-	status = get_log_entries(filename,NULL,FALSE);
+	status = get_log_entries(filename,NULL,FALSE,t1-(60*60*24*backtrack_archives),t2);
 	
 	if (status!=READLOG_OK) {
 #ifdef DEBUG2
diff --git a/cgi/history.c b/cgi/history.c
index 738c192..fd20e10 100644
--- a/cgi/history.c
+++ b/cgi/history.c
@@ -439,7 +439,7 @@ void show_history(void){
 	struct tm *time_ptr=NULL;
 
 	/* read log entries */
-	status=get_log_entries(log_file_to_use,NULL,reverse);
+	status=get_log_entries(log_file_to_use,NULL,reverse,-1,-1);
 
 	if (status==READLOG_ERROR_MEMORY) {
 		printf("<P><DIV CLASS='warningMessage'>Run out of memory..., showing all I could gather!</DIV></P>");
diff --git a/cgi/notifications.c b/cgi/notifications.c
index be5ac12..58ca474 100644
--- a/cgi/notifications.c
+++ b/cgi/notifications.c
@@ -441,7 +441,7 @@ void display_notifications(void){
 	add_log_filter(LOGENTRY_HOST_NOTIFICATION,LOGFILTER_INCLUDE);
 	add_log_filter(LOGENTRY_SERVICE_NOTIFICATION,LOGFILTER_INCLUDE);
 
-	status = get_log_entries(log_file_to_use,NULL,reverse);
+	status = get_log_entries(log_file_to_use,NULL,reverse,-1,-1);
 
 	if (status==READLOG_ERROR_MEMORY) {
 		printf("<P><DIV CLASS='warningMessage'>Run out of memory..., showing all I could gather!</DIV></P>");
diff --git a/cgi/readlogs.c b/cgi/readlogs.c
index 67ab74a..6e9c8fc 100644
--- a/cgi/readlogs.c
+++ b/cgi/readlogs.c
@@ -83,7 +83,7 @@ int add_log_filter(int requested_filter, int include_exclude) {
  * Thats the actual function for reading entries.
  */
 
-int get_log_entries(char *log_file, char *search_string, int reverse) {
+int get_log_entries(char *log_file, char *search_string, int reverse,time_t ts_start, time_t ts_end) {
 	char *input=NULL;
 	char *temp_buffer=NULL;
 	int error=READLOG_OK;
@@ -163,6 +163,10 @@ int get_log_entries(char *log_file, char *search_string, int reverse) {
 			temp_buffer=strtok(input,"]");
 			timestamp=(temp_buffer==NULL)?0L:strtoul(temp_buffer+1,NULL,10);
 
+			/* skip line if out of time range */
+			if ((ts_start>=0 && timestamp<ts_start) || (ts_end>=0 && timestamp>ts_end))
+				continue;
+
 			/* get log entry text */
 			temp_buffer=strtok(NULL,"\n");
 			
diff --git a/cgi/showlog.c b/cgi/showlog.c
index 829ab77..fb33acb 100644
--- a/cgi/showlog.c
+++ b/cgi/showlog.c
@@ -629,7 +629,7 @@ void display_logentries() {
 		get_log_archive_to_use(current_archive,filename,sizeof(filename)-1);
 
 		/* scan the log file for archived state data */
-		status=get_log_entries(filename,query_string,reverse);
+		status=get_log_entries(filename,query_string,reverse,ts_start,ts_end);
 
 		/* Stop if we out of memory or have a wrong filter */
 		if (status==READLOG_ERROR_FILTER || status==READLOG_ERROR_MEMORY) {
@@ -691,13 +691,6 @@ void display_logentries() {
 
 		for(temp_entry=next_log_entry();temp_entry!=NULL;temp_entry=next_log_entry()) {
 
-			/* check time */
-			if (temp_entry->timestamp<ts_start || temp_entry->timestamp>ts_end) {
-				my_free(temp_entry->entry_text);
-				my_free(temp_entry);
-				continue;
-			}
-
 			if(temp_entry->type==LOGENTRY_STARTUP){
 				strcpy(image,START_ICON);
 				strcpy(image_alt,START_ICON_ALT);
diff --git a/cgi/summary.c b/cgi/summary.c
index 3321fd4..424eef0 100644
--- a/cgi/summary.c
+++ b/cgi/summary.c
@@ -1169,7 +1169,7 @@ void scan_log_file_for_archived_event_data(char *filename){
 	logentry *temp_entry=NULL;
 
 	/* read log entries */
-	status=get_log_entries(filename,NULL,FALSE);
+	status=get_log_entries(filename,NULL,FALSE,t1,t2);
 
 	if (status==READLOG_OK) {
 
diff --git a/cgi/trends.c b/cgi/trends.c
index e2737a4..8ed119e 100644
--- a/cgi/trends.c
+++ b/cgi/trends.c
@@ -2441,7 +2441,7 @@ void scan_log_file_for_archived_state_data(char *filename){
 		fflush(NULL);
 	}
 
-	status = get_log_entries(filename,NULL,FALSE);
+	status = get_log_entries(filename,NULL,FALSE,t1-(60*60*24*backtrack_archives),t2);
 
 	if (status!=READLOG_OK) {
 #ifdef DEBUG
diff --git a/include/readlogs.h b/include/readlogs.h
index 174e40d..fdfc8fe 100644
--- a/include/readlogs.h
+++ b/include/readlogs.h
@@ -142,7 +142,7 @@ int push_lifo(char *);
 char *pop_lifo(void);
 
 
-int get_log_entries(char *, char *, int);			/* for reading and filtering logs */
+int get_log_entries(char *, char *, int, time_t, time_t);			/* for reading and filtering logs */
 int add_log_filter(int, int);
 logentry *next_log_entry(void);
 void free_log_entries(void);





More information about the icinga-checkins mailing list