Index: cgi/avail.c =================================================================== RCS file: /cvsroot/nagios/nagios/cgi/avail.c,v retrieving revision 1.23 diff -u -r1.23 avail.c --- cgi/avail.c 21 Jan 2004 04:56:09 -0000 1.23 +++ cgi/avail.c 15 Sep 2004 10:48:53 -0000 @@ -41,6 +41,7 @@ extern hostgroup *hostgroup_list; extern servicegroup *servicegroup_list; extern service *service_list; +extern timeperiod *timeperiod_list; extern int log_rotation_method; @@ -104,7 +105,7 @@ #define MAX_ARCHIVE_BACKTRACKS 60 authdata current_authdata; - +timeperiod *current_timeperiod = NULL; typedef struct archived_state_struct{ time_t time_stamp; int entry_type; @@ -600,6 +601,7 @@ /* step 3 - ask user for report date range */ if(get_date_parts==TRUE){ + timeperiod *temp_timeperiod; time(¤t_time); t=localtime(¤t_time); @@ -700,6 +702,22 @@ printf("
\n"); + // Added new dropdown to select timeperiods. + + printf(""); + printf("Report time Period:\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("
\n"); + printf("Assume Initial States:\n"); printf("\n"); printf("\n"); printf("\n"); - } + } printf("First Assumed Service State:\n"); printf("\n"); @@ -1555,13 +1573,29 @@ if(variables[x]==NULL){ error=TRUE; break; - } + } if(!strcmp(variables[x],"yes")) show_scheduled_downtime=TRUE; else show_scheduled_downtime=FALSE; - } + } + /* we found the report timeperiod option */ + else if(!strcmp(variables[x],"rpttimeperiod")){ + timeperiod *temp_timeperiod; + x++; + if(variables[x]==NULL){ + error=TRUE; + break; + } + + for(temp_timeperiod=timeperiod_list;temp_timeperiod!=NULL;temp_timeperiod=temp_timeperiod->next){ + if (!strcmp(url_encode(temp_timeperiod->name),variables[x])) { + current_timeperiod = temp_timeperiod; + break; + } + } + } } @@ -1900,6 +1934,8 @@ } +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define min(a,b) (((a) < (b)) ? (a) : (b)) /* computes availability times */ void compute_subject_availability_times(int first_state,int last_state,time_t real_start_time,time_t start_time,time_t end_time,avail_subject *subject, archived_state *as){ @@ -1928,8 +1964,62 @@ if(end_timetm_sec=0; + t->tm_min=0; + t->tm_hour=0; + unsigned long midnight_today=(unsigned long)mktime(t); + int weekday = t->tm_wday; + + while (midnight_today midnight_today) + temp_start = start_time - midnight_today; +#ifdef DEBUG + printf("Matching: %ld -> %ld. (%ld -> %ld)
\n",temp_start, temp_end, midnight_today+temp_start, midnight_today+temp_end); +#endif + /* check all time ranges for this day of the week */ + for(temp_timerange=current_timeperiod->days[weekday]; + temp_timerange!=NULL; + temp_timerange=temp_timerange->next){ + unsigned long start, end; +#ifdef DEBUG + printf("
  • Matching in timerang[%d]: %d -> %d (%ld -> %ld)
    \n",weekday, temp_timerange->range_start, temp_timerange->range_end,temp_start, temp_end); +#endif + start = max(temp_timerange->range_start, temp_start); + end = min(temp_timerange->range_end, temp_end); + + if (start < end) { + temp_duration += end-start; +#ifdef DEBUG + printf("
  • Matched time: %ld -> %ld = %d
    \n",start, end, temp_duration); +#endif + } +#ifdef DEBUG + else { + printf("
  • Ignored time: %ld -> %ld
    \n",start, end); + } +#endif + } + state_duration+=temp_duration; + temp_start = 0; + midnight_today += 86400; + if (++weekday>6) + weekday = 0; + } + } else { + /* calculate time in this state */ + state_duration = (unsigned long)(end_time-start_time); + } /* can't graph if we don't have data... */ if(first_state==AS_NO_DATA || last_state==AS_NO_DATA){ @@ -3738,9 +3828,55 @@ char *bgclass=""; int odd=1; + // MickeM Attempt to handle the current time_period + if (current_timeperiod) { + // "A day" is 86400 seconds + struct tm *t=localtime(&t1); + total_time = 0; + + // calculate the start of the day (midnight, 00:00 hours) + t->tm_sec=0; + t->tm_min=0; + t->tm_hour=0; + unsigned long midnight_today=(unsigned long)mktime(t); + int weekday = t->tm_wday; + + // printf("%ld < %ld .
    \n",midnight_today + temp_end, end_time); + total_time = 0; + while (midnight_today midnight_today) + temp_start = t1 - midnight_today; + + // check all time ranges for this day of the week + for(temp_timerange=current_timeperiod->days[weekday]; + temp_timerange!=NULL; + temp_timerange=temp_timerange->next){ + unsigned long start, end; + start = max(temp_timerange->range_start, temp_start); + end = min(temp_timerange->range_end, temp_end); +#ifdef DEBUG + printf("
  • Matching in timerange[%d]: %d -> %d (%ld -> %ld) %d -> %d = %ld
    \n",weekday, temp_timerange->range_start, temp_timerange->range_end,temp_start, temp_end, start, end, end-start); +#endif + if (end > start) + temp_duration += end-start; + } + total_time+=temp_duration; + temp_start = 0; + midnight_today += 86400; + if (++weekday>6) + weekday = 0; + } + } else { + total_time=t2-t1; + } - total_time=t2-t1; - +#ifdef DEBUG + printf("Total time: '%ld' seconds
    \n",total_time); +#endif /* show data for a specific host */ if(show_all_hosts==FALSE){