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.
A small fix was required to solve an inconsistency of the image
width (600 vs. 900 pixels).
Signed-off-by: Carsten Emde
---
cgi/trends.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 86 insertions(+), 4 deletions(-)
Index: nagios-2.12/cgi/trends.c
===================================================================
--- nagios-2.12.orig/cgi/trends.c
+++ nagios-2.12/cgi/trends.c
@@ -98,7 +98,8 @@ extern skiplist *object_skiplists[NUM_OB
#define TIMEPERIOD_LASTYEAR 10
#define TIMEPERIOD_LAST24HOURS 11
#define TIMEPERIOD_LAST7DAYS 12
-#define TIMEPERIOD_LAST31DAYS 13
+#define TIMEPERIOD_LAST31DAYS 13
+#define TIMEPERIOD_NEXTPROBLEM 14
#define MIN_TIMESTAMP_SPACING 10
@@ -192,7 +193,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
@@ -242,6 +243,7 @@ unsigned long time_warning=0L;
unsigned long time_unknown=0L;
unsigned long time_critical=0L;
+int problem_found;
@@ -363,6 +365,7 @@ int main(int argc, char **argv){
}
if(mode==CREATE_HTML && display_header==TRUE){
+ time_t old_t1=t1, old_t2=t2;
/* begin top table */
printf("\n");
@@ -380,6 +383,69 @@ int main(int argc, char **argv){
temp_buffer[sizeof(temp_buffer)-1]='\x0';
display_info_table(temp_buffer,FALSE,¤t_authdata);
+ if (timeperiod_type==TIMEPERIOD_NEXTPROBLEM) {
+ archived_state *temp_as;
+ time_t problem_t1, problem_t2=0;
+
+ 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) {
+ time_t margin;
+
+ 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("\n");
@@ -504,6 +570,10 @@ int main(int argc, char **argv){
printf("Last Month\n",(timeperiod_type==TIMEPERIOD_LASTMONTH)?"SELECTED":"");
printf("This Year\n",(timeperiod_type==TIMEPERIOD_THISYEAR)?"SELECTED":"");
prin
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]