![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * TRENDS.C - Icinga State Trends CGI 00004 * 00005 * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00007 * 00008 * License: 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License version 2 as 00012 * published by the Free Software Foundation. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00022 * 00023 *****************************************************************************/ 00024 00025 #include "../include/config.h" 00026 #include "../include/common.h" 00027 #include "../include/objects.h" 00028 #include "../include/comments.h" 00029 #include "../include/statusdata.h" 00030 #include "../include/readlogs.h" 00031 00032 #include "../include/cgiutils.h" 00033 #include "../include/getcgi.h" 00034 #include "../include/cgiauth.h" 00035 00036 #include <gd.h> /* Boutell's GD library function */ 00037 #include <gdfonts.h> /* GD library small font definition */ 00038 00039 00040 /*#define DEBUG 1*/ 00041 00042 00043 extern char main_config_file[MAX_FILENAME_LENGTH]; 00044 extern char url_html_path[MAX_FILENAME_LENGTH]; 00045 extern char url_images_path[MAX_FILENAME_LENGTH]; 00046 extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; 00047 extern char url_js_path[MAX_FILENAME_LENGTH]; 00048 extern char physical_images_path[MAX_FILENAME_LENGTH]; 00049 00050 extern int log_rotation_method; 00051 00052 extern host *host_list; 00053 extern service *service_list; 00054 extern logentry *entry_list; 00055 00056 #include "../include/skiplist.h" 00057 extern skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS]; 00058 00059 /* archived state types */ 00060 #define AS_CURRENT_STATE -1 /* special case for initial assumed state */ 00061 #define AS_NO_DATA 0 00062 #define AS_PROGRAM_END 1 00063 #define AS_PROGRAM_START 2 00064 #define AS_HOST_UP 3 00065 #define AS_HOST_DOWN 4 00066 #define AS_HOST_UNREACHABLE 5 00067 #define AS_SVC_OK 6 00068 #define AS_SVC_UNKNOWN 7 00069 #define AS_SVC_WARNING 8 00070 #define AS_SVC_CRITICAL 9 00071 00072 #define AS_SOFT_STATE 1 00073 #define AS_HARD_STATE 2 00074 00075 /* display types */ 00076 #define DISPLAY_HOST_TRENDS 0 00077 #define DISPLAY_SERVICE_TRENDS 1 00078 #define DISPLAY_NO_TRENDS 2 00079 00080 /* input types */ 00081 #define GET_INPUT_NONE 0 00082 #define GET_INPUT_TARGET_TYPE 1 00083 #define GET_INPUT_HOST_TARGET 2 00084 #define GET_INPUT_SERVICE_TARGET 3 00085 #define GET_INPUT_OPTIONS 4 00086 00087 #define MIN_TIMESTAMP_SPACING 10 00088 00089 #define MAX_ARCHIVE_SPREAD 65 00090 #define MAX_ARCHIVE 65 00091 #define MAX_ARCHIVE_BACKTRACKS 60 00092 00093 authdata current_authdata; 00094 00095 typedef struct archived_state_struct{ 00096 time_t time_stamp; 00097 int entry_type; 00098 int processed_state; 00099 int state_type; 00100 char *state_info; 00101 struct archived_state_struct *next; 00102 }archived_state; 00103 00104 00105 archived_state *as_list=NULL; 00106 00107 time_t t1; 00108 time_t t2; 00109 00110 int start_second=0; 00111 int start_minute=0; 00112 int start_hour=0; 00113 int start_day=1; 00114 int start_month=1; 00115 int start_year=2000; 00116 int end_second=0; 00117 int end_minute=0; 00118 int end_hour=24; 00119 int end_day=1; 00120 int end_month=1; 00121 int end_year=2000; 00122 00123 extern int content_type; 00124 int input_type=GET_INPUT_NONE; 00125 int timeperiod_type=TIMEPERIOD_LAST24HOURS; 00126 int compute_time_from_parts=FALSE; 00127 00128 int display_popups=TRUE; 00129 int use_map=TRUE; 00130 int small_image=FALSE; 00131 extern int embedded; 00132 extern int display_header; 00133 extern int daemon_check; 00134 00135 int assume_initial_states=TRUE; 00136 int assume_state_retention=TRUE; 00137 int assume_states_during_notrunning=TRUE; 00138 int include_soft_states=FALSE; 00139 int ignore_daemon_restart=FALSE; 00140 00141 00142 void graph_all_trend_data(void); 00143 void graph_trend_data(int,int,time_t,time_t,time_t,char *); 00144 void draw_timestamps(void); 00145 void draw_timestamp(int,time_t); 00146 void draw_time_breakdowns(void); 00147 void draw_horizontal_grid_lines(void); 00148 void draw_dashed_line(int,int,int,int,int); 00149 00150 int convert_host_state_to_archived_state(int); 00151 int convert_service_state_to_archived_state(int); 00152 void add_archived_state(int,int,time_t,char *); 00153 void free_archived_state_list(void); 00154 void read_archived_state_data(void); 00155 void scan_log_file_for_archived_state_data(char *); 00156 void scan_log_file_for_archived_state_data_old(char *); 00157 void compute_report_times(void); 00158 void get_time_breakdown_string(unsigned long,unsigned long,char *,char *buffer,int); 00159 00160 int process_cgivars(void); 00161 00162 gdImagePtr trends_image=0; 00163 int color_white=0; 00164 int color_black=0; 00165 int color_red=0; 00166 int color_darkred=0; 00167 int color_green=0; 00168 int color_darkgreen=0; 00169 int color_yellow=0; 00170 int color_orange=0; 00171 FILE *image_file=NULL; 00172 00173 int image_width=900; 00174 int image_height=300; 00175 00176 #define HOST_DRAWING_WIDTH 498 00177 #define HOST_DRAWING_HEIGHT 70 00178 #define HOST_DRAWING_X_OFFSET 116 00179 #define HOST_DRAWING_Y_OFFSET 55 00180 00181 #define SVC_DRAWING_WIDTH 498 00182 #define SVC_DRAWING_HEIGHT 90 00183 #define SVC_DRAWING_X_OFFSET 116 00184 #define SVC_DRAWING_Y_OFFSET 55 00185 00186 #define SMALL_HOST_DRAWING_WIDTH 500 00187 #define SMALL_HOST_DRAWING_HEIGHT 20 00188 #define SMALL_HOST_DRAWING_X_OFFSET 0 00189 #define SMALL_HOST_DRAWING_Y_OFFSET 0 00190 00191 #define SMALL_SVC_DRAWING_WIDTH 500 00192 #define SMALL_SVC_DRAWING_HEIGHT 20 00193 #define SMALL_SVC_DRAWING_X_OFFSET 0 00194 #define SMALL_SVC_DRAWING_Y_OFFSET 0 00195 00196 int drawing_width=0; 00197 int drawing_height=0; 00198 00199 int drawing_x_offset=0; 00200 int drawing_y_offset=0; 00201 00202 int last_known_state=AS_NO_DATA; 00203 00204 int zoom_factor=4; 00205 int backtrack_archives=2; 00206 int earliest_archive=0; 00207 time_t earliest_time; 00208 time_t latest_time; 00209 int earliest_state=AS_NO_DATA; 00210 int latest_state=AS_NO_DATA; 00211 00212 int initial_assumed_host_state=AS_NO_DATA; 00213 int initial_assumed_service_state=AS_NO_DATA; 00214 00215 unsigned long time_up=0L; 00216 unsigned long time_down=0L; 00217 unsigned long time_unreachable=0L; 00218 unsigned long time_ok=0L; 00219 unsigned long time_warning=0L; 00220 unsigned long time_unknown=0L; 00221 unsigned long time_critical=0L; 00222 00223 int problem_found; 00224 00225 int display_type=DISPLAY_NO_TRENDS; 00226 int show_all_hosts=TRUE; 00227 int show_all_hostgroups=TRUE; 00228 int show_all_servicegroups=TRUE; 00229 00230 char *host_name=""; 00231 char *host_filter=NULL; 00232 char *hostgroup_name=NULL; 00233 char *servicegroup_name=NULL; 00234 char *service_desc=""; 00235 char *service_filter=NULL; 00236 00237 int CGI_ID=TRENDS_CGI_ID; 00238 00239 int main(int argc, char **argv){ 00240 int result=OK; 00241 char temp_buffer[MAX_INPUT_BUFFER]; 00242 char image_template[MAX_INPUT_BUFFER]; 00243 char start_time[MAX_INPUT_BUFFER]; 00244 char end_time[MAX_INPUT_BUFFER]; 00245 int string_width; 00246 int string_height; 00247 char start_timestring[MAX_INPUT_BUFFER]; 00248 char end_timestring[MAX_INPUT_BUFFER]; 00249 host *temp_host = NULL; 00250 service *temp_service = NULL; 00251 int is_authorized=TRUE; 00252 int found=FALSE; 00253 int days,hours,minutes,seconds; 00254 char *first_service=NULL; 00255 time_t t3; 00256 time_t current_time; 00257 struct tm *t; 00258 time_t old_t1; 00259 time_t old_t2; 00260 archived_state *temp_as; 00261 time_t problem_t1=0; 00262 time_t problem_t2=0; 00263 time_t margin; 00264 00265 /* reset internal CGI variables */ 00266 reset_cgi_vars(); 00267 00268 /* read the CGI configuration file */ 00269 result=read_cgi_config_file(get_cgi_config_location()); 00270 if(result==ERROR){ 00271 if(content_type==HTML_CONTENT){ 00272 document_header(CGI_ID,FALSE); 00273 print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE); 00274 document_footer(CGI_ID); 00275 } 00276 return ERROR; 00277 } 00278 00279 /* read the main configuration file */ 00280 result=read_main_config_file(main_config_file); 00281 if(result==ERROR){ 00282 if(content_type==HTML_CONTENT){ 00283 document_header(CGI_ID,FALSE); 00284 print_error(main_config_file, ERROR_CGI_MAIN_CFG); 00285 document_footer(CGI_ID); 00286 } 00287 return ERROR; 00288 } 00289 00290 00291 /* initialize time period to last 24 hours */ 00292 time(¤t_time); 00293 t2=current_time; 00294 t1=(time_t)(current_time-(60*60*24)); 00295 00296 /* default number of backtracked archives */ 00297 switch(log_rotation_method){ 00298 case LOG_ROTATION_MONTHLY: 00299 backtrack_archives=1; 00300 break; 00301 case LOG_ROTATION_WEEKLY: 00302 backtrack_archives=2; 00303 break; 00304 case LOG_ROTATION_DAILY: 00305 backtrack_archives=4; 00306 break; 00307 case LOG_ROTATION_HOURLY: 00308 backtrack_archives=8; 00309 break; 00310 default: 00311 backtrack_archives=2; 00312 break; 00313 } 00314 00315 /* get the arguments passed in the URL */ 00316 process_cgivars(); 00317 00318 /* get authentication information */ 00319 get_authentication_information(¤t_authdata); 00320 00321 result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA); 00322 if(result==ERROR){ 00323 if(content_type==HTML_CONTENT){ 00324 document_header(CGI_ID,FALSE); 00325 print_error(NULL, ERROR_CGI_OBJECT_DATA); 00326 document_footer(CGI_ID); 00327 } 00328 return ERROR; 00329 } 00330 00331 /* read all status data */ 00332 result=read_all_status_data(get_cgi_config_location(),READ_ALL_STATUS_DATA); 00333 if(result==ERROR && daemon_check==TRUE){ 00334 if(content_type==HTML_CONTENT){ 00335 document_header(CGI_ID,FALSE); 00336 print_error(NULL, ERROR_CGI_STATUS_DATA); 00337 document_footer(CGI_ID); 00338 } 00339 return ERROR; 00340 } 00341 00342 document_header(CGI_ID,TRUE); 00343 00344 if(compute_time_from_parts==TRUE) 00345 compute_report_times(); 00346 00347 /* make sure times are sane, otherwise swap them */ 00348 if(t2<t1){ 00349 t3=t2; 00350 t2=t1; 00351 t1=t3; 00352 } 00353 00354 /* don't let user create reports in the future */ 00355 if(t2>current_time){ 00356 t2=current_time; 00357 if(t1>t2) 00358 t1=t2-(60*60*24); 00359 } 00360 00361 if(content_type==HTML_CONTENT && display_header==TRUE){ 00362 00363 old_t1=t1; 00364 old_t2=t2; 00365 00366 /* begin top table */ 00367 printf("<table border=0 width=100%% cellspacing=0 cellpadding=0>\n"); 00368 printf("<tr>\n"); 00369 00370 /* left column of the first row */ 00371 printf("<td align=left valign=top width=33%%>\n"); 00372 00373 if(display_type==DISPLAY_HOST_TRENDS) 00374 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Host State Trends"); 00375 else if(display_type==DISPLAY_SERVICE_TRENDS) 00376 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Service State Trends"); 00377 else 00378 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Host and Service State Trends"); 00379 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00380 display_info_table(temp_buffer,FALSE,¤t_authdata, daemon_check); 00381 00382 if (timeperiod_type==TIMEPERIOD_NEXTPROBLEM) { 00383 problem_t1=0; 00384 problem_t2=0; 00385 00386 t1=t2; 00387 t2=current_time; 00388 read_archived_state_data(); 00389 problem_found=FALSE; 00390 00391 if(display_type==DISPLAY_HOST_TRENDS){ 00392 for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){ 00393 if((temp_as->entry_type==HOST_DOWN || temp_as->entry_type==HOST_UNREACHABLE) && temp_as->time_stamp>t1){ 00394 problem_t1=temp_as->time_stamp; 00395 problem_found=TRUE; 00396 break; 00397 } 00398 } 00399 00400 if(problem_found==TRUE){ 00401 for(;temp_as!=NULL;temp_as=temp_as->next){ 00402 if(temp_as->entry_type==AS_HOST_UP && temp_as->time_stamp>problem_t1){ 00403 problem_t2=temp_as->time_stamp; 00404 break; 00405 } 00406 } 00407 } 00408 } else{ 00409 for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){ 00410 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){ 00411 problem_t1=temp_as->time_stamp; 00412 problem_found=TRUE; 00413 break; 00414 } 00415 } 00416 00417 if(problem_found==TRUE){ 00418 for(;temp_as!=NULL;temp_as=temp_as->next){ 00419 if(temp_as->entry_type==AS_SVC_OK && temp_as->time_stamp>problem_t1){ 00420 problem_t2=temp_as->time_stamp; 00421 break; 00422 } 00423 } 00424 } 00425 } 00426 00427 if(problem_found==TRUE) { 00428 if (problem_t2==0){ 00429 margin=12*60*60; 00430 problem_t2=problem_t1; 00431 } else { 00432 margin=(problem_t2-problem_t1)/2; 00433 } 00434 00435 t1=problem_t1-margin; 00436 t2=problem_t2+margin; 00437 } 00438 } 00439 00440 if (timeperiod_type==TIMEPERIOD_NEXTPROBLEM && problem_found==FALSE){ 00441 t1=old_t1; 00442 t2=old_t2; 00443 } 00444 00445 if(display_type!=DISPLAY_NO_TRENDS && input_type==GET_INPUT_NONE){ 00446 00447 printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n"); 00448 printf("<TR><TD CLASS='linkBox'>\n"); 00449 00450 if(display_type==DISPLAY_HOST_TRENDS){ 00451 printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d&show_log_entries'>View Availability Report For This Host</a><BR>\n",AVAIL_CGI,url_encode(host_name),t1,t2,(include_soft_states==TRUE)?"yes":"no",(assume_state_retention==TRUE)?"yes":"no",(assume_initial_states==TRUE)?"yes":"no",(assume_states_during_notrunning==TRUE)?"yes":"no",initial_assumed_host_state,backtrack_archives); 00452 #ifdef USE_HISTROGRAM 00453 printf("<a href='%s?host=%s&t1=%lu&t2=%lu&assumestateretention=%s'>View Alert Histogram For This Host</a><BR>\n",HISTOGRAM_CGI,url_encode(host_name),t1,t2,(assume_state_retention==TRUE)?"yes":"no"); 00454 #endif 00455 printf("<a href='%s?host=%s'>View Status Detail For This Host</a><BR>\n",STATUS_CGI,url_encode(host_name)); 00456 printf("<a href='%s?host=%s'>View Alert History For This Host</a><BR>\n",HISTORY_CGI,url_encode(host_name)); 00457 printf("<a href='%s?host=%s'>View Notifications For This Host</a><BR>\n",NOTIFICATIONS_CGI,url_encode(host_name)); 00458 } 00459 else{ 00460 printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>View Trends For This Host</a><BR>\n",TRENDS_CGI,url_encode(host_name),t1,t2,(include_soft_states==TRUE)?"yes":"no",(assume_state_retention==TRUE)?"yes":"no",(assume_initial_states==TRUE)?"yes":"no",(assume_states_during_notrunning==TRUE)?"yes":"no",initial_assumed_service_state,backtrack_archives); 00461 printf("<a href='%s?host=%s",AVAIL_CGI,url_encode(host_name)); 00462 printf("&service=%s&t1=%lu&t2=%lu&assumestateretention=%s&includesoftstates=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d&show_log_entries'>View Availability Report For This Service</a><BR>\n",url_encode(service_desc),t1,t2,(include_soft_states==TRUE)?"yes":"no",(assume_state_retention==TRUE)?"yes":"no",(assume_initial_states==TRUE)?"yes":"no",(assume_states_during_notrunning==TRUE)?"yes":"no",initial_assumed_service_state,backtrack_archives); 00463 printf("<a href='%s?host=%s",HISTOGRAM_CGI,url_encode(host_name)); 00464 printf("&service=%s&t1=%lu&t2=%lu&assumestateretention=%s'>View Alert Histogram For This Service</a><BR>\n",url_encode(service_desc),t1,t2,(assume_state_retention==TRUE)?"yes":"no"); 00465 printf("<A HREF='%s?host=%s&",HISTORY_CGI,url_encode(host_name)); 00466 printf("service=%s'>View Alert History For This Service</A><BR>\n",url_encode(service_desc)); 00467 printf("<A HREF='%s?host=%s&",NOTIFICATIONS_CGI,url_encode(host_name)); 00468 printf("service=%s'>View Notifications For This Service</A><BR>\n",url_encode(service_desc)); 00469 } 00470 00471 printf("</TD></TR>\n"); 00472 printf("</TABLE>\n"); 00473 } 00474 00475 printf("</td>\n"); 00476 00477 /* center column of top row */ 00478 printf("<td align=center valign=top width=33%%>\n"); 00479 00480 if(display_type!=DISPLAY_NO_TRENDS && input_type==GET_INPUT_NONE){ 00481 00482 00483 /* find the host */ 00484 temp_host=find_host(host_name); 00485 00486 /* find the service */ 00487 temp_service=find_service(host_name,service_desc); 00488 00489 printf("<DIV ALIGN=CENTER CLASS='dataTitle'>\n"); 00490 if(display_type==DISPLAY_HOST_TRENDS) 00491 printf("Host '%s'",(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 00492 else if(display_type==DISPLAY_SERVICE_TRENDS) 00493 printf("Service '%s' On Host '%s'",(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 00494 printf("</DIV>\n"); 00495 00496 printf("<BR>\n"); 00497 00498 printf("<IMG SRC='%s%s' BORDER=0 ALT='%s State Trends' TITLE='%s State Trends'>\n",url_images_path,TRENDS_ICON,(display_type==DISPLAY_HOST_TRENDS)?"Host":"Service",(display_type==DISPLAY_HOST_TRENDS)?"Host":"Service"); 00499 00500 printf("<BR CLEAR=ALL>\n"); 00501 00502 get_time_string(&t1,start_timestring,sizeof(start_timestring)-1,SHORT_DATE_TIME); 00503 get_time_string(&t2,end_timestring,sizeof(end_timestring)-1,SHORT_DATE_TIME); 00504 printf("<div align=center class='reportRange'>%s to %s</div>\n",start_timestring,end_timestring); 00505 00506 get_time_breakdown((time_t)(t2-t1),&days,&hours,&minutes,&seconds); 00507 printf("<div align=center class='reportDuration'>Duration: %dd %dh %dm %ds</div>\n",days,hours,minutes,seconds); 00508 } 00509 00510 printf("</td>\n"); 00511 00512 /* right hand column of top row */ 00513 printf("<td align=right valign=bottom width=33%%>\n"); 00514 00515 printf("<form method=\"GET\" action=\"%s\">\n",TRENDS_CGI); 00516 printf("<table border=0 CLASS='optBox'>\n"); 00517 00518 if(display_type!=DISPLAY_NO_TRENDS && input_type==GET_INPUT_NONE){ 00519 00520 printf("<tr><td CLASS='optBoxItem' valign=top align=left>First assumed %s state:</td><td CLASS='optBoxItem' valign=top align=left>Backtracked archives:</td></tr>\n",(display_type==DISPLAY_HOST_TRENDS)?"host":"service"); 00521 printf("<tr><td CLASS='optBoxItem' valign=top align=left>"); 00522 00523 if(display_popups==FALSE) 00524 printf("<input type='hidden' name='nopopups' value=''>\n"); 00525 if(use_map==FALSE) 00526 printf("<input type='hidden' name='nomap' value=''>\n"); 00527 if(ignore_daemon_restart==TRUE) 00528 printf("<input type='hidden' name='ignorerestart' value=''>\n"); 00529 printf("<input type='hidden' name='t1' value='%lu'>\n",(unsigned long)t1); 00530 printf("<input type='hidden' name='t2' value='%lu'>\n",(unsigned long)t2); 00531 printf("<input type='hidden' name='host' value='%s'>\n",escape_string(host_name)); 00532 if(display_type==DISPLAY_SERVICE_TRENDS) 00533 printf("<input type='hidden' name='service' value='%s'>\n",escape_string(service_desc)); 00534 00535 printf("<input type='hidden' name='assumeinitialstates' value='%s'>\n",(assume_initial_states==TRUE)?"yes":"no"); 00536 printf("<input type='hidden' name='assumestateretention' value='%s'>\n",(assume_state_retention==TRUE)?"yes":"no"); 00537 printf("<input type='hidden' name='assumestatesduringnotrunning' value='%s'>\n",(assume_states_during_notrunning==TRUE)?"yes":"no"); 00538 printf("<input type='hidden' name='includesoftstates' value='%s'>\n",(include_soft_states==TRUE)?"yes":"no"); 00539 00540 if(display_type==DISPLAY_HOST_TRENDS){ 00541 printf("<input type='hidden' name='initialassumedservicestate' value='%d'>",initial_assumed_service_state); 00542 printf("<select name='initialassumedhoststate'>\n"); 00543 printf("<option value=%d %s>Unspecified\n",AS_NO_DATA,(initial_assumed_host_state==AS_NO_DATA)?"SELECTED":""); 00544 printf("<option value=%d %s>Current State\n",AS_CURRENT_STATE,(initial_assumed_host_state==AS_CURRENT_STATE)?"SELECTED":""); 00545 printf("<option value=%d %s>Host Up\n",AS_HOST_UP,(initial_assumed_host_state==AS_HOST_UP)?"SELECTED":""); 00546 printf("<option value=%d %s>Host Down\n",AS_HOST_DOWN,(initial_assumed_host_state==AS_HOST_DOWN)?"SELECTED":""); 00547 printf("<option value=%d %s>Host Unreachable\n",AS_HOST_UNREACHABLE,(initial_assumed_host_state==AS_HOST_UNREACHABLE)?"SELECTED":""); 00548 } 00549 else{ 00550 printf("<input type='hidden' name='initialassumedhoststate' value='%d'>",initial_assumed_host_state); 00551 printf("<select name='initialassumedservicestate'>\n"); 00552 printf("<option value=%d %s>Unspecified\n",AS_NO_DATA,(initial_assumed_service_state==AS_NO_DATA)?"SELECTED":""); 00553 printf("<option value=%d %s>Current State\n",AS_CURRENT_STATE,(initial_assumed_service_state==AS_CURRENT_STATE)?"SELECTED":""); 00554 printf("<option value=%d %s>Service Ok\n",AS_SVC_OK,(initial_assumed_service_state==AS_SVC_OK)?"SELECTED":""); 00555 printf("<option value=%d %s>Service Warning\n",AS_SVC_WARNING,(initial_assumed_service_state==AS_SVC_WARNING)?"SELECTED":""); 00556 printf("<option value=%d %s>Service Unknown\n",AS_SVC_UNKNOWN,(initial_assumed_service_state==AS_SVC_UNKNOWN)?"SELECTED":""); 00557 printf("<option value=%d %s>Service Critical\n",AS_SVC_CRITICAL,(initial_assumed_service_state==AS_SVC_CRITICAL)?"SELECTED":""); 00558 } 00559 printf("</select>\n"); 00560 printf("</td><td CLASS='optBoxItem' valign=top align=left>\n"); 00561 printf("<input type='text' name='backtrack' size='2' maxlength='2' value='%d'>\n",backtrack_archives); 00562 printf("</td></tr>\n"); 00563 00564 printf("<tr><td CLASS='optBoxItem' valign=top align=left>Report period:</td><td CLASS='optBoxItem' valign=top align=left>Zoom factor:</td></tr>\n"); 00565 printf("<tr><td CLASS='optBoxItem' valign=top align=left>\n"); 00566 printf("<select name='timeperiod'>\n"); 00567 printf("<option>[ Current time range ]\n"); 00568 printf("<option value=today %s>Today\n",(timeperiod_type==TIMEPERIOD_TODAY)?"SELECTED":""); 00569 printf("<option value=last24hours %s>Last 24 Hours\n",(timeperiod_type==TIMEPERIOD_LAST24HOURS)?"SELECTED":""); 00570 printf("<option value=yesterday %s>Yesterday\n",(timeperiod_type==TIMEPERIOD_YESTERDAY)?"SELECTED":""); 00571 printf("<option value=thisweek %s>This Week\n",(timeperiod_type==TIMEPERIOD_THISWEEK)?"SELECTED":""); 00572 printf("<option value=last7days %s>Last 7 Days\n",(timeperiod_type==TIMEPERIOD_LAST7DAYS)?"SELECTED":""); 00573 printf("<option value=lastweek %s>Last Week\n",(timeperiod_type==TIMEPERIOD_LASTWEEK)?"SELECTED":""); 00574 printf("<option value=thismonth %s>This Month\n",(timeperiod_type==TIMEPERIOD_THISMONTH)?"SELECTED":""); 00575 printf("<option value=last31days %s>Last 31 Days\n",(timeperiod_type==TIMEPERIOD_LAST31DAYS)?"SELECTED":""); 00576 printf("<option value=lastmonth %s>Last Month\n",(timeperiod_type==TIMEPERIOD_LASTMONTH)?"SELECTED":""); 00577 printf("<option value=thisyear %s>This Year\n",(timeperiod_type==TIMEPERIOD_THISYEAR)?"SELECTED":""); 00578 printf("<option value=lastyear %s>Last Year\n",(timeperiod_type==TIMEPERIOD_LASTYEAR)?"SELECTED":""); 00579 if(display_type==DISPLAY_HOST_TRENDS) 00580 printf("<option value=nextproblem %s>Next Host Problem\n",(timeperiod_type==TIMEPERIOD_NEXTPROBLEM)?"SELECTED":""); 00581 else 00582 printf("<option value=nextproblem %s>Next Service Problem\n",(timeperiod_type==TIMEPERIOD_NEXTPROBLEM)?"SELECTED":""); 00583 printf("</select>\n"); 00584 printf("</td><td CLASS='optBoxItem' valign=top align=left>\n"); 00585 printf("<select name='zoom'>\n"); 00586 printf("<option value=%d selected>%d\n",zoom_factor,zoom_factor); 00587 printf("<option value=+2>+2\n"); 00588 printf("<option value=+3>+3\n"); 00589 printf("<option value=+4>+4\n"); 00590 printf("<option value=-2>-2\n"); 00591 printf("<option value=-3>-3\n"); 00592 printf("<option value=-4>-4\n"); 00593 printf("</select>\n"); 00594 printf("</td></tr>\n"); 00595 00596 printf("<tr><td CLASS='optBoxItem' valign=top align=left>\n"); 00597 printf("</td><td CLASS='optBoxItem' valign=top align=left>\n"); 00598 printf("<input type='submit' value='Update'>\n"); 00599 printf("</td></tr>\n"); 00600 } 00601 00602 /* display context-sensitive help */ 00603 printf("<tr><td></td><td align=right valign=bottom>\n"); 00604 if(display_type!=DISPLAY_NO_TRENDS && input_type==GET_INPUT_NONE){ 00605 if(display_type==DISPLAY_HOST_TRENDS) 00606 display_context_help(CONTEXTHELP_TRENDS_HOST); 00607 else 00608 display_context_help(CONTEXTHELP_TRENDS_SERVICE); 00609 } 00610 else if(display_type==DISPLAY_NO_TRENDS || input_type!=GET_INPUT_NONE){ 00611 if(input_type==GET_INPUT_NONE) 00612 display_context_help(CONTEXTHELP_TRENDS_MENU1); 00613 else if(input_type==GET_INPUT_TARGET_TYPE) 00614 display_context_help(CONTEXTHELP_TRENDS_MENU1); 00615 else if(input_type==GET_INPUT_HOST_TARGET) 00616 display_context_help(CONTEXTHELP_TRENDS_MENU2); 00617 else if(input_type==GET_INPUT_SERVICE_TARGET) 00618 display_context_help(CONTEXTHELP_TRENDS_MENU3); 00619 else if(input_type==GET_INPUT_OPTIONS) 00620 display_context_help(CONTEXTHELP_TRENDS_MENU4); 00621 } 00622 printf("</td></tr>\n"); 00623 00624 printf("</table>\n"); 00625 printf("</form>\n"); 00626 00627 printf("</td>\n"); 00628 00629 /* end of top table */ 00630 printf("</tr>\n"); 00631 printf("</table>\n"); 00632 } 00633 00634 00635 #ifndef DEBUG 00636 00637 /* check authorization... */ 00638 if(display_type==DISPLAY_HOST_TRENDS){ 00639 temp_host=find_host(host_name); 00640 if(temp_host==NULL || is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 00641 is_authorized=FALSE; 00642 } 00643 else if(display_type==DISPLAY_SERVICE_TRENDS){ 00644 temp_service=find_service(host_name,service_desc); 00645 if(temp_service==NULL || is_authorized_for_service(temp_service,¤t_authdata)==FALSE) 00646 is_authorized=FALSE; 00647 } 00648 if(is_authorized==FALSE){ 00649 00650 if(content_type==HTML_CONTENT) { 00651 if (display_type==DISPLAY_HOST_TRENDS) 00652 print_generic_error_message("It appears as though you are not authorized to view information for the specified host...",NULL,0); 00653 else 00654 print_generic_error_message("It appears as though you are not authorized to view information for the specified service...",NULL,0); 00655 } 00656 00657 document_footer(CGI_ID); 00658 free_memory(); 00659 return ERROR; 00660 } 00661 #endif 00662 00663 if(timeperiod_type==TIMEPERIOD_NEXTPROBLEM && problem_found==FALSE) { 00664 print_generic_error_message("No problem found between end of display and end of recording.",NULL,0); 00665 00666 document_footer(CGI_ID); 00667 free_memory(); 00668 return ERROR; 00669 } 00670 00671 /* set drawing parameters, etc */ 00672 00673 if(small_image==TRUE){ 00674 image_height=20; 00675 image_width=500; 00676 } 00677 else{ 00678 image_height=300; 00679 image_width=900; 00680 } 00681 00682 if(display_type==DISPLAY_HOST_TRENDS){ 00683 00684 if(small_image==TRUE){ 00685 drawing_width=SMALL_HOST_DRAWING_WIDTH; 00686 drawing_height=SMALL_HOST_DRAWING_HEIGHT; 00687 drawing_x_offset=SMALL_HOST_DRAWING_X_OFFSET; 00688 drawing_y_offset=SMALL_HOST_DRAWING_Y_OFFSET; 00689 } 00690 else{ 00691 drawing_width=HOST_DRAWING_WIDTH; 00692 drawing_height=HOST_DRAWING_HEIGHT; 00693 drawing_x_offset=HOST_DRAWING_X_OFFSET; 00694 drawing_y_offset=HOST_DRAWING_Y_OFFSET; 00695 } 00696 } 00697 else if(display_type==DISPLAY_SERVICE_TRENDS){ 00698 00699 if(small_image==TRUE){ 00700 drawing_width=SMALL_SVC_DRAWING_WIDTH; 00701 drawing_height=SMALL_SVC_DRAWING_HEIGHT; 00702 drawing_x_offset=SMALL_SVC_DRAWING_X_OFFSET; 00703 drawing_y_offset=SMALL_SVC_DRAWING_Y_OFFSET; 00704 } 00705 else{ 00706 drawing_width=SVC_DRAWING_WIDTH; 00707 drawing_height=SVC_DRAWING_HEIGHT; 00708 drawing_x_offset=SVC_DRAWING_X_OFFSET; 00709 drawing_y_offset=SVC_DRAWING_Y_OFFSET; 00710 } 00711 } 00712 00713 /* last known state should always be initially set to indeterminate! */ 00714 last_known_state=AS_NO_DATA; 00715 00716 00717 /* initialize PNG image */ 00718 if(display_type!=DISPLAY_NO_TRENDS && content_type==IMAGE_CONTENT){ 00719 00720 if(small_image==TRUE){ 00721 trends_image=gdImageCreate(image_width,image_height); 00722 if(trends_image==NULL){ 00723 #ifdef DEBUG 00724 printf("Error: Could not allocate memory for image\n"); 00725 #endif 00726 return ERROR; 00727 } 00728 } 00729 00730 else{ 00731 00732 if(display_type==DISPLAY_HOST_TRENDS) 00733 snprintf(image_template,sizeof(image_template)-1,"%s/trendshost.png",physical_images_path); 00734 else 00735 snprintf(image_template,sizeof(image_template)-1,"%s/trendssvc.png",physical_images_path); 00736 image_template[sizeof(image_template)-1]='\x0'; 00737 00738 /* allocate buffer for storing image */ 00739 trends_image=NULL; 00740 image_file=fopen(image_template,"r"); 00741 if(image_file!=NULL){ 00742 trends_image=gdImageCreateFromPng(image_file); 00743 fclose(image_file); 00744 } 00745 if(trends_image==NULL) 00746 trends_image=gdImageCreate(image_width,image_height); 00747 if(trends_image==NULL){ 00748 #ifdef DEBUG 00749 printf("Error: Could not allocate memory for image\n"); 00750 #endif 00751 return ERROR; 00752 } 00753 } 00754 00755 /* allocate colors used for drawing */ 00756 color_white=gdImageColorAllocate(trends_image,255,255,255); 00757 color_black=gdImageColorAllocate(trends_image,0,0,0); 00758 color_red=gdImageColorAllocate(trends_image,255,0,0); 00759 color_darkred=gdImageColorAllocate(trends_image,128,0,0); 00760 color_green=gdImageColorAllocate(trends_image,0,210,0); 00761 color_darkgreen=gdImageColorAllocate(trends_image,0,128,0); 00762 color_yellow=gdImageColorAllocate(trends_image,176,178,20); 00763 color_orange=gdImageColorAllocate(trends_image,255,100,25); 00764 00765 /* set transparency index */ 00766 gdImageColorTransparent(trends_image,color_white); 00767 00768 /* make sure the graphic is interlaced */ 00769 gdImageInterlace(trends_image,1); 00770 00771 if(small_image==FALSE){ 00772 00773 /* find the host */ 00774 temp_host=find_host(host_name); 00775 00776 /* find the service */ 00777 temp_service=find_service(host_name,service_desc); 00778 00779 /* title */ 00780 snprintf(start_time,sizeof(start_time)-1,"%s",ctime(&t1)); 00781 start_time[sizeof(start_time)-1]='\x0'; 00782 start_time[strlen(start_time)-1]='\x0'; 00783 snprintf(end_time,sizeof(end_time)-1,"%s",ctime(&t2)); 00784 end_time[sizeof(end_time)-1]='\x0'; 00785 end_time[strlen(end_time)-1]='\x0'; 00786 00787 string_height=gdFontSmall->h; 00788 00789 if(display_type==DISPLAY_HOST_TRENDS) 00790 snprintf(temp_buffer,sizeof(temp_buffer)-1,"State History For Host '%s'",(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 00791 else 00792 snprintf(temp_buffer,sizeof(temp_buffer)-1,"State History For Service '%s' On Host '%s'",(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 00793 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00794 string_width=gdFontSmall->w*strlen(temp_buffer); 00795 gdImageString(trends_image,gdFontSmall,(drawing_width/2)-(string_width/2)+drawing_x_offset,string_height,(unsigned char *)temp_buffer,color_black); 00796 00797 snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s to %s",start_time,end_time); 00798 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00799 string_width=gdFontSmall->w*strlen(temp_buffer); 00800 gdImageString(trends_image,gdFontSmall,(drawing_width/2)-(string_width/2)+drawing_x_offset,(string_height*2)+5,(unsigned char *)temp_buffer,color_black); 00801 00802 00803 /* first time stamp */ 00804 snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s",start_time); 00805 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00806 string_width=gdFontSmall->w*strlen(temp_buffer); 00807 gdImageStringUp(trends_image,gdFontSmall,drawing_x_offset-(string_height/2),drawing_y_offset+drawing_height+string_width+5,(unsigned char *)temp_buffer,color_black); 00808 } 00809 } 00810 00811 if(display_type!=DISPLAY_NO_TRENDS && input_type==GET_INPUT_NONE){ 00812 00813 00814 if(content_type==IMAGE_CONTENT || (content_type==HTML_CONTENT && use_map==TRUE)){ 00815 00816 /* read in all necessary archived state data */ 00817 read_archived_state_data(); 00818 00819 /* graph archived state trend data */ 00820 graph_all_trend_data(); 00821 } 00822 00823 /* print URL to image */ 00824 if(content_type==HTML_CONTENT){ 00825 00826 printf("<BR><BR>\n"); 00827 printf("<DIV ALIGN=CENTER>\n"); 00828 printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu",TRENDS_CGI,(unsigned long)t1,(unsigned long)t2); 00829 printf("&assumeinitialstates=%s",(assume_initial_states==TRUE)?"yes":"no"); 00830 printf("&assumestatesduringnotrunning=%s",(assume_states_during_notrunning==TRUE)?"yes":"no"); 00831 printf("&initialassumedhoststate=%d",initial_assumed_host_state); 00832 printf("&initialassumedservicestate=%d",initial_assumed_service_state); 00833 printf("&assumestateretention=%s",(assume_state_retention==TRUE)?"yes":"no"); 00834 printf("&includesoftstates=%s",(include_soft_states==TRUE)?"yes":"no"); 00835 printf("&host=%s",url_encode(host_name)); 00836 if(display_type==DISPLAY_SERVICE_TRENDS) 00837 printf("&service=%s",url_encode(service_desc)); 00838 if(backtrack_archives>0) 00839 printf("&backtrack=%d",backtrack_archives); 00840 printf("&zoom=%d",zoom_factor); 00841 printf("' BORDER=0 name='trendsimage' useMap='#trendsmap' width=%d>\n", image_width); 00842 printf("</DIV>\n"); 00843 } 00844 00845 if(content_type==IMAGE_CONTENT || (content_type==HTML_CONTENT && use_map==TRUE)){ 00846 00847 /* draw timestamps */ 00848 draw_timestamps(); 00849 00850 /* draw horizontal lines */ 00851 draw_horizontal_grid_lines(); 00852 00853 /* draw state time breakdowns */ 00854 draw_time_breakdowns(); 00855 } 00856 00857 if(content_type==IMAGE_CONTENT){ 00858 00859 /* use STDOUT for writing the image data... */ 00860 image_file=stdout; 00861 00862 #ifndef DEBUG 00863 /* write the image to file */ 00864 gdImagePng(trends_image,image_file); 00865 #endif 00866 #ifdef DEBUG 00867 image_file=fopen("trends.png","w"); 00868 if(image_file==NULL) 00869 printf("Could not open trends.png for writing!\n"); 00870 else{ 00871 gdImagePng(trends_image,image_file); 00872 fclose(image_file); 00873 } 00874 #endif 00875 00876 /* free memory allocated to image */ 00877 gdImageDestroy(trends_image); 00878 } 00879 } 00880 00881 00882 /* show user a selection of hosts and services to choose from... */ 00883 if(display_type==DISPLAY_NO_TRENDS || input_type!=GET_INPUT_NONE){ 00884 00885 /* ask the user for what host they want a report for */ 00886 if(input_type==GET_INPUT_HOST_TARGET){ 00887 00888 printf("<P><DIV ALIGN=CENTER>\n"); 00889 printf("<DIV CLASS='reportSelectTitle'>Step 2: Select Host</DIV>\n"); 00890 printf("</DIV></P>\n"); 00891 00892 printf("<P><DIV ALIGN=CENTER>\n"); 00893 00894 printf("<form method=\"GET\" action=\"%s\">\n",TRENDS_CGI); 00895 printf("<input type='hidden' name='input' value='getoptions'>\n"); 00896 00897 printf("<TABLE BORDER=0 cellspacing=0 cellpadding=10>\n"); 00898 printf("<tr><td class='reportSelectSubTitle' valign=center>Host:</td>\n"); 00899 printf("<td class='reportSelectItem' valign=center>\n"); 00900 printf("<select name='host'>\n"); 00901 00902 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ 00903 if(is_authorized_for_host(temp_host,¤t_authdata)==TRUE) 00904 printf("<option value='%s'>%s\n",escape_string(temp_host->name),(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 00905 } 00906 00907 printf("</select>\n"); 00908 printf("</td></tr>\n"); 00909 00910 printf("<tr><td></td><td class='reportSelectItem'>\n"); 00911 printf("<input type='submit' value='Continue to Step 3'>\n"); 00912 printf("</td></tr>\n"); 00913 00914 printf("</TABLE>\n"); 00915 printf("</form>\n"); 00916 00917 printf("</DIV></P>\n"); 00918 } 00919 00920 /* ask the user for what service they want a report for */ 00921 else if(input_type==GET_INPUT_SERVICE_TARGET){ 00922 00923 printf("<SCRIPT LANGUAGE='JavaScript'>\n"); 00924 printf("function gethostname(hostindex){\n"); 00925 printf("hostnames=["); 00926 00927 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ 00928 if(is_authorized_for_service(temp_service,¤t_authdata)==TRUE){ 00929 if(found==TRUE) 00930 printf(","); 00931 else 00932 first_service=temp_service->host_name; 00933 printf(" \"%s\"",temp_service->host_name); 00934 found=TRUE; 00935 } 00936 } 00937 00938 printf(" ]\n"); 00939 printf("return hostnames[hostindex];\n"); 00940 printf("}\n"); 00941 printf("</SCRIPT>\n"); 00942 00943 00944 printf("<P><DIV ALIGN=CENTER>\n"); 00945 printf("<DIV CLASS='reportSelectTitle'>Step 2: Select Service</DIV>\n"); 00946 printf("</DIV></P>\n"); 00947 00948 printf("<P><DIV ALIGN=CENTER>\n"); 00949 00950 printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n",TRENDS_CGI); 00951 printf("<input type='hidden' name='input' value='getoptions'>\n"); 00952 printf("<input type='hidden' name='host' value='%s'>\n",(first_service==NULL)?"unknown":(char *)escape_string(first_service)); 00953 00954 printf("<TABLE BORDER=0 cellpadding=5>\n"); 00955 printf("<tr><td class='reportSelectSubTitle'>Service:</td>\n"); 00956 printf("<td class='reportSelectItem'>\n"); 00957 printf("<select name='service' onFocus='document.serviceform.host.value=gethostname(this.selectedIndex);' onChange='document.serviceform.host.value=gethostname(this.selectedIndex);'>\n"); 00958 00959 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ 00960 if(is_authorized_for_service(temp_service,¤t_authdata)==TRUE) 00961 temp_host=find_host(temp_service->host_name); 00962 printf("<option value='%s'>%s;%s\n",escape_string(temp_service->description),(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name,(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description); 00963 } 00964 00965 printf("</select>\n"); 00966 printf("</td></tr>\n"); 00967 00968 printf("<tr><td></td><td class='reportSelectItem'>\n"); 00969 printf("<input type='submit' value='Continue to Step 3'>\n"); 00970 printf("</td></tr>\n"); 00971 00972 printf("</TABLE>\n"); 00973 printf("</form>\n"); 00974 00975 printf("</DIV></P>\n"); 00976 } 00977 00978 /* ask the user for report range and options */ 00979 else if(input_type==GET_INPUT_OPTIONS){ 00980 00981 time(¤t_time); 00982 t=localtime(¤t_time); 00983 00984 start_day=1; 00985 start_year=t->tm_year+1900; 00986 end_day=t->tm_mday; 00987 end_year=t->tm_year+1900; 00988 00989 printf("<P><DIV ALIGN=CENTER>\n"); 00990 printf("<DIV CLASS='reportSelectTitle'>Step 3: Select Report Options</DIV>\n"); 00991 printf("</DIV></P>\n"); 00992 00993 printf("<P><DIV ALIGN=CENTER>\n"); 00994 00995 printf("<form method=\"GET\" action=\"%s\">\n",TRENDS_CGI); 00996 printf("<input type='hidden' name='host' value='%s'>\n",escape_string(host_name)); 00997 if(display_type==DISPLAY_SERVICE_TRENDS) 00998 printf("<input type='hidden' name='service' value='%s'>\n",escape_string(service_desc)); 00999 01000 printf("<TABLE BORDER=0 CELLPADDING=5>\n"); 01001 printf("<tr><td class='reportSelectSubTitle' align=right>Report period:</td>\n"); 01002 printf("<td class='reportSelectItem'>\n"); 01003 printf("<select name='timeperiod'>\n"); 01004 printf("<option value=today>Today\n"); 01005 printf("<option value=last24hours>Last 24 Hours\n"); 01006 printf("<option value=yesterday>Yesterday\n"); 01007 printf("<option value=thisweek>This Week\n"); 01008 printf("<option value=last7days SELECTED>Last 7 Days\n"); 01009 printf("<option value=lastweek>Last Week\n"); 01010 printf("<option value=thismonth>This Month\n"); 01011 printf("<option value=last31days>Last 31 Days\n"); 01012 printf("<option value=lastmonth>Last Month\n"); 01013 printf("<option value=thisyear>This Year\n"); 01014 printf("<option value=lastyear>Last Year\n"); 01015 printf("<option value=custom>* CUSTOM REPORT PERIOD *\n"); 01016 printf("</select>\n"); 01017 printf("</td></tr>\n"); 01018 01019 printf("<tr><td valign=top class='reportSelectSubTitle'>If Custom Report Period...</td></tr>\n"); 01020 01021 printf("<tr>"); 01022 printf("<td valign=top class='reportSelectSubTitle'>Start Date (Inclusive):</td>\n"); 01023 printf("<td align=left valign=top class='reportSelectItem'>"); 01024 printf("<select name='smon'>\n"); 01025 printf("<option value='1' %s>January\n",(t->tm_mon==0)?"SELECTED":""); 01026 printf("<option value='2' %s>February\n",(t->tm_mon==1)?"SELECTED":""); 01027 printf("<option value='3' %s>March\n",(t->tm_mon==2)?"SELECTED":""); 01028 printf("<option value='4' %s>April\n",(t->tm_mon==3)?"SELECTED":""); 01029 printf("<option value='5' %s>May\n",(t->tm_mon==4)?"SELECTED":""); 01030 printf("<option value='6' %s>June\n",(t->tm_mon==5)?"SELECTED":""); 01031 printf("<option value='7' %s>July\n",(t->tm_mon==6)?"SELECTED":""); 01032 printf("<option value='8' %s>August\n",(t->tm_mon==7)?"SELECTED":""); 01033 printf("<option value='9' %s>September\n",(t->tm_mon==8)?"SELECTED":""); 01034 printf("<option value='10' %s>October\n",(t->tm_mon==9)?"SELECTED":""); 01035 printf("<option value='11' %s>November\n",(t->tm_mon==10)?"SELECTED":""); 01036 printf("<option value='12' %s>December\n",(t->tm_mon==11)?"SELECTED":""); 01037 printf("</select>\n "); 01038 printf("<input type='text' size='2' maxlength='2' name='sday' value='%d'> ",start_day); 01039 printf("<input type='text' size='4' maxlength='4' name='syear' value='%d'>",start_year); 01040 printf("<input type='hidden' name='shour' value='0'>\n"); 01041 printf("<input type='hidden' name='smin' value='0'>\n"); 01042 printf("<input type='hidden' name='ssec' value='0'>\n"); 01043 printf("</td>\n"); 01044 printf("</tr>\n"); 01045 01046 printf("<tr>"); 01047 printf("<td valign=top class='reportSelectSubTitle'>End Date (Inclusive):</td>\n"); 01048 printf("<td align=left valign=top class='reportSelectItem'>"); 01049 printf("<select name='emon'>\n"); 01050 printf("<option value='1' %s>January\n",(t->tm_mon==0)?"SELECTED":""); 01051 printf("<option value='2' %s>February\n",(t->tm_mon==1)?"SELECTED":""); 01052 printf("<option value='3' %s>March\n",(t->tm_mon==2)?"SELECTED":""); 01053 printf("<option value='4' %s>April\n",(t->tm_mon==3)?"SELECTED":""); 01054 printf("<option value='5' %s>May\n",(t->tm_mon==4)?"SELECTED":""); 01055 printf("<option value='6' %s>June\n",(t->tm_mon==5)?"SELECTED":""); 01056 printf("<option value='7' %s>July\n",(t->tm_mon==6)?"SELECTED":""); 01057 printf("<option value='8' %s>August\n",(t->tm_mon==7)?"SELECTED":""); 01058 printf("<option value='9' %s>September\n",(t->tm_mon==8)?"SELECTED":""); 01059 printf("<option value='10' %s>October\n",(t->tm_mon==9)?"SELECTED":""); 01060 printf("<option value='11' %s>November\n",(t->tm_mon==10)?"SELECTED":""); 01061 printf("<option value='12' %s>December\n",(t->tm_mon==11)?"SELECTED":""); 01062 printf("</select>\n "); 01063 printf("<input type='text' size='2' maxlength='2' name='eday' value='%d'> ",end_day); 01064 printf("<input type='text' size='4' maxlength='4' name='eyear' value='%d'>",end_year); 01065 printf("<input type='hidden' name='ehour' value='24'>\n"); 01066 printf("<input type='hidden' name='emin' value='0'>\n"); 01067 printf("<input type='hidden' name='esec' value='0'>\n"); 01068 printf("</td>\n"); 01069 printf("</tr>\n"); 01070 01071 printf("<tr><td colspan=2><br></td></tr>\n"); 01072 01073 printf("<tr><td class='reportSelectSubTitle' align=right>Assume Initial States:</td>\n"); 01074 printf("<td class='reportSelectItem'>\n"); 01075 printf("<select name='assumeinitialstates'>\n"); 01076 printf("<option value=yes>Yes\n"); 01077 printf("<option value=no>No\n"); 01078 printf("</select>\n"); 01079 printf("</td></tr>\n"); 01080 01081 printf("<tr><td class='reportSelectSubTitle' align=right>Assume State Retention:</td>\n"); 01082 printf("<td class='reportSelectItem'>\n"); 01083 printf("<select name='assumestateretention'>\n"); 01084 printf("<option value=yes>Yes\n"); 01085 printf("<option value=no>No\n"); 01086 printf("</select>\n"); 01087 printf("</td></tr>\n"); 01088 01089 printf("<tr><td class='reportSelectSubTitle' align=right>Assume States During Program Downtime:</td>\n"); 01090 printf("<td class='reportSelectItem'>\n"); 01091 printf("<select name='assumestatesduringnotrunning'>\n"); 01092 printf("<option value=yes>Yes\n"); 01093 printf("<option value=no>No\n"); 01094 printf("</select>\n"); 01095 printf("</td></tr>\n"); 01096 01097 printf("<tr><td class='reportSelectSubTitle' align=right>Include Soft States:</td>\n"); 01098 printf("<td class='reportSelectItem'>\n"); 01099 printf("<select name='includesoftstates'>\n"); 01100 printf("<option value=yes>Yes\n"); 01101 printf("<option value=no SELECTED>No\n"); 01102 printf("</select>\n"); 01103 printf("</td></tr>\n"); 01104 01105 printf("<tr><td class='reportSelectSubTitle' align=right>First Assumed %s State:</td>\n",(display_type==DISPLAY_HOST_TRENDS)?"Host":"Service"); 01106 printf("<td class='reportSelectItem'>\n"); 01107 if(display_type==DISPLAY_HOST_TRENDS){ 01108 printf("<select name='initialassumedhoststate'>\n"); 01109 printf("<option value=%d>Unspecified\n",AS_NO_DATA); 01110 printf("<option value=%d>Current State\n",AS_CURRENT_STATE); 01111 printf("<option value=%d>Host Up\n",AS_HOST_UP); 01112 printf("<option value=%d>Host Down\n",AS_HOST_DOWN); 01113 printf("<option value=%d>Host Unreachable\n",AS_HOST_UNREACHABLE); 01114 } 01115 else{ 01116 printf("<select name='initialassumedservicestate'>\n"); 01117 printf("<option value=%d>Unspecified\n",AS_NO_DATA); 01118 printf("<option value=%d>Current State\n",AS_CURRENT_STATE); 01119 printf("<option value=%d>Service Ok\n",AS_SVC_OK); 01120 printf("<option value=%d>Service Warning\n",AS_SVC_WARNING); 01121 printf("<option value=%d>Service Unknown\n",AS_SVC_UNKNOWN); 01122 printf("<option value=%d>Service Critical\n",AS_SVC_CRITICAL); 01123 } 01124 printf("</select>\n"); 01125 printf("</td></tr>\n"); 01126 01127 printf("<tr><td class='reportSelectSubTitle' align=right>Backtracked Archives (To Scan For Initial States):</td>\n"); 01128 printf("<td class='reportSelectItem'>\n"); 01129 printf("<input type='text' name='backtrack' size='2' maxlength='2' value='%d'>\n",backtrack_archives); 01130 printf("</td></tr>\n"); 01131 01132 printf("<tr><td class='reportSelectSubTitle' align=right>Suppress image map:</td><td class='reportSelectItem'><input type='checkbox' name='nomap'></td></tr>"); 01133 printf("<tr><td class='reportSelectSubTitle' align=right>Suppress popups:</td><td class='reportSelectItem'><input type='checkbox' name='nopopups'></td></tr>\n"); 01134 01135 printf("<tr><td class='reportSelectSubTitle' align=right>Ignore daemon starts/restarts:</td><td class='reportSelectItem'><input type='checkbox' name='ignorerestart'></td></tr>\n"); 01136 01137 printf("<tr><td></td><td class='reportSelectItem'><input type='submit' value='Create Report'></td></tr>\n"); 01138 01139 printf("</TABLE>\n"); 01140 printf("</form>\n"); 01141 01142 printf("</DIV></P>\n"); 01143 01144 /* 01145 printf("<P><DIV ALIGN=CENTER CLASS='helpfulHint'>\n"); 01146 printf("Note: Choosing the 'suppress image map' option will make the report run approximately twice as fast as it would otherwise, but it will prevent you from being able to zoom in on specific time periods.\n"); 01147 printf("</DIV></P>\n"); 01148 */ 01149 } 01150 01151 /* as the user whether they want a graph for a host or service */ 01152 else{ 01153 printf("<P><DIV ALIGN=CENTER>\n"); 01154 printf("<DIV CLASS='reportSelectTitle'>Step 1: Select Report Type</DIV>\n"); 01155 printf("</DIV></P>\n"); 01156 01157 printf("<P><DIV ALIGN=CENTER>\n"); 01158 01159 printf("<form method=\"GET\" action=\"%s\">\n",TRENDS_CGI); 01160 printf("<TABLE BORDER=0 cellpadding=5>\n"); 01161 01162 printf("<tr><td class='reportSelectSubTitle' align=right>Type:</td>\n"); 01163 printf("<td class='reportSelectItem'>\n"); 01164 printf("<select name='input'>\n"); 01165 printf("<option value=gethost>Host\n"); 01166 printf("<option value=getservice>Service\n"); 01167 printf("</select>\n"); 01168 printf("</td></tr>\n"); 01169 01170 printf("<tr><td></td><td class='reportSelectItem'>\n"); 01171 printf("<input type='submit' value='Continue to Step 2'>\n"); 01172 printf("</td></tr>\n"); 01173 01174 printf("</TABLE>\n"); 01175 printf("</form>\n"); 01176 01177 printf("</DIV></P>\n"); 01178 } 01179 01180 } 01181 01182 document_footer(CGI_ID); 01183 01184 /* free memory allocated to the archived state data list */ 01185 free_archived_state_list(); 01186 01187 /* free all other allocated memory */ 01188 free_memory(); 01189 01190 return OK; 01191 } 01192 01193 int process_cgivars(void){ 01194 char **variables; 01195 int error=FALSE; 01196 int x; 01197 01198 variables=getcgivars(); 01199 01200 for(x=0;variables[x]!=NULL;x++){ 01201 01202 /* do some basic length checking on the variable identifier to prevent buffer overflows */ 01203 if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){ 01204 x++; 01205 continue; 01206 } 01207 01208 /* we found the host argument */ 01209 else if(!strcmp(variables[x],"host")){ 01210 x++; 01211 if(variables[x]==NULL){ 01212 error=TRUE; 01213 break; 01214 } 01215 01216 if((host_name=(char *)strdup(variables[x]))==NULL) 01217 host_name=""; 01218 strip_html_brackets(host_name); 01219 01220 display_type=DISPLAY_HOST_TRENDS; 01221 } 01222 01223 /* we found the node width argument */ 01224 else if(!strcmp(variables[x],"service")){ 01225 x++; 01226 if(variables[x]==NULL){ 01227 error=TRUE; 01228 break; 01229 } 01230 01231 if((service_desc=(char *)strdup(variables[x]))==NULL) 01232 service_desc=""; 01233 strip_html_brackets(service_desc); 01234 01235 display_type=DISPLAY_SERVICE_TRENDS; 01236 } 01237 01238 /* we found first time argument */ 01239 else if(!strcmp(variables[x],"t1")){ 01240 x++; 01241 if(variables[x]==NULL){ 01242 error=TRUE; 01243 break; 01244 } 01245 01246 t1=(time_t)strtoul(variables[x],NULL,10); 01247 timeperiod_type=TIMEPERIOD_CUSTOM; 01248 } 01249 01250 /* we found first time argument */ 01251 else if(!strcmp(variables[x],"t2")){ 01252 x++; 01253 if(variables[x]==NULL){ 01254 error=TRUE; 01255 break; 01256 } 01257 01258 t2=(time_t)strtoul(variables[x],NULL,10); 01259 timeperiod_type=TIMEPERIOD_CUSTOM; 01260 } 01261 01262 /* we found the image creation option */ 01263 else if(!strcmp(variables[x],"createimage")){ 01264 content_type=IMAGE_CONTENT; 01265 } 01266 01267 /* we found the assume initial states option */ 01268 else if(!strcmp(variables[x],"assumeinitialstates")){ 01269 x++; 01270 if(variables[x]==NULL){ 01271 error=TRUE; 01272 break; 01273 } 01274 01275 if(!strcmp(variables[x],"yes")) 01276 assume_initial_states=TRUE; 01277 else 01278 assume_initial_states=FALSE; 01279 } 01280 01281 /* we found the initial assumed host state option */ 01282 else if(!strcmp(variables[x],"initialassumedhoststate")){ 01283 x++; 01284 if(variables[x]==NULL){ 01285 error=TRUE; 01286 break; 01287 } 01288 01289 initial_assumed_host_state=atoi(variables[x]); 01290 } 01291 01292 /* we found the initial assumed service state option */ 01293 else if(!strcmp(variables[x],"initialassumedservicestate")){ 01294 x++; 01295 if(variables[x]==NULL){ 01296 error=TRUE; 01297 break; 01298 } 01299 01300 initial_assumed_service_state=atoi(variables[x]); 01301 } 01302 01303 /* we found the assume state during program not running option */ 01304 else if(!strcmp(variables[x],"assumestatesduringnotrunning")){ 01305 x++; 01306 if(variables[x]==NULL){ 01307 error=TRUE; 01308 break; 01309 } 01310 01311 if(!strcmp(variables[x],"yes")) 01312 assume_states_during_notrunning=TRUE; 01313 else 01314 assume_states_during_notrunning=FALSE; 01315 } 01316 01317 /* we found the assume state retention option */ 01318 else if(!strcmp(variables[x],"assumestateretention")){ 01319 x++; 01320 if(variables[x]==NULL){ 01321 error=TRUE; 01322 break; 01323 } 01324 01325 if(!strcmp(variables[x],"yes")) 01326 assume_state_retention=TRUE; 01327 else 01328 assume_state_retention=FALSE; 01329 } 01330 01331 /* we found the include soft states option */ 01332 else if(!strcmp(variables[x],"includesoftstates")){ 01333 x++; 01334 if(variables[x]==NULL){ 01335 error=TRUE; 01336 break; 01337 } 01338 01339 if(!strcmp(variables[x],"yes")) 01340 include_soft_states=TRUE; 01341 else 01342 include_soft_states=FALSE; 01343 } 01344 01345 /* we found the zoom factor argument */ 01346 else if(!strcmp(variables[x],"zoom")){ 01347 x++; 01348 if(variables[x]==NULL){ 01349 error=TRUE; 01350 break; 01351 } 01352 01353 zoom_factor=atoi(variables[x]); 01354 if(zoom_factor==0) 01355 zoom_factor=1; 01356 } 01357 01358 /* we found the backtrack archives argument */ 01359 else if(!strcmp(variables[x],"backtrack")){ 01360 x++; 01361 if(variables[x]==NULL){ 01362 error=TRUE; 01363 break; 01364 } 01365 01366 backtrack_archives=atoi(variables[x]); 01367 if(backtrack_archives<0) 01368 backtrack_archives=0; 01369 if(backtrack_archives>MAX_ARCHIVE_BACKTRACKS) 01370 backtrack_archives=MAX_ARCHIVE_BACKTRACKS; 01371 } 01372 01373 /* we found the standard timeperiod argument */ 01374 else if(!strcmp(variables[x],"timeperiod")){ 01375 x++; 01376 if(variables[x]==NULL){ 01377 error=TRUE; 01378 break; 01379 } 01380 01381 if(!strcmp(variables[x],"today")) 01382 timeperiod_type=TIMEPERIOD_TODAY; 01383 else if(!strcmp(variables[x],"yesterday")) 01384 timeperiod_type=TIMEPERIOD_YESTERDAY; 01385 else if(!strcmp(variables[x],"thisweek")) 01386 timeperiod_type=TIMEPERIOD_THISWEEK; 01387 else if(!strcmp(variables[x],"lastweek")) 01388 timeperiod_type=TIMEPERIOD_LASTWEEK; 01389 else if(!strcmp(variables[x],"thismonth")) 01390 timeperiod_type=TIMEPERIOD_THISMONTH; 01391 else if(!strcmp(variables[x],"lastmonth")) 01392 timeperiod_type=TIMEPERIOD_LASTMONTH; 01393 else if(!strcmp(variables[x],"thisquarter")) 01394 timeperiod_type=TIMEPERIOD_THISQUARTER; 01395 else if(!strcmp(variables[x],"lastquarter")) 01396 timeperiod_type=TIMEPERIOD_LASTQUARTER; 01397 else if(!strcmp(variables[x],"thisyear")) 01398 timeperiod_type=TIMEPERIOD_THISYEAR; 01399 else if(!strcmp(variables[x],"lastyear")) 01400 timeperiod_type=TIMEPERIOD_LASTYEAR; 01401 else if(!strcmp(variables[x],"nextproblem")) 01402 timeperiod_type=TIMEPERIOD_NEXTPROBLEM; 01403 else if(!strcmp(variables[x],"last24hours")) 01404 timeperiod_type=TIMEPERIOD_LAST24HOURS; 01405 else if(!strcmp(variables[x],"last7days")) 01406 timeperiod_type=TIMEPERIOD_LAST7DAYS; 01407 else if(!strcmp(variables[x],"last31days")) 01408 timeperiod_type=TIMEPERIOD_LAST31DAYS; 01409 else if(!strcmp(variables[x],"custom")) 01410 timeperiod_type=TIMEPERIOD_CUSTOM; 01411 else 01412 continue; 01413 01414 convert_timeperiod_to_times(timeperiod_type,&t1,&t2); 01415 } 01416 01417 /* we found time argument */ 01418 else if(!strcmp(variables[x],"smon")){ 01419 x++; 01420 if(variables[x]==NULL){ 01421 error=TRUE; 01422 break; 01423 } 01424 01425 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01426 continue; 01427 01428 start_month=atoi(variables[x]); 01429 timeperiod_type=TIMEPERIOD_CUSTOM; 01430 compute_time_from_parts=TRUE; 01431 } 01432 01433 /* we found time argument */ 01434 else if(!strcmp(variables[x],"sday")){ 01435 x++; 01436 if(variables[x]==NULL){ 01437 error=TRUE; 01438 break; 01439 } 01440 01441 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01442 continue; 01443 01444 start_day=atoi(variables[x]); 01445 timeperiod_type=TIMEPERIOD_CUSTOM; 01446 compute_time_from_parts=TRUE; 01447 } 01448 01449 /* we found time argument */ 01450 else if(!strcmp(variables[x],"syear")){ 01451 x++; 01452 if(variables[x]==NULL){ 01453 error=TRUE; 01454 break; 01455 } 01456 01457 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01458 continue; 01459 01460 start_year=atoi(variables[x]); 01461 timeperiod_type=TIMEPERIOD_CUSTOM; 01462 compute_time_from_parts=TRUE; 01463 } 01464 01465 /* we found time argument */ 01466 else if(!strcmp(variables[x],"smin")){ 01467 x++; 01468 if(variables[x]==NULL){ 01469 error=TRUE; 01470 break; 01471 } 01472 01473 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01474 continue; 01475 01476 start_minute=atoi(variables[x]); 01477 timeperiod_type=TIMEPERIOD_CUSTOM; 01478 compute_time_from_parts=TRUE; 01479 } 01480 01481 /* we found time argument */ 01482 else if(!strcmp(variables[x],"ssec")){ 01483 x++; 01484 if(variables[x]==NULL){ 01485 error=TRUE; 01486 break; 01487 } 01488 01489 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01490 continue; 01491 01492 start_second=atoi(variables[x]); 01493 timeperiod_type=TIMEPERIOD_CUSTOM; 01494 compute_time_from_parts=TRUE; 01495 } 01496 01497 /* we found time argument */ 01498 else if(!strcmp(variables[x],"shour")){ 01499 x++; 01500 if(variables[x]==NULL){ 01501 error=TRUE; 01502 break; 01503 } 01504 01505 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01506 continue; 01507 01508 start_hour=atoi(variables[x]); 01509 timeperiod_type=TIMEPERIOD_CUSTOM; 01510 compute_time_from_parts=TRUE; 01511 } 01512 01513 01514 /* we found time argument */ 01515 else if(!strcmp(variables[x],"emon")){ 01516 x++; 01517 if(variables[x]==NULL){ 01518 error=TRUE; 01519 break; 01520 } 01521 01522 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01523 continue; 01524 01525 end_month=atoi(variables[x]); 01526 timeperiod_type=TIMEPERIOD_CUSTOM; 01527 compute_time_from_parts=TRUE; 01528 } 01529 01530 /* we found time argument */ 01531 else if(!strcmp(variables[x],"eday")){ 01532 x++; 01533 if(variables[x]==NULL){ 01534 error=TRUE; 01535 break; 01536 } 01537 01538 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01539 continue; 01540 01541 end_day=atoi(variables[x]); 01542 timeperiod_type=TIMEPERIOD_CUSTOM; 01543 compute_time_from_parts=TRUE; 01544 } 01545 01546 /* we found time argument */ 01547 else if(!strcmp(variables[x],"eyear")){ 01548 x++; 01549 if(variables[x]==NULL){ 01550 error=TRUE; 01551 break; 01552 } 01553 01554 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01555 continue; 01556 01557 end_year=atoi(variables[x]); 01558 timeperiod_type=TIMEPERIOD_CUSTOM; 01559 compute_time_from_parts=TRUE; 01560 } 01561 01562 /* we found time argument */ 01563 else if(!strcmp(variables[x],"emin")){ 01564 x++; 01565 if(variables[x]==NULL){ 01566 error=TRUE; 01567 break; 01568 } 01569 01570 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01571 continue; 01572 01573 end_minute=atoi(variables[x]); 01574 timeperiod_type=TIMEPERIOD_CUSTOM; 01575 compute_time_from_parts=TRUE; 01576 } 01577 01578 /* we found time argument */ 01579 else if(!strcmp(variables[x],"esec")){ 01580 x++; 01581 if(variables[x]==NULL){ 01582 error=TRUE; 01583 break; 01584 } 01585 01586 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01587 continue; 01588 01589 end_second=atoi(variables[x]); 01590 timeperiod_type=TIMEPERIOD_CUSTOM; 01591 compute_time_from_parts=TRUE; 01592 } 01593 01594 /* we found time argument */ 01595 else if(!strcmp(variables[x],"ehour")){ 01596 x++; 01597 if(variables[x]==NULL){ 01598 error=TRUE; 01599 break; 01600 } 01601 01602 if(timeperiod_type!=TIMEPERIOD_CUSTOM) 01603 continue; 01604 01605 end_hour=atoi(variables[x]); 01606 timeperiod_type=TIMEPERIOD_CUSTOM; 01607 compute_time_from_parts=TRUE; 01608 } 01609 01610 /* we found the embed option */ 01611 else if(!strcmp(variables[x],"embedded")) 01612 embedded=TRUE; 01613 01614 /* we found the noheader option */ 01615 else if(!strcmp(variables[x],"noheader")) 01616 display_header=FALSE; 01617 01618 /* we found the nopopups option */ 01619 else if(!strcmp(variables[x],"nopopups")) 01620 display_popups=FALSE; 01621 01622 /* we found the nomap option */ 01623 else if(!strcmp(variables[x],"nomap")){ 01624 display_popups=FALSE; 01625 use_map=FALSE; 01626 } 01627 01628 /* we found the input option */ 01629 else if(!strcmp(variables[x],"input")){ 01630 x++; 01631 if(variables[x]==NULL){ 01632 error=TRUE; 01633 break; 01634 } 01635 01636 if(!strcmp(variables[x],"gethost")) 01637 input_type=GET_INPUT_HOST_TARGET; 01638 else if(!strcmp(variables[x],"getservice")) 01639 input_type=GET_INPUT_SERVICE_TARGET; 01640 else if(!strcmp(variables[x],"getoptions")) 01641 input_type=GET_INPUT_OPTIONS; 01642 else 01643 input_type=GET_INPUT_TARGET_TYPE; 01644 } 01645 01646 /* we found the small image option */ 01647 else if(!strcmp(variables[x],"smallimage")) 01648 small_image=TRUE; 01649 01650 /* we found the nodaemoncheck option */ 01651 else if(!strcmp(variables[x],"nodaemoncheck")) 01652 daemon_check=FALSE; 01653 01654 else if(!strcmp(variables[x],"ignorerestart")) 01655 ignore_daemon_restart=TRUE; 01656 01657 } 01658 01659 /* free memory allocated to the CGI variables */ 01660 free_cgivars(variables); 01661 01662 return error; 01663 } 01664 01665 01666 01667 /* top level routine for graphic all trend data */ 01668 void graph_all_trend_data(void){ 01669 archived_state *temp_as; 01670 archived_state *last_as; 01671 time_t a; 01672 time_t b; 01673 time_t current_time; 01674 int current_state=AS_NO_DATA; 01675 int have_some_real_data=FALSE; 01676 hoststatus *hststatus=NULL; 01677 servicestatus *svcstatus=NULL; 01678 unsigned long wobble=300; 01679 int first_real_state=AS_NO_DATA; 01680 time_t initial_assumed_time; 01681 int initial_assumed_state=AS_SVC_OK; 01682 int error=FALSE; 01683 01684 01685 time(¤t_time); 01686 01687 /* if left hand of graph is after current time, we can't do anything at all.... */ 01688 if(t1>current_time) 01689 return; 01690 01691 /* find current state for host or service */ 01692 if(display_type==DISPLAY_HOST_TRENDS) 01693 hststatus=find_hoststatus(host_name); 01694 else 01695 svcstatus=find_servicestatus(host_name,service_desc); 01696 01697 01698 /************************************/ 01699 /* INSERT CURRENT STATE (IF WE CAN) */ 01700 /************************************/ 01701 01702 /* if current time DOES NOT fall within graph bounds, so we can't do anything as far as assuming current state */ 01703 /* the "wobble" value is necessary because when the CGI is called to do the PNG generation, t2 will actually be less that current_time by a bit */ 01704 01705 /* if we don't have any data, assume current state (if possible) */ 01706 if(as_list==NULL && current_time>t1 && current_time<(t2+wobble)){ 01707 01708 /* we don't have any historical information, but the current time falls within the reporting period, so use */ 01709 /* the current status of the host/service as the starting data */ 01710 if(display_type==DISPLAY_HOST_TRENDS){ 01711 if(hststatus!=NULL){ 01712 01713 if(hststatus->status==HOST_DOWN) 01714 last_known_state=AS_HOST_DOWN; 01715 else if(hststatus->status==HOST_UNREACHABLE) 01716 last_known_state=AS_HOST_UNREACHABLE; 01717 else 01718 last_known_state=AS_HOST_UP; 01719 01720 /* add a dummy archived state item, so something can get graphed */ 01721 add_archived_state(last_known_state,AS_HARD_STATE,t1,"Current Host State Assumed (Faked Log Entry)"); 01722 01723 /* use the current state as the last known real state */ 01724 first_real_state=last_known_state; 01725 } 01726 } 01727 else{ 01728 if(svcstatus!=NULL){ 01729 01730 if(svcstatus->status==SERVICE_OK) 01731 last_known_state=AS_SVC_OK; 01732 else if(svcstatus->status==SERVICE_WARNING) 01733 last_known_state=AS_SVC_WARNING; 01734 else if(svcstatus->status==SERVICE_CRITICAL) 01735 last_known_state=AS_SVC_CRITICAL; 01736 else if(svcstatus->status==SERVICE_UNKNOWN) 01737 last_known_state=AS_SVC_UNKNOWN; 01738 01739 /* add a dummy archived state item, so something can get graphed */ 01740 add_archived_state(last_known_state,AS_HARD_STATE,t1,"Current Service State Assumed (Faked Log Entry)"); 01741 01742 /* use the current state as the last known real state */ 01743 first_real_state=last_known_state; 01744 } 01745 } 01746 } 01747 01748 01749 /******************************************/ 01750 /* INSERT FIRST ASSUMED STATE (IF WE CAN) */ 01751 /******************************************/ 01752 01753 if((display_type==DISPLAY_HOST_TRENDS && initial_assumed_host_state!=AS_NO_DATA) || (display_type==DISPLAY_SERVICE_TRENDS && initial_assumed_service_state!=AS_NO_DATA)){ 01754 01755 /* see if its okay to assume initial state for this subject */ 01756 error=FALSE; 01757 if(display_type==DISPLAY_SERVICE_TRENDS){ 01758 if(initial_assumed_service_state!=AS_SVC_OK && initial_assumed_service_state!=AS_SVC_WARNING && initial_assumed_service_state!=AS_SVC_UNKNOWN && initial_assumed_service_state!=AS_SVC_CRITICAL && initial_assumed_service_state!=AS_CURRENT_STATE) 01759 error=TRUE; 01760 else 01761 initial_assumed_state=initial_assumed_service_state; 01762 if(initial_assumed_service_state==AS_CURRENT_STATE && svcstatus==NULL) 01763 error=TRUE; 01764 } 01765 else{ 01766 if(initial_assumed_host_state!=AS_HOST_UP && initial_assumed_host_state!=AS_HOST_DOWN && initial_assumed_host_state!=AS_HOST_UNREACHABLE && initial_assumed_host_state!=AS_CURRENT_STATE) 01767 error=TRUE; 01768 else 01769 initial_assumed_state=initial_assumed_host_state; 01770 if(initial_assumed_host_state==AS_CURRENT_STATE && hststatus==NULL) 01771 error=TRUE; 01772 } 01773 01774 /* get the current state if applicable */ 01775 if(((display_type==DISPLAY_HOST_TRENDS && initial_assumed_host_state==AS_CURRENT_STATE) || (display_type==DISPLAY_SERVICE_TRENDS && initial_assumed_service_state==AS_CURRENT_STATE)) && error==FALSE){ 01776 if(display_type==DISPLAY_HOST_TRENDS){ 01777 switch(hststatus->status){ 01778 case HOST_DOWN: 01779 initial_assumed_state=AS_HOST_DOWN; 01780 break; 01781 case HOST_UNREACHABLE: 01782 initial_assumed_state=AS_HOST_UNREACHABLE; 01783 break; 01784 case HOST_UP: 01785 initial_assumed_state=AS_HOST_UP; 01786 break; 01787 default: 01788 error=TRUE; 01789 break; 01790 } 01791 } 01792 else{ 01793 switch(svcstatus->status){ 01794 case SERVICE_OK: 01795 initial_assumed_state=AS_SVC_OK; 01796 break; 01797 case SERVICE_WARNING: 01798 initial_assumed_state=AS_SVC_WARNING; 01799 break; 01800 case SERVICE_UNKNOWN: 01801 initial_assumed_state=AS_SVC_UNKNOWN; 01802 break; 01803 case SERVICE_CRITICAL: 01804 initial_assumed_state=AS_SVC_CRITICAL; 01805 break; 01806 default: 01807 error=TRUE; 01808 break; 01809 } 01810 } 01811 } 01812 01813 if(error==FALSE){ 01814 01815 /* add this assumed state entry before any entries in the list and <= t1 */ 01816 if(as_list==NULL) 01817 initial_assumed_time=t1; 01818 else if(as_list->time_stamp>t1) 01819 initial_assumed_time=t1; 01820 else 01821 initial_assumed_time=as_list->time_stamp-1; 01822 01823 if(display_type==DISPLAY_HOST_TRENDS) 01824 add_archived_state(initial_assumed_state,AS_HARD_STATE,initial_assumed_time,"First Host State Assumed (Faked Log Entry)"); 01825 else 01826 add_archived_state(initial_assumed_state,AS_HARD_STATE,initial_assumed_time,"First Service State Assumed (Faked Log Entry)"); 01827 } 01828 } 01829 01830 01831 01832 01833 /**************************************/ 01834 /* BAIL OUT IF WE DON'T HAVE ANYTHING */ 01835 /**************************************/ 01836 01837 have_some_real_data=FALSE; 01838 for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){ 01839 if(temp_as->entry_type!=AS_NO_DATA && temp_as->entry_type!=AS_PROGRAM_START && temp_as->entry_type!=AS_PROGRAM_END){ 01840 have_some_real_data=TRUE; 01841 break; 01842 } 01843 } 01844 if(have_some_real_data==FALSE) 01845 return; 01846 01847 01848 01849 01850 /* if we're creating the HTML, start map code... */ 01851 if(content_type==HTML_CONTENT) 01852 printf("<MAP name='trendsmap'>\n"); 01853 01854 last_as=NULL; 01855 earliest_time=t2; 01856 latest_time=t1; 01857 01858 01859 01860 #ifdef DEBUG 01861 printf("--- BEGINNING/MIDDLE SECTION ---<BR>\n"); 01862 #endif 01863 01864 /**********************************/ 01865 /* BEGINNING/MIDDLE SECTION */ 01866 /**********************************/ 01867 01868 for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){ 01869 01870 /* keep this as last known state if this is the first entry or if it occurs before the starting point of the graph */ 01871 if((temp_as->time_stamp<=t1 || temp_as==as_list) && (temp_as->entry_type!=AS_NO_DATA && temp_as->entry_type!=AS_PROGRAM_END && temp_as->entry_type!=AS_PROGRAM_START)){ 01872 last_known_state=temp_as->entry_type; 01873 #ifdef DEBUG 01874 printf("SETTING LAST KNOWN STATE=%d<br>\n",last_known_state); 01875 #endif 01876 } 01877 01878 /* skip this entry if it occurs before the starting point of the graph */ 01879 if(temp_as->time_stamp<=t1){ 01880 #ifdef DEBUG 01881 printf("SKIPPING PRE-EVENT: %d @ %lu<br>\n",temp_as->entry_type,temp_as->time_stamp); 01882 #endif 01883 last_as=temp_as; 01884 continue; 01885 } 01886 01887 /* graph this span if we're not on the first item */ 01888 if(last_as!=NULL){ 01889 01890 a=last_as->time_stamp; 01891 b=temp_as->time_stamp; 01892 01893 /* we've already passed the last time displayed in the graph */ 01894 if(a>t2) 01895 break; 01896 01897 /* only graph this data if its on the graph */ 01898 else if(b>t1){ 01899 01900 /* clip last time if it exceeds graph limits */ 01901 if(b>t2) 01902 b=t2; 01903 01904 /* clip first time if it precedes graph limits */ 01905 if(a<t1) 01906 a=t1; 01907 01908 /* save this time if its the earliest we've graphed */ 01909 if(a<earliest_time){ 01910 earliest_time=a; 01911 earliest_state=last_as->entry_type; 01912 } 01913 01914 /* save this time if its the latest we've graphed */ 01915 if(b>latest_time){ 01916 latest_time=b; 01917 latest_state=last_as->entry_type; 01918 } 01919 01920 /* compute availability times for this chunk */ 01921 graph_trend_data(last_as->entry_type,temp_as->entry_type,last_as->time_stamp,a,b,last_as->state_info); 01922 01923 /* return if we've reached the end of the graph limits */ 01924 if(b>=t2){ 01925 last_as=temp_as; 01926 break; 01927 } 01928 } 01929 } 01930 01931 01932 /* keep track of the last item */ 01933 last_as=temp_as; 01934 } 01935 01936 01937 #ifdef DEBUG 01938 printf("--- END SECTION ---<BR>\n"); 01939 #endif 01940 01941 /**********************************/ 01942 /* END SECTION */ 01943 /**********************************/ 01944 01945 if(last_as!=NULL){ 01946 01947 /* don't process an entry that is beyond the limits of the graph */ 01948 if(last_as->time_stamp<t2){ 01949 01950 time(¤t_time); 01951 b=current_time; 01952 if(b>t2) 01953 b=t2; 01954 01955 a=last_as->time_stamp; 01956 if(a<t1) 01957 a=t1; 01958 01959 /* fake the current state (it doesn't really matter for graphing) */ 01960 if(display_type==DISPLAY_HOST_TRENDS) 01961 current_state=AS_HOST_UP; 01962 else 01963 current_state=AS_SVC_OK; 01964 01965 /* compute availability times for last state */ 01966 graph_trend_data(last_as->entry_type,current_state,a,a,b,last_as->state_info); 01967 } 01968 } 01969 01970 01971 01972 /* if we're creating the HTML, close the map code */ 01973 if(content_type==HTML_CONTENT) 01974 printf("</MAP>\n"); 01975 01976 return; 01977 } 01978 01979 01980 01981 /* graphs trend data */ 01982 void graph_trend_data(int first_state,int last_state,time_t real_start_time,time_t start_time,time_t end_time,char *state_info){ 01983 int start_state; 01984 int end_state; 01985 int start_pixel=0; 01986 int end_pixel=0; 01987 int color_to_use=0; 01988 int height=0; 01989 double start_pixel_ratio; 01990 double end_pixel_ratio; 01991 char temp_buffer[MAX_INPUT_BUFFER]; 01992 char state_string[MAX_INPUT_BUFFER]; 01993 char end_timestring[MAX_INPUT_BUFFER]; 01994 char start_timestring[MAX_INPUT_BUFFER]; 01995 time_t center_time; 01996 time_t next_start_time; 01997 time_t next_end_time; 01998 int days=0; 01999 int hours=0; 02000 int minutes=0; 02001 int seconds=0; 02002 02003 /* can't graph if we don't have data... */ 02004 if(first_state==AS_NO_DATA || last_state==AS_NO_DATA) 02005 return; 02006 if(first_state==AS_PROGRAM_START && (last_state==AS_PROGRAM_END || last_state==AS_PROGRAM_START)){ 02007 if(assume_initial_states==FALSE) 02008 return; 02009 } 02010 if(first_state==AS_PROGRAM_END){ 02011 if(assume_states_during_notrunning==TRUE) 02012 first_state=last_known_state; 02013 else 02014 return; 02015 } 02016 02017 /* special case if first entry was program start */ 02018 if(first_state==AS_PROGRAM_START){ 02019 #ifdef DEBUG 02020 printf("First state=program start!\n"); 02021 #endif 02022 if(assume_initial_states==TRUE){ 02023 #ifdef DEBUG 02024 printf("\tWe are assuming initial states...\n"); 02025 #endif 02026 if(assume_state_retention==TRUE){ 02027 start_state=last_known_state; 02028 #ifdef DEBUG 02029 printf("\tWe are assuming state retention (%d)...\n",start_state); 02030 #endif 02031 } 02032 else{ 02033 #ifdef DEBUG 02034 printf("\tWe are NOT assuming state retention...\n"); 02035 #endif 02036 if(display_type==DISPLAY_HOST_TRENDS) 02037 start_state=AS_HOST_UP; 02038 else 02039 start_state=AS_SVC_OK; 02040 } 02041 } 02042 else{ 02043 #ifdef DEBUG 02044 printf("We ARE NOT assuming initial states!\n"); 02045 #endif 02046 return; 02047 } 02048 } 02049 else{ 02050 start_state=first_state; 02051 last_known_state=first_state; 02052 } 02053 02054 /* special case if last entry was program stop */ 02055 if(last_state==AS_PROGRAM_END) 02056 end_state=first_state; 02057 else 02058 end_state=last_state; 02059 02060 #ifdef DEBUG 02061 printf("Graphing state %d\n",start_state); 02062 printf("\tfrom %s",ctime(&start_time)); 02063 printf("\tto %s",ctime(&end_time)); 02064 #endif 02065 02066 if(start_time<t1) 02067 start_time=t1; 02068 if(end_time>t2) 02069 end_time=t2; 02070 if(end_time<t1 || start_time>t2) 02071 return; 02072 02073 /* calculate the first and last pixels to use */ 02074 if(start_time==t1) 02075 start_pixel=0; 02076 else{ 02077 start_pixel_ratio=((double)(start_time-t1))/((double)(t2-t1)); 02078 start_pixel=(int)(start_pixel_ratio*(drawing_width-1)); 02079 } 02080 if(end_time==t1) 02081 end_pixel=0; 02082 else{ 02083 end_pixel_ratio=((double)(end_time-t1))/((double)(t2-t1)); 02084 end_pixel=(int)(end_pixel_ratio*(drawing_width-1)); 02085 } 02086 02087 #ifdef DEBUG 02088 printf("\tPixel %d to %d\n\n",start_pixel,end_pixel); 02089 #endif 02090 02091 02092 /* we're creating the image, so draw... */ 02093 if(content_type==IMAGE_CONTENT){ 02094 02095 /* figure out the color to use for drawing */ 02096 switch(start_state){ 02097 case AS_HOST_UP: 02098 color_to_use=color_green; 02099 height=60; 02100 break; 02101 case AS_HOST_DOWN: 02102 color_to_use=color_red; 02103 height=40; 02104 break; 02105 case AS_HOST_UNREACHABLE: 02106 color_to_use=color_darkred; 02107 height=20; 02108 break; 02109 case AS_SVC_OK: 02110 color_to_use=color_green; 02111 height=80; 02112 break; 02113 case AS_SVC_WARNING: 02114 color_to_use=color_yellow; 02115 height=60; 02116 break; 02117 case AS_SVC_UNKNOWN: 02118 color_to_use=color_orange; 02119 height=40; 02120 break; 02121 case AS_SVC_CRITICAL: 02122 color_to_use=color_red; 02123 height=20; 02124 break; 02125 default: 02126 color_to_use=color_black; 02127 height=0; 02128 break; 02129 } 02130 02131 /* draw a rectangle */ 02132 if(start_state!=AS_NO_DATA) 02133 gdImageFilledRectangle(trends_image,start_pixel+drawing_x_offset,drawing_height-height+drawing_y_offset,end_pixel+drawing_x_offset,drawing_height+drawing_y_offset,color_to_use); 02134 } 02135 02136 /* else we're creating the HTML, so write map area code... */ 02137 else{ 02138 02139 02140 /* figure out the the state string to use */ 02141 switch(start_state){ 02142 case AS_HOST_UP: 02143 strcpy(state_string,"UP"); 02144 height=60; 02145 break; 02146 case AS_HOST_DOWN: 02147 strcpy(state_string,"DOWN"); 02148 height=40; 02149 break; 02150 case AS_HOST_UNREACHABLE: 02151 strcpy(state_string,"UNREACHABLE"); 02152 height=20; 02153 break; 02154 case AS_SVC_OK: 02155 strcpy(state_string,"OK"); 02156 height=80; 02157 break; 02158 case AS_SVC_WARNING: 02159 strcpy(state_string,"WARNING"); 02160 height=60; 02161 break; 02162 case AS_SVC_UNKNOWN: 02163 strcpy(state_string,"UNKNOWN"); 02164 height=40; 02165 break; 02166 case AS_SVC_CRITICAL: 02167 strcpy(state_string,"CRITICAL"); 02168 height=20; 02169 break; 02170 default: 02171 strcpy(state_string,"?"); 02172 height=5; 02173 break; 02174 } 02175 02176 /* get the center of this time range */ 02177 center_time=start_time+((end_time-start_time)/2); 02178 02179 /* determine next start and end time range with zoom factor */ 02180 if(zoom_factor>0){ 02181 next_start_time=center_time-(((t2-t1)/2)/zoom_factor); 02182 next_end_time=center_time+(((t2-t1)/2)/zoom_factor); 02183 } 02184 else{ 02185 next_start_time=center_time+(((t2-t1)/2)*zoom_factor); 02186 next_end_time=center_time-(((t2-t1)/2)*zoom_factor); 02187 } 02188 02189 printf("<AREA shape='rect' "); 02190 02191 printf("coords='%d,%d,%d,%d' ",drawing_x_offset+start_pixel,drawing_y_offset+(drawing_height-height),drawing_x_offset+end_pixel,drawing_y_offset+drawing_height); 02192 02193 printf("href='%s?t1=%lu&t2=%lu&host=%s",TRENDS_CGI,(unsigned long)next_start_time,(unsigned long)next_end_time,url_encode(host_name)); 02194 if(display_type==DISPLAY_SERVICE_TRENDS) 02195 printf("&service=%s",url_encode(service_desc)); 02196 printf("&assumeinitialstates=%s",(assume_initial_states==TRUE)?"yes":"no"); 02197 printf("&initialassumedhoststate=%d",initial_assumed_host_state); 02198 printf("&initialassumedservicestate=%d",initial_assumed_service_state); 02199 printf("&assumestateretention=%s",(assume_state_retention==TRUE)?"yes":"no"); 02200 printf("&assumestatesduringnotrunning=%s",(assume_states_during_notrunning==TRUE)?"yes":"no"); 02201 printf("&includesoftstates=%s",(include_soft_states==TRUE)?"yes":"no"); 02202 if(backtrack_archives>0) 02203 printf("&backtrack=%d",backtrack_archives); 02204 printf("&zoom=%d",zoom_factor); 02205 02206 printf("' "); 02207 02208 /* display popup text */ 02209 if(display_popups==TRUE){ 02210 02211 snprintf(start_timestring,sizeof(start_timestring)-1,"%s",ctime(&real_start_time)); 02212 start_timestring[sizeof(start_timestring)-1]='\x0'; 02213 start_timestring[strlen(start_timestring)-1]='\x0'; 02214 02215 snprintf(end_timestring,sizeof(end_timestring)-1,"%s",ctime(&end_time)); 02216 end_timestring[sizeof(end_timestring)-1]='\x0'; 02217 end_timestring[strlen(end_timestring)-1]='\x0'; 02218 02219 /* calculate total time in this state */ 02220 get_time_breakdown((time_t)(end_time-start_time),&days,&hours,&minutes,&seconds); 02221 02222 /* sanitize plugin output */ 02223 sanitize_plugin_output(state_info); 02224 02225 printf("onMouseOver='showPopup(\""); 02226 snprintf(temp_buffer,sizeof(temp_buffer)-1,"<B><U>%s</U></B><BR><B>Time Range</B>: <I>%s</I> to <I>%s</I><BR><B>Duration</B>: <I>%dd %dh %dm %ds</I><BR><B>State Info</B>: <I>%s</I>",state_string,start_timestring,end_timestring,days,hours,minutes,seconds,(state_info==NULL)?"N/A":state_info); 02227 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 02228 printf("%s",temp_buffer); 02229 printf("\",event)' onMouseOut='hidePopup()'"); 02230 } 02231 02232 printf(">\n"); 02233 02234 } 02235 02236 02237 /* calculate time in this state */ 02238 switch(start_state){ 02239 case AS_HOST_UP: 02240 time_up+=(unsigned long)(end_time-start_time); 02241 break; 02242 case AS_HOST_DOWN: 02243 time_down+=(unsigned long)(end_time-start_time); 02244 break; 02245 case AS_HOST_UNREACHABLE: 02246 time_unreachable+=(unsigned long)(end_time-start_time); 02247 break; 02248 case AS_SVC_OK: 02249 time_ok+=(unsigned long)(end_time-start_time); 02250 break; 02251 case AS_SVC_WARNING: 02252 time_warning+=(unsigned long)(end_time-start_time); 02253 break; 02254 case AS_SVC_UNKNOWN: 02255 time_unknown+=(unsigned long)(end_time-start_time); 02256 break; 02257 case AS_SVC_CRITICAL: 02258 time_critical+=(unsigned long)(end_time-start_time); 02259 break; 02260 default: 02261 break; 02262 } 02263 02264 return; 02265 } 02266 02267 02268 02269 /* convert current host state to archived state value */ 02270 int convert_host_state_to_archived_state(int current_status){ 02271 02272 if(current_status==HOST_UP) 02273 return AS_HOST_UP; 02274 if(current_status==HOST_DOWN) 02275 return AS_HOST_DOWN; 02276 if(current_status==HOST_UNREACHABLE) 02277 return AS_HOST_UNREACHABLE; 02278 02279 return AS_NO_DATA; 02280 } 02281 02282 02283 /* convert current service state to archived state value */ 02284 int convert_service_state_to_archived_state(int current_status){ 02285 02286 if(current_status==SERVICE_OK) 02287 return AS_SVC_OK; 02288 if(current_status==SERVICE_UNKNOWN) 02289 return AS_SVC_UNKNOWN; 02290 if(current_status==SERVICE_WARNING) 02291 return AS_SVC_WARNING; 02292 if(current_status==SERVICE_CRITICAL) 02293 return AS_SVC_CRITICAL; 02294 02295 return AS_NO_DATA; 02296 } 02297 02298 02299 02300 /* adds an archived state entry */ 02301 void add_archived_state(int entry_type, int state_type, time_t time_stamp, char *state_info){ 02302 archived_state *last_as=NULL; 02303 archived_state *temp_as=NULL; 02304 archived_state *new_as=NULL; 02305 02306 #ifdef DEBUG 02307 printf("Added state %d @ %s",state_type,ctime(&time_stamp)); 02308 #endif 02309 02310 /* allocate memory for the new entry */ 02311 new_as=(archived_state *)malloc(sizeof(archived_state)); 02312 if(new_as==NULL) 02313 return; 02314 02315 /* allocate memory fo the state info */ 02316 if(state_info!=NULL){ 02317 new_as->state_info=(char *)malloc(strlen(state_info)+1); 02318 if(new_as->state_info!=NULL) 02319 strcpy(new_as->state_info,state_info); 02320 } 02321 else new_as->state_info=NULL; 02322 02323 new_as->entry_type=entry_type; 02324 new_as->processed_state=entry_type; 02325 new_as->state_type=state_type; 02326 new_as->time_stamp=time_stamp; 02327 02328 /* add the new entry to the list in memory, sorted by time */ 02329 last_as=as_list; 02330 for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){ 02331 if(new_as->time_stamp<temp_as->time_stamp){ 02332 new_as->next=temp_as; 02333 if(temp_as==as_list) 02334 as_list=new_as; 02335 else 02336 last_as->next=new_as; 02337 break; 02338 } 02339 else 02340 last_as=temp_as; 02341 } 02342 if(as_list==NULL){ 02343 new_as->next=NULL; 02344 as_list=new_as; 02345 } 02346 else if(temp_as==NULL){ 02347 new_as->next=NULL; 02348 last_as->next=new_as; 02349 } 02350 02351 return; 02352 } 02353 02354 02355 /* frees memory allocated to the archived state list */ 02356 void free_archived_state_list(void){ 02357 archived_state *this_as=NULL; 02358 archived_state *next_as=NULL; 02359 02360 for(this_as=as_list;this_as!=NULL;){ 02361 next_as=this_as->next; 02362 if(this_as->state_info!=NULL) 02363 free(this_as->state_info); 02364 free(this_as); 02365 this_as=next_as; 02366 } 02367 02368 as_list=NULL; 02369 02370 return; 02371 } 02372 02373 02374 /* reads log files for archived state data */ 02375 void read_archived_state_data(void){ 02376 char filename[MAX_FILENAME_LENGTH]; 02377 int newest_archive=0; 02378 int oldest_archive=0; 02379 int current_archive; 02380 02381 #ifdef DEBUG 02382 printf("Determining archives to use...\n"); 02383 #endif 02384 02385 /* determine earliest archive to use */ 02386 oldest_archive=determine_archive_to_use_from_time(t1); 02387 if(log_rotation_method!=LOG_ROTATION_NONE) 02388 oldest_archive+=backtrack_archives; 02389 02390 /* determine most recent archive to use */ 02391 newest_archive=determine_archive_to_use_from_time(t2); 02392 02393 if(oldest_archive<newest_archive) 02394 oldest_archive=newest_archive; 02395 02396 #ifdef DEBUG 02397 printf("Oldest archive: %d\n",oldest_archive); 02398 printf("Newest archive: %d\n",newest_archive); 02399 #endif 02400 02401 /* Service filter */ 02402 add_log_filter(LOGENTRY_SERVICE_OK,LOGFILTER_INCLUDE); 02403 add_log_filter(LOGENTRY_SERVICE_WARNING,LOGFILTER_INCLUDE); 02404 add_log_filter(LOGENTRY_SERVICE_CRITICAL,LOGFILTER_INCLUDE); 02405 add_log_filter(LOGENTRY_SERVICE_UNKNOWN,LOGFILTER_INCLUDE); 02406 add_log_filter(LOGENTRY_SERVICE_RECOVERY,LOGFILTER_INCLUDE); 02407 add_log_filter(LOGENTRY_SERVICE_INITIAL_STATE,LOGFILTER_INCLUDE); 02408 add_log_filter(LOGENTRY_SERVICE_CURRENT_STATE,LOGFILTER_INCLUDE); 02409 02410 /* Host filter */ 02411 add_log_filter(LOGENTRY_HOST_UP,LOGFILTER_INCLUDE); 02412 add_log_filter(LOGENTRY_HOST_DOWN,LOGFILTER_INCLUDE); 02413 add_log_filter(LOGENTRY_HOST_UNREACHABLE,LOGFILTER_INCLUDE); 02414 add_log_filter(LOGENTRY_HOST_RECOVERY,LOGFILTER_INCLUDE); 02415 add_log_filter(LOGENTRY_HOST_INITIAL_STATE,LOGFILTER_INCLUDE); 02416 add_log_filter(LOGENTRY_HOST_CURRENT_STATE,LOGFILTER_INCLUDE); 02417 02418 if (ignore_daemon_restart==FALSE) { 02419 add_log_filter(LOGENTRY_STARTUP,LOGFILTER_INCLUDE); 02420 add_log_filter(LOGENTRY_RESTART,LOGFILTER_INCLUDE); 02421 add_log_filter(LOGENTRY_SHUTDOWN,LOGFILTER_INCLUDE); 02422 add_log_filter(LOGENTRY_BAILOUT,LOGFILTER_INCLUDE); 02423 } 02424 02425 /* read in all the necessary archived logs */ 02426 for(current_archive=newest_archive;current_archive<=oldest_archive;current_archive++){ 02427 02428 /* get the name of the log file that contains this archive */ 02429 get_log_archive_to_use(current_archive,filename,sizeof(filename)-1); 02430 02431 #ifdef DEBUG 02432 printf("\tCurrent archive: %d (%s)\n",current_archive,filename); 02433 #endif 02434 02435 /* scan the log file for archived state data */ 02436 scan_log_file_for_archived_state_data(filename); 02437 } 02438 02439 free_log_filters(); 02440 02441 return; 02442 } 02443 02444 02445 /* grabs archives state data from a log file */ 02446 void scan_log_file_for_archived_state_data(char *filename){ 02447 char entry_host_name[MAX_INPUT_BUFFER]; 02448 char entry_service_desc[MAX_INPUT_BUFFER]; 02449 char *plugin_output=NULL; 02450 char *temp_buffer=NULL; 02451 logentry *temp_entry=NULL; 02452 int state_type=0,status; 02453 02454 /* print something so browser doesn't time out */ 02455 if(content_type==HTML_CONTENT){ 02456 printf(" "); 02457 fflush(NULL); 02458 } 02459 02460 status = get_log_entries(filename,NULL,FALSE,t1-(60*60*24*backtrack_archives),t2); 02461 02462 if (status!=READLOG_OK) { 02463 #ifdef DEBUG 02464 printf("Could not open file '%s' for reading.\n",filename); 02465 #endif 02466 free_log_entries(); 02467 return; 02468 }else{ 02469 02470 #ifdef DEBUG 02471 printf("Scanning log file '%s' for archived state data...\n",filename); 02472 #endif 02473 02474 02475 for(temp_entry=entry_list;temp_entry!=NULL;temp_entry=temp_entry->next) { 02476 02477 if (ignore_daemon_restart==FALSE) { 02478 /* program starts/restarts */ 02479 if(temp_entry->type==LOGENTRY_STARTUP) 02480 add_archived_state(AS_PROGRAM_START,AS_NO_DATA,temp_entry->timestamp,"Program start"); 02481 if(temp_entry->type==LOGENTRY_RESTART) 02482 add_archived_state(AS_PROGRAM_START,AS_NO_DATA,temp_entry->timestamp,"Program restart"); 02483 02484 /* program stops */ 02485 if(temp_entry->type==LOGENTRY_SHUTDOWN) 02486 add_archived_state(AS_PROGRAM_END,AS_NO_DATA,temp_entry->timestamp,"Normal program termination"); 02487 if(temp_entry->type==LOGENTRY_BAILOUT) 02488 add_archived_state(AS_PROGRAM_END,AS_NO_DATA,temp_entry->timestamp,"Abnormal program termination"); 02489 } 02490 02491 if(display_type==DISPLAY_HOST_TRENDS){ 02492 02493 switch(temp_entry->type){ 02494 02495 /* normal host alerts and initial/current states */ 02496 case LOGENTRY_HOST_DOWN: 02497 case LOGENTRY_HOST_UNREACHABLE: 02498 case LOGENTRY_HOST_RECOVERY: 02499 case LOGENTRY_HOST_UP: 02500 case LOGENTRY_HOST_INITIAL_STATE: 02501 case LOGENTRY_HOST_CURRENT_STATE: 02502 02503 /* get host name */ 02504 temp_buffer=my_strtok(temp_entry->entry_text,":"); 02505 temp_buffer=my_strtok(NULL,";"); 02506 strncpy(entry_host_name,(temp_buffer==NULL)?"":temp_buffer+1,sizeof(entry_host_name)); 02507 entry_host_name[sizeof(entry_host_name)-1]='\x0'; 02508 02509 if(strcmp(host_name,entry_host_name)) 02510 break; 02511 02512 /* state types */ 02513 if(strstr(temp_entry->entry_text,";SOFT;")){ 02514 if(include_soft_states==FALSE) 02515 break; 02516 state_type=AS_SOFT_STATE; 02517 } 02518 if(strstr(temp_entry->entry_text,";HARD;")) 02519 state_type=AS_HARD_STATE; 02520 02521 /* get the plugin output */ 02522 temp_buffer=my_strtok(NULL,";"); 02523 temp_buffer=my_strtok(NULL,";"); 02524 temp_buffer=my_strtok(NULL,";"); 02525 plugin_output=my_strtok(NULL,"\n"); 02526 02527 if(strstr(temp_entry->entry_text,";DOWN;")) 02528 add_archived_state(AS_HOST_DOWN,state_type,temp_entry->timestamp,plugin_output); 02529 else if(strstr(temp_entry->entry_text,";UNREACHABLE;")) 02530 add_archived_state(AS_HOST_UNREACHABLE,state_type,temp_entry->timestamp,plugin_output); 02531 else if(strstr(temp_entry->entry_text,";RECOVERY;") || strstr(temp_entry->entry_text,";UP;")) 02532 add_archived_state(AS_HOST_UP,state_type,temp_entry->timestamp,plugin_output); 02533 else 02534 add_archived_state(AS_NO_DATA,AS_NO_DATA,temp_entry->timestamp,plugin_output); 02535 02536 break; 02537 } 02538 } 02539 02540 if(display_type==DISPLAY_SERVICE_TRENDS){ 02541 02542 switch(temp_entry->type){ 02543 02544 /* normal service alerts and initial/current states */ 02545 case LOGENTRY_SERVICE_CRITICAL: 02546 case LOGENTRY_SERVICE_WARNING: 02547 case LOGENTRY_SERVICE_UNKNOWN: 02548 case LOGENTRY_SERVICE_RECOVERY: 02549 case LOGENTRY_SERVICE_OK: 02550 case LOGENTRY_SERVICE_INITIAL_STATE: 02551 case LOGENTRY_SERVICE_CURRENT_STATE: 02552 02553 /* get host name */ 02554 temp_buffer=my_strtok(temp_entry->entry_text,":"); 02555 temp_buffer=my_strtok(NULL,";"); 02556 strncpy(entry_host_name,(temp_buffer==NULL)?"":temp_buffer+1,sizeof(entry_host_name)); 02557 entry_host_name[sizeof(entry_host_name)-1]='\x0'; 02558 02559 if(strcmp(host_name,entry_host_name)) 02560 break; 02561 02562 /* get service description */ 02563 temp_buffer=my_strtok(NULL,";"); 02564 strncpy(entry_service_desc,(temp_buffer==NULL)?"":temp_buffer,sizeof(entry_service_desc)); 02565 entry_service_desc[sizeof(entry_service_desc)-1]='\x0'; 02566 02567 if(strcmp(service_desc,entry_service_desc)) 02568 break; 02569 02570 /* state types */ 02571 if(strstr(temp_entry->entry_text,";SOFT;")){ 02572 if(include_soft_states==FALSE) 02573 break; 02574 state_type=AS_SOFT_STATE; 02575 } 02576 if(strstr(temp_entry->entry_text,";HARD;")) 02577 state_type=AS_HARD_STATE; 02578 02579 /* get the plugin output */ 02580 temp_buffer=my_strtok(NULL,";"); 02581 temp_buffer=my_strtok(NULL,";"); 02582 temp_buffer=my_strtok(NULL,";"); 02583 plugin_output=my_strtok(NULL,"\n"); 02584 02585 if(strstr(temp_entry->entry_text,";CRITICAL;")) 02586 add_archived_state(AS_SVC_CRITICAL,state_type,temp_entry->timestamp,plugin_output); 02587 else if(strstr(temp_entry->entry_text,";WARNING;")) 02588 add_archived_state(AS_SVC_WARNING,state_type,temp_entry->timestamp,plugin_output); 02589 else if(strstr(temp_entry->entry_text,";UNKNOWN;")) 02590 add_archived_state(AS_SVC_UNKNOWN,state_type,temp_entry->timestamp,plugin_output); 02591 else if(strstr(temp_entry->entry_text,";RECOVERY;") || strstr(temp_entry->entry_text,";OK;")) 02592 add_archived_state(AS_SVC_OK,state_type,temp_entry->timestamp,plugin_output); 02593 else 02594 add_archived_state(AS_NO_DATA,AS_NO_DATA,temp_entry->timestamp,plugin_output); 02595 02596 break; 02597 } 02598 } 02599 } 02600 free_log_entries(); 02601 } 02602 return; 02603 } 02604 02605 02606 /* write timestamps */ 02607 void draw_timestamps(void){ 02608 int last_timestamp=0; 02609 archived_state *temp_as; 02610 double start_pixel_ratio; 02611 int start_pixel; 02612 02613 if(content_type!=IMAGE_CONTENT) 02614 return; 02615 02616 /* draw first timestamp */ 02617 draw_timestamp(0,t1); 02618 last_timestamp=0; 02619 02620 for(temp_as=as_list;temp_as!=NULL;temp_as=temp_as->next){ 02621 02622 if(temp_as->time_stamp<t1 || temp_as->time_stamp>t2) 02623 continue; 02624 02625 start_pixel_ratio=((double)(temp_as->time_stamp-t1))/((double)(t2-t1)); 02626 start_pixel=(int)(start_pixel_ratio*(drawing_width-1)); 02627 02628 /* draw start timestamp if possible */ 02629 if((start_pixel > last_timestamp+MIN_TIMESTAMP_SPACING) && (start_pixel < drawing_width-1-MIN_TIMESTAMP_SPACING)){ 02630 draw_timestamp(start_pixel,temp_as->time_stamp); 02631 last_timestamp=start_pixel; 02632 } 02633 } 02634 02635 /* draw last timestamp */ 02636 draw_timestamp(drawing_width-1,t2); 02637 02638 return; 02639 } 02640 02641 02642 /* write timestamp below graph */ 02643 void draw_timestamp(int ts_pixel, time_t ts_time){ 02644 char temp_buffer[MAX_INPUT_BUFFER]; 02645 int string_height; 02646 int string_width; 02647 02648 snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s",ctime(&ts_time)); 02649 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 02650 temp_buffer[strlen(temp_buffer)-1]='\x0'; 02651 02652 string_height=gdFontSmall->h; 02653 string_width=gdFontSmall->w*strlen(temp_buffer); 02654 02655 if(small_image==FALSE) 02656 gdImageStringUp(trends_image,gdFontSmall,ts_pixel+drawing_x_offset-(string_height/2),drawing_y_offset+drawing_height+string_width+5,(unsigned char *)temp_buffer,color_black); 02657 02658 /* draw a dashed vertical line at this point */ 02659 if(ts_pixel>0 && ts_pixel<(drawing_width-1)) 02660 draw_dashed_line(ts_pixel+drawing_x_offset,drawing_y_offset,ts_pixel+drawing_x_offset,drawing_y_offset+drawing_height,color_black); 02661 02662 return; 02663 } 02664 02665 02666 02667 /* draw total state times */ 02668 void draw_time_breakdowns(void){ 02669 char temp_buffer[MAX_INPUT_BUFFER]; 02670 unsigned long total_time=0L; 02671 unsigned long total_state_time; 02672 unsigned long time_indeterminate=0L; 02673 int string_height; 02674 02675 if(content_type==HTML_CONTENT) 02676 return; 02677 02678 if(small_image==TRUE) 02679 return; 02680 02681 total_time=(unsigned long)(t2-t1); 02682 02683 if(display_type==DISPLAY_HOST_TRENDS) 02684 total_state_time=time_up+time_down+time_unreachable; 02685 else 02686 total_state_time=time_ok+time_warning+time_unknown+time_critical; 02687 02688 if(total_state_time>=total_time) 02689 time_indeterminate=0L; 02690 else 02691 time_indeterminate=total_time-total_state_time; 02692 02693 string_height=gdFontSmall->h; 02694 02695 if(display_type==DISPLAY_HOST_TRENDS){ 02696 02697 get_time_breakdown_string(total_time,time_up,"Up",&temp_buffer[0],sizeof(temp_buffer)); 02698 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+5,(unsigned char *)temp_buffer,color_darkgreen); 02699 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*2),drawing_y_offset+5,(unsigned char *)"Up",color_darkgreen); 02700 02701 get_time_breakdown_string(total_time,time_down,"Down",&temp_buffer[0],sizeof(temp_buffer)); 02702 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+25,(unsigned char *)temp_buffer,color_red); 02703 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*4),drawing_y_offset+25,(unsigned char *)"Down",color_red); 02704 02705 get_time_breakdown_string(total_time,time_unreachable,"Unreachable",&temp_buffer[0],sizeof(temp_buffer)); 02706 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+45,(unsigned char *)temp_buffer,color_darkred); 02707 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*11),drawing_y_offset+45,(unsigned char *)"Unreachable",color_darkred); 02708 02709 get_time_breakdown_string(total_time,time_indeterminate,"Indeterminate",&temp_buffer[0],sizeof(temp_buffer)); 02710 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+65,(unsigned char *)temp_buffer,color_black); 02711 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*13),drawing_y_offset+65,(unsigned char *)"Indeterminate",color_black); 02712 } 02713 else{ 02714 get_time_breakdown_string(total_time,time_ok,"Ok",&temp_buffer[0],sizeof(temp_buffer)); 02715 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+5,(unsigned char *)temp_buffer,color_darkgreen); 02716 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*2),drawing_y_offset+5,(unsigned char *)"Ok",color_darkgreen); 02717 02718 get_time_breakdown_string(total_time,time_warning,"Warning",&temp_buffer[0],sizeof(temp_buffer)); 02719 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+25,(unsigned char *)temp_buffer,color_yellow); 02720 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*7),drawing_y_offset+25,(unsigned char *)"Warning",color_yellow); 02721 02722 get_time_breakdown_string(total_time,time_unknown,"Unknown",&temp_buffer[0],sizeof(temp_buffer)); 02723 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+45,(unsigned char *)temp_buffer,color_orange); 02724 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*7),drawing_y_offset+45,(unsigned char *)"Unknown",color_orange); 02725 02726 get_time_breakdown_string(total_time,time_critical,"Critical",&temp_buffer[0],sizeof(temp_buffer)); 02727 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+65,(unsigned char *)temp_buffer,color_red); 02728 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*8),drawing_y_offset+65,(unsigned char *)"Critical",color_red); 02729 02730 get_time_breakdown_string(total_time,time_indeterminate,"Indeterminate",&temp_buffer[0],sizeof(temp_buffer)); 02731 gdImageString(trends_image,gdFontSmall,drawing_x_offset+drawing_width+20,drawing_y_offset+85,(unsigned char *)temp_buffer,color_black); 02732 gdImageString(trends_image,gdFontSmall,drawing_x_offset-10-(gdFontSmall->w*13),drawing_y_offset+85,(unsigned char *)"Indeterminate",color_black); 02733 } 02734 02735 return; 02736 } 02737 02738 02739 void get_time_breakdown_string(unsigned long total_time, unsigned long state_time, char *state_string, char *buffer, int buffer_length){ 02740 int days; 02741 int hours; 02742 int minutes; 02743 int seconds; 02744 double percent_time; 02745 02746 get_time_breakdown(state_time,&days,&hours,&minutes,&seconds); 02747 if(total_time==0L) 02748 percent_time=0.0; 02749 else 02750 percent_time=((double)state_time/total_time)*100.0; 02751 snprintf(buffer,buffer_length-1,"%-13s: (%.3f%%) %dd %dh %dm %ds",state_string,percent_time,days,hours,minutes,seconds); 02752 buffer[buffer_length-1]='\x0'; 02753 02754 return; 02755 } 02756 02757 02758 void compute_report_times(void){ 02759 time_t current_time; 02760 struct tm *st; 02761 struct tm *et; 02762 02763 /* get the current time */ 02764 time(¤t_time); 02765 02766 st=localtime(¤t_time); 02767 02768 st->tm_sec=start_second; 02769 st->tm_min=start_minute; 02770 st->tm_hour=start_hour; 02771 st->tm_mday=start_day; 02772 st->tm_mon=start_month-1; 02773 st->tm_year=start_year-1900; 02774 st->tm_isdst=-1; 02775 02776 t1=mktime(st); 02777 02778 et=localtime(¤t_time); 02779 02780 et->tm_sec=end_second; 02781 et->tm_min=end_minute; 02782 et->tm_hour=end_hour; 02783 et->tm_mday=end_day; 02784 et->tm_mon=end_month-1; 02785 et->tm_year=end_year-1900; 02786 et->tm_isdst=-1; 02787 02788 t2=mktime(et); 02789 } 02790 02791 02792 02793 /* draws a dashed line */ 02794 void draw_dashed_line(int x1,int y1,int x2,int y2,int color){ 02795 int styleDashed[12]; 02796 02797 styleDashed[0]=color; 02798 styleDashed[1]=color; 02799 styleDashed[2]=gdTransparent; 02800 styleDashed[3]=gdTransparent; 02801 styleDashed[4]=color; 02802 styleDashed[5]=color; 02803 styleDashed[6]=gdTransparent; 02804 styleDashed[7]=gdTransparent; 02805 styleDashed[8]=color; 02806 styleDashed[9]=color; 02807 styleDashed[10]=gdTransparent; 02808 styleDashed[11]=gdTransparent; 02809 02810 /* sets current style to a dashed line */ 02811 gdImageSetStyle(trends_image,styleDashed,12); 02812 02813 /* draws a line (dashed) */ 02814 gdImageLine(trends_image,x1,y1,x2,y2,gdStyled); 02815 02816 return; 02817 } 02818 02819 02820 /* draws horizontal grid lines */ 02821 void draw_horizontal_grid_lines(void){ 02822 02823 if(content_type==HTML_CONTENT) 02824 return; 02825 02826 if(small_image==TRUE) 02827 return; 02828 02829 draw_dashed_line(drawing_x_offset,drawing_y_offset+10,drawing_x_offset+drawing_width,drawing_y_offset+10,color_black); 02830 draw_dashed_line(drawing_x_offset,drawing_y_offset+30,drawing_x_offset+drawing_width,drawing_y_offset+30,color_black); 02831 draw_dashed_line(drawing_x_offset,drawing_y_offset+50,drawing_x_offset+drawing_width,drawing_y_offset+50,color_black); 02832 if(display_type==DISPLAY_SERVICE_TRENDS) 02833 draw_dashed_line(drawing_x_offset,drawing_y_offset+70,drawing_x_offset+drawing_width,drawing_y_offset+70,color_black); 02834 02835 return; 02836 }