[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: classic ui: add trend timeperiod feature to locate the next problem (Carsten Emde) #1074

git at icinga.org git at icinga.org
Wed Jan 5 15:18:30 CET 2011


Module: icinga-core
Branch: mfriedrich/core
Commit: d1337cb588cf1347e23a235b5d26c8cbc7d8f5d6
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=d1337cb588cf1347e23a235b5d26c8cbc7d8f5d6

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Jan  5 13:44:06 2011 +0100

classic ui: add trend timeperiod feature to locate the next problem (Carsten Emde) #1074

[--SNIP--]
In order to allow for scanning through the remaining recording and
searching for the occurrence of the next host or service problem,
the addtional time period tag TIMEPERIOD_NEXTPROBLEM was introduced.
If selected, the time period of the next diplay will be selected in
such a way that the full duration of the next problem will be
displayed at the center of the image. If only the start time is
available, because the problem is still present, the time window
of the image falls back to the 24-hour period.
[--SNIP--]

fixes #1074

---

 AUTHORS      |    1 +
 Changelog    |    1 +
 THANKS       |    1 +
 cgi/trends.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 95 insertions(+), 6 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 33fba16..a166712 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -4,6 +4,7 @@ Ricardo Bartels
 Jochen Bern
 Rune Darrud
 Karl DeBisschop
+Carsten Emde
 Andreas Ericsson
 Duncan Ferguson
 Michael Friedrich
diff --git a/Changelog b/Changelog
index 066c95e..9d477a5 100644
--- a/Changelog
+++ b/Changelog
@@ -18,6 +18,7 @@ ENHANCEMENTS
 * classic ui: add url_stylesheet_path to cgi.cfg to allow custom css path #898
 * classic ui: change color of unknown/unreachable state to more warm signalling purple #1029
 * classic ui: move "add service/host comment" to the command box on extinfo.cgi, abandon remove all in favor of multiple comment delete #837
+* classic ui: add trend timeperiod feature to locate the next problem (Carsten Emde) #1074
 
 * core: add support for same host service dependencies with servicegroups (Mathieu Gagné) #928
 * core: allow eventbroker modules to override sending notifications (Matthieu Kermagoret) #1057
diff --git a/THANKS b/THANKS
index 3ecf174..fb5713f 100644
--- a/THANKS
+++ b/THANKS
@@ -89,6 +89,7 @@ in various ways.  If we missed your name, let us know.
 * Matthias Eble
 * Ari Edelkind
 * Matthias Eichler
+* Carsten Emde
 * Rob Enders
 * Lars Engels
 * Andreas Ericsson
diff --git a/cgi/trends.c b/cgi/trends.c
index 1600e9e..8f670c8 100644
--- a/cgi/trends.c
+++ b/cgi/trends.c
@@ -97,6 +97,7 @@ extern skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];
 #define TIMEPERIOD_LAST24HOURS	11
 #define TIMEPERIOD_LAST7DAYS	12
 #define TIMEPERIOD_LAST31DAYS   13
+#define TIMEPERIOD_NEXTPROBLEM  14
 
 #define MIN_TIMESTAMP_SPACING	10
 
@@ -183,7 +184,7 @@ int color_yellow=0;
 int color_orange=0;
 FILE *image_file=NULL;
 
-int image_width=600;
+int image_width=900;
 int image_height=300;
 
 #define HOST_DRAWING_WIDTH	498
@@ -233,6 +234,8 @@ unsigned long time_warning=0L;
 unsigned long time_unknown=0L;
 unsigned long time_critical=0L;
 
+int problem_found;
+
 int display_type=DISPLAY_NO_TRENDS;
 int show_all_hosts=TRUE;
 int show_all_hostgroups=TRUE;
@@ -266,11 +269,14 @@ int main(int argc, char **argv){
 	time_t t3;
 	time_t current_time;
 	struct tm *t;
-
+	time_t old_t1, old_t2;
+	archived_state *temp_as;
+	time_t problem_t1, problem_t2=0;
+	time_t margin;
 
 	/* reset internal CGI variables */
 	reset_cgi_vars();
-	
+
 	/* read the CGI configuration file */
 	result=read_cgi_config_file(get_cgi_config_location());
 	if(result==ERROR){
@@ -363,9 +369,12 @@ int main(int argc, char **argv){
 		if(t1>t2)
 			t1=t2-(60*60*24);
 	        }
-			
+
 	if(content_type==HTML_CONTENT && display_header==TRUE){
 
+		old_t1=t1;
+		old_t2=t2;
+
 		/* begin top table */
 		printf("<table border=0 width=100%% cellspacing=0 cellpadding=0>\n");
 		printf("<tr>\n");
@@ -382,6 +391,67 @@ int main(int argc, char **argv){
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		display_info_table(temp_buffer,FALSE,&current_authdata, daemon_check);
 
+		if (timeperiod_type==TIMEPERIOD_NEXTPROBLEM) {
+
+			t1=t2;
+			t2=current_time;
+			read_archived_state_data();
+			problem_found=FALSE;
+
+			if(display_type==DISPLAY_HOST_TRENDS){
+				for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){
+					if((temp_as->entry_type==HOST_DOWN || temp_as->entry_type==HOST_UNREACHABLE) && temp_as->time_stamp>t1){
+						problem_t1=temp_as->time_stamp;
+						problem_found=TRUE;
+						break;
+					}
+				}
+
+				if(problem_found==TRUE){
+					for(;temp_as!=NULL;temp_as=temp_as->next){
+						if(temp_as->entry_type==AS_HOST_UP && temp_as->time_stamp>problem_t1){
+							problem_t2=temp_as->time_stamp;
+							break;
+						}
+					}
+				}
+			} else{
+				for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){
+					if((temp_as->entry_type==AS_SVC_UNKNOWN || temp_as->entry_type==AS_SVC_CRITICAL || temp_as->entry_type==AS_SVC_WARNING) && temp_as->time_stamp>t1){
+						problem_t1=temp_as->time_stamp;
+						problem_found=TRUE;
+						break;
+					}
+				}
+
+				if(problem_found==TRUE){
+					for(;temp_as!=NULL;temp_as=temp_as->next){
+						if(temp_as->entry_type==AS_SVC_OK && temp_as->time_stamp>problem_t1){
+							problem_t2=temp_as->time_stamp;
+							break;
+						}
+					}
+				}
+			}
+
+			if(problem_found==TRUE) {
+				if (problem_t2==0){
+					margin=12*60*60;
+					problem_t2=problem_t1;
+				} else {
+					margin=(problem_t2-problem_t1)/2;
+				}
+
+				t1=problem_t1-margin;
+				t2=problem_t2+margin;
+			}
+		}
+
+		if (timeperiod_type==TIMEPERIOD_NEXTPROBLEM && problem_found==FALSE){
+			t1=old_t1;
+			t2=old_t2;
+		}
+
 		if(display_type!=DISPLAY_NO_TRENDS && input_type==GET_INPUT_NONE){
 
 			printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n");
@@ -513,6 +583,10 @@ int main(int argc, char **argv){
 			printf("<option value=lastmonth %s>Last Month\n",(timeperiod_type==TIMEPERIOD_LASTMONTH)?"SELECTED":"");
 			printf("<option value=thisyear %s>This Year\n",(timeperiod_type==TIMEPERIOD_THISYEAR)?"SELECTED":"");
 			printf("<option value=lastyear %s>Last Year\n",(timeperiod_type==TIMEPERIOD_LASTYEAR)?"SELECTED":"");
+			if(display_type==DISPLAY_HOST_TRENDS)
+				printf("<option value=nextproblem %s>Next Host Problem\n",(timeperiod_type==TIMEPERIOD_NEXTPROBLEM)?"SELECTED":"");
+			else
+				printf("<option value=nextproblem %s>Next Service Problem\n",(timeperiod_type==TIMEPERIOD_NEXTPROBLEM)?"SELECTED":"");
 			printf("</select>\n");
 			printf("</td><td CLASS='optBoxItem' valign=top align=left>\n");
 			printf("<select name='zoom'>\n");
@@ -590,6 +664,13 @@ int main(int argc, char **argv){
 	        }
 #endif
 
+	if(timeperiod_type==TIMEPERIOD_NEXTPROBLEM && problem_found==FALSE) {
+		printf("<P><DIV ALIGN=CENTER CLASS='errorMessage'>No problem found between end of display and end of recording</DIV></P>\n");
+
+		document_footer(CGI_ID);
+		free_memory();
+		return ERROR;
+	}
 
 	/* set drawing parameters, etc */
 
@@ -599,7 +680,7 @@ int main(int argc, char **argv){
 	        }
 	else{
 		image_height=300;
-		image_width=600;
+		image_width=900;
 	        }
 
 	if(display_type==DISPLAY_HOST_TRENDS){
@@ -761,7 +842,7 @@ int main(int argc, char **argv){
 			if(backtrack_archives>0)
 				printf("&backtrack=%d",backtrack_archives);
 			printf("&zoom=%d",zoom_factor);
-			printf("' BORDER=0 name='trendsimage' useMap='#trendsmap' width=900>\n");
+			printf("' BORDER=0 name='trendsimage' useMap='#trendsmap' width=%d>\n", image_width);
 			printf("</DIV>\n");
 		        }
 
@@ -1319,6 +1400,8 @@ int process_cgivars(void){
 				timeperiod_type=TIMEPERIOD_THISYEAR;
 			else if(!strcmp(variables[x],"lastyear"))
 				timeperiod_type=TIMEPERIOD_LASTYEAR;
+			else if(!strcmp(variables[x],"nextproblem"))
+				timeperiod_type=TIMEPERIOD_NEXTPROBLEM;
 			else if(!strcmp(variables[x],"last24hours"))
 				timeperiod_type=TIMEPERIOD_LAST24HOURS;
 			else if(!strcmp(variables[x],"last7days"))
@@ -2720,6 +2803,9 @@ void convert_timeperiod_to_times(int type){
 		t->tm_year--;
 		t1=mktime(t);
 		break;
+	case TIMEPERIOD_NEXTPROBLEM:
+		/* Time period will be defined later */
+		break;
 	case TIMEPERIOD_LAST7DAYS:
 		t2=current_time;
 		t1=current_time-(7*24*60*60);





More information about the icinga-checkins mailing list