![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /************************************************************************** 00002 * 00003 * STATUS.C - Icinga Status CGI 00004 * 00005 * Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00007 * 00008 * Last Modified: 08-08-2010 00009 * 00010 * License: 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License version 2 as 00014 * published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 *************************************************************************/ 00025 00026 #include "../include/config.h" 00027 #include "../include/common.h" 00028 #include "../include/objects.h" 00029 #include "../include/comments.h" 00030 #include "../include/macros.h" 00031 #include "../include/statusdata.h" 00032 00033 #include "../include/cgiutils.h" 00034 #include "../include/getcgi.h" 00035 #include "../include/cgiauth.h" 00036 00037 static icinga_macros *mac; 00038 00039 extern time_t program_start; 00040 00041 extern char main_config_file[MAX_FILENAME_LENGTH]; 00042 extern char url_html_path[MAX_FILENAME_LENGTH]; 00043 extern char url_docs_path[MAX_FILENAME_LENGTH]; 00044 extern char url_images_path[MAX_FILENAME_LENGTH]; 00045 extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; 00046 extern char url_js_path[MAX_FILENAME_LENGTH]; 00047 extern char url_logo_images_path[MAX_FILENAME_LENGTH]; 00048 extern char url_media_path[MAX_FILENAME_LENGTH]; 00049 extern char log_file[MAX_FILENAME_LENGTH]; 00050 00051 extern char *service_critical_sound; 00052 extern char *service_warning_sound; 00053 extern char *service_unknown_sound; 00054 extern char *host_down_sound; 00055 extern char *host_unreachable_sound; 00056 extern char *normal_sound; 00057 00058 extern char *notes_url_target; 00059 extern char *action_url_target; 00060 00061 extern int suppress_alert_window; 00062 00063 extern int enable_splunk_integration; 00064 00065 extern int status_show_long_plugin_output; 00066 00067 extern host *host_list; 00068 extern service *service_list; 00069 extern hostgroup *hostgroup_list; 00070 extern servicegroup *servicegroup_list; 00071 extern hoststatus *hoststatus_list; 00072 extern servicestatus *servicestatus_list; 00073 00074 #define MAX_MESSAGE_BUFFER 4096 00075 00076 #define DISPLAY_HOSTS 0 00077 #define DISPLAY_HOSTGROUPS 1 00078 #define DISPLAY_SERVICEGROUPS 2 00079 00080 #define STYLE_OVERVIEW 0 00081 #define STYLE_SERVICE_DETAIL 1 00082 #define STYLE_SUMMARY 2 00083 #define STYLE_GRID 3 00084 #define STYLE_HOST_DETAIL 4 00085 00086 #define HOST_STATUS 0 00087 #define SERVICE_STATUS 1 00088 00089 /* Status data for all Elements */ 00090 typedef struct statusdata_struct{ 00091 int type; 00092 char *host_name; 00093 char *svc_description; 00094 int status; 00095 char *status_string; 00096 char *last_check; 00097 time_t ts_last_check; 00098 char *state_duration; 00099 time_t ts_state_duration; 00100 char *attempts; 00101 int current_attempt; 00102 int last_state_change; 00103 char *plugin_output; 00104 int problem_has_been_acknowledged; 00105 int scheduled_downtime_depth; 00106 int notifications_enabled; 00107 int checks_enabled; 00108 int is_flapping; 00109 struct statusdata_struct *next; 00110 }statusdata; 00111 00112 statusdata *statusdata_list=NULL; 00113 statusdata *last_statusdata=NULL; 00114 00115 /* SERVICESORT structure */ 00116 typedef struct sort_struct{ 00117 statusdata *status; 00118 struct sort_struct *next; 00119 }sort; 00120 00121 sort *statussort_list=NULL; 00122 00123 void grab_statusdata(void); 00124 int sort_status_data(int ,int , int); 00125 int compare_sort_entries(int,int,int,sort *,sort *); /* compares service sort entries */ 00126 void free_sort_list(void); 00127 int add_status_data(int,hoststatus *,servicestatus *); 00128 00129 void show_host_status_totals(void); 00130 void show_service_status_totals(void); 00131 void show_service_detail(void); 00132 void show_host_detail(void); 00133 void show_servicegroup_overviews(void); 00134 void show_servicegroup_overview(servicegroup *); 00135 void show_servicegroup_summaries(void); 00136 void show_servicegroup_summary(servicegroup *,int); 00137 void show_servicegroup_host_totals_summary(servicegroup *); 00138 void show_servicegroup_service_totals_summary(servicegroup *); 00139 void show_servicegroup_grids(void); 00140 void show_servicegroup_grid(servicegroup *); 00141 void show_hostgroup_overviews(void); 00142 void show_hostgroup_overview(hostgroup *); 00143 void show_servicegroup_hostgroup_member_overview(hoststatus *,int,void *); 00144 void show_servicegroup_hostgroup_member_service_status_totals(char *,void *); 00145 void show_hostgroup_summaries(void); 00146 void show_hostgroup_summary(hostgroup *,int); 00147 void show_hostgroup_host_totals_summary(hostgroup *); 00148 void show_hostgroup_service_totals_summary(hostgroup *); 00149 void show_hostgroup_grids(void); 00150 void show_hostgroup_grid(hostgroup *); 00151 00152 void show_servicecommand_table(void); 00153 void show_hostcommand_table(void); 00154 00155 void show_filters(void); 00156 00157 int passes_host_properties_filter(hoststatus *); 00158 int passes_service_properties_filter(servicestatus *); 00159 00160 int process_cgivars(void); 00161 00162 void print_comment_icon(char *,char *); 00163 00164 authdata current_authdata; 00165 time_t current_time; 00166 00167 char alert_message[MAX_MESSAGE_BUFFER]; 00168 char *host_name=NULL; 00169 char *host_filter=NULL; 00170 char *hostgroup_name=NULL; 00171 char *servicegroup_name=NULL; 00172 char *service_desc=NULL; 00173 char *service_filter=NULL; 00174 00175 int host_alert=FALSE; 00176 int show_all_hosts=TRUE; 00177 int show_all_hostgroups=TRUE; 00178 int show_all_servicegroups=TRUE; 00179 int display_type=DISPLAY_HOSTS; 00180 int overview_columns=3; 00181 int max_grid_width=8; 00182 int group_style_type=STYLE_OVERVIEW; 00183 int navbar_search=FALSE; 00184 int user_is_authorized_for_statusdata=FALSE; 00185 00186 int service_status_types=SERVICE_PENDING|SERVICE_OK|SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL; 00187 int all_service_status_types=SERVICE_PENDING|SERVICE_OK|SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL; 00188 00189 int host_status_types=HOST_PENDING|HOST_UP|HOST_DOWN|HOST_UNREACHABLE; 00190 int all_host_status_types=HOST_PENDING|HOST_UP|HOST_DOWN|HOST_UNREACHABLE; 00191 00192 int all_service_problems=SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL; 00193 int all_host_problems=HOST_DOWN|HOST_UNREACHABLE; 00194 00195 unsigned long host_properties=0L; 00196 unsigned long service_properties=0L; 00197 00198 int sort_type=SORT_NONE; 00199 int sort_option=SORT_HOSTNAME; 00200 00201 int problem_hosts_down=0; 00202 int problem_hosts_unreachable=0; 00203 int problem_services_critical=0; 00204 int problem_services_warning=0; 00205 int problem_services_unknown=0; 00206 00207 extern int refresh; 00208 extern int embedded; 00209 extern int display_header; 00210 extern int daemon_check; 00211 extern int content_type; 00212 extern int escape_html_tags; 00213 00214 extern int add_notif_num_hard; 00215 extern int add_notif_num_soft; 00216 00217 extern char *csv_delimiter; 00218 extern char *csv_data_enclosure; 00219 00220 int CGI_ID=STATUS_CGI_ID; 00221 00222 int main(void){ 00223 int result=OK; 00224 char *sound=NULL; 00225 host *temp_host=NULL; 00226 hostgroup *temp_hostgroup=NULL; 00227 servicegroup *temp_servicegroup=NULL; 00228 servicestatus *temp_servicestatus=NULL; 00229 int regex_i=1,i=0; 00230 int len; 00231 int host_has_no_service=TRUE; 00232 00233 mac = get_global_macros(); 00234 00235 time(¤t_time); 00236 00237 /* get the arguments passed in the URL */ 00238 process_cgivars(); 00239 00240 /* reset internal variables */ 00241 reset_cgi_vars(); 00242 00243 /* read the CGI configuration file */ 00244 result=read_cgi_config_file(get_cgi_config_location()); 00245 if(result==ERROR){ 00246 document_header(CGI_ID,FALSE); 00247 print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE); 00248 document_footer(CGI_ID); 00249 return ERROR; 00250 } 00251 00252 /* read the main configuration file */ 00253 result=read_main_config_file(main_config_file); 00254 if(result==ERROR){ 00255 document_header(CGI_ID,FALSE); 00256 print_error(main_config_file, ERROR_CGI_MAIN_CFG); 00257 document_footer(CGI_ID); 00258 return ERROR; 00259 } 00260 00261 /* read all object configuration data */ 00262 result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA); 00263 if(result==ERROR){ 00264 document_header(CGI_ID,FALSE); 00265 print_error(NULL, ERROR_CGI_OBJECT_DATA); 00266 document_footer(CGI_ID); 00267 return ERROR; 00268 } 00269 00270 /* read all status data */ 00271 result=read_all_status_data(get_cgi_config_location(),READ_ALL_STATUS_DATA); 00272 if(result==ERROR && daemon_check==TRUE){ 00273 document_header(CGI_ID,FALSE); 00274 print_error(NULL, ERROR_CGI_STATUS_DATA); 00275 document_footer(CGI_ID); 00276 free_memory(); 00277 return ERROR; 00278 } 00279 00280 /* initialize macros */ 00281 init_macros(); 00282 00283 document_header(CGI_ID,TRUE); 00284 00285 /* get authentication information */ 00286 get_authentication_information(¤t_authdata); 00287 00288 /* if a navbar search was performed, find the host by name, address or partial name */ 00289 if(navbar_search==TRUE){ 00290 if(host_name!=NULL && NULL!=strstr(host_name, "*")){ 00291 /* allocate for 3 extra chars, ^, $ and \0 */ 00292 host_filter = malloc(sizeof(char) * (strlen(host_name) * 2 + 3)); 00293 len=strlen(host_name); 00294 for (i=0;i<len;i++,regex_i++) { 00295 if(host_name[i]=='*') { 00296 host_filter[regex_i++]='.'; 00297 host_filter[regex_i]='*'; 00298 }else 00299 host_filter[regex_i]=host_name[i]; 00300 } 00301 host_filter[0]='^'; 00302 host_filter[regex_i++]='$'; 00303 host_filter[regex_i]='\0'; 00304 }else{ 00305 if((temp_host=find_host(host_name))==NULL){ 00306 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ 00307 if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 00308 continue; 00309 /* address */ 00310 if(!strcmp(host_name,temp_host->address)){ 00311 free(host_name); 00312 host_name=strdup(temp_host->name); 00313 break; 00314 } 00315 /* address6 */ 00316 if(!strcmp(host_name,temp_host->address6)){ 00317 free(host_name); 00318 host_name=strdup(temp_host->name); 00319 break; 00320 } 00321 /* display_name */ 00322 if(!strcmp(host_name,temp_host->display_name)){ 00323 free(host_name); 00324 host_name=strdup(temp_host->name); 00325 break; 00326 } 00327 } 00328 if(temp_host==NULL){ 00329 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ 00330 if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 00331 continue; 00332 /* host_name */ 00333 if((strstr(temp_host->name,host_name)==temp_host->name) || !strncasecmp(temp_host->name,host_name,strlen(host_name))){ 00334 free(host_name); 00335 host_name=strdup(temp_host->name); 00336 break; 00337 } 00338 /* display_name, use host_name as found identifier */ 00339 else if((strstr(temp_host->display_name,host_name)==temp_host->display_name) || !strncasecmp(temp_host->display_name,host_name,strlen(host_name))){ 00340 free(host_name); 00341 host_name=strdup(temp_host->name); 00342 break; 00343 } 00344 } 00345 } 00346 } 00347 /* if host has no services attached, show host status detail */ 00348 if(temp_host!=NULL){ 00349 for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ 00350 if(!strcmp(temp_servicestatus->host_name,temp_host->name)) { 00351 host_has_no_service=FALSE; 00352 break; 00353 } 00354 } 00355 if(host_has_no_service) 00356 group_style_type=STYLE_HOST_DETAIL; 00357 } 00358 /* last effort, search hostgroups then servicegroups */ 00359 if(temp_host==NULL){ 00360 if((temp_hostgroup=find_hostgroup(host_name))!=NULL){ 00361 display_type=DISPLAY_HOSTGROUPS; 00362 show_all_hostgroups=FALSE; 00363 free(host_name); 00364 hostgroup_name=strdup(temp_hostgroup->group_name); 00365 } 00366 else if((temp_servicegroup=find_servicegroup(host_name))!=NULL){ 00367 display_type=DISPLAY_SERVICEGROUPS; 00368 show_all_servicegroups=FALSE; 00369 free(host_name); 00370 servicegroup_name=strdup(temp_servicegroup->group_name); 00371 } 00372 } 00373 } 00374 } 00375 00376 if(display_header==TRUE){ 00377 00378 /* begin top table */ 00379 /* network status, hosts/service status totals */ 00380 00381 printf("<table border=0 width=100%% cellspacing=0 cellpadding=0>\n"); 00382 printf("<tr>\n"); 00383 00384 /* left column of the first row */ 00385 printf("<td align=left valign=top width=33%%>\n"); 00386 /* info table */ 00387 display_info_table("Current Network Status",refresh,¤t_authdata, daemon_check); 00388 printf("</td>\n"); 00389 00390 /* middle column of top row */ 00391 printf("<td align=center valign=top width=33%%>\n"); 00392 show_host_status_totals(); 00393 printf("</td>\n"); 00394 00395 /* right hand column of top row */ 00396 printf("<td align=center valign=top width=33%%>\n"); 00397 show_service_status_totals(); 00398 printf("</td>\n"); 00399 00400 /* display context-sensitive help */ 00401 printf("<td align=right valign=bottom>\n"); 00402 if(display_type==DISPLAY_HOSTS) 00403 if(group_style_type==STYLE_HOST_DETAIL) 00404 display_context_help(CONTEXTHELP_STATUS_HOST_DETAIL); 00405 else 00406 display_context_help(CONTEXTHELP_STATUS_DETAIL); 00407 else if(display_type==DISPLAY_SERVICEGROUPS){ 00408 if(group_style_type==STYLE_HOST_DETAIL) 00409 display_context_help(CONTEXTHELP_STATUS_DETAIL); 00410 else if(group_style_type==STYLE_OVERVIEW) 00411 display_context_help(CONTEXTHELP_STATUS_SGOVERVIEW); 00412 else if(group_style_type==STYLE_SUMMARY) 00413 display_context_help(CONTEXTHELP_STATUS_SGSUMMARY); 00414 else if(group_style_type==STYLE_GRID) 00415 display_context_help(CONTEXTHELP_STATUS_SGGRID); 00416 }else{ 00417 if(group_style_type==STYLE_HOST_DETAIL) 00418 display_context_help(CONTEXTHELP_STATUS_HOST_DETAIL); 00419 else if(group_style_type==STYLE_OVERVIEW) 00420 display_context_help(CONTEXTHELP_STATUS_HGOVERVIEW); 00421 else if(group_style_type==STYLE_SUMMARY) 00422 display_context_help(CONTEXTHELP_STATUS_HGSUMMARY); 00423 else if(group_style_type==STYLE_GRID) 00424 display_context_help(CONTEXTHELP_STATUS_HGGRID); 00425 } 00426 printf("</td>\n"); 00427 printf("</tr>\n"); 00428 printf("</table>\n"); 00429 00430 /* second table below */ 00431 printf("<br>\n"); 00432 /* Links & Commands */ 00433 00434 printf("<table border=0 width=100%% cellspacing=0 cellpadding=0>\n"); 00435 printf("<tr>\n"); 00436 00437 /* left column of the first row */ 00438 printf("<td align=left valign=top width=50%%>\n"); 00439 00440 printf("<table border=1 cellpading=0 cellspacing=0 class='linkBox'>\n"); 00441 printf("<tr><td class='linkBox'>\n"); 00442 00443 if(display_type==DISPLAY_HOSTS){ 00444 printf("<a href='%s?host=%s'>View History For %s</a><br>\n",HISTORY_CGI,(show_all_hosts==TRUE)?"all":url_encode(host_name),(show_all_hosts==TRUE)?"all hosts":"This Host"); 00445 printf("<a href='%s?host=%s'>View Notifications For %s</a>\n",NOTIFICATIONS_CGI,(show_all_hosts==TRUE)?"all":url_encode(host_name),(show_all_hosts==TRUE)?"All Hosts":"This Host"); 00446 if(show_all_hosts==FALSE) 00447 printf("<br><a href='%s?host=all'>View Service Status Detail For All Hosts</a>\n",STATUS_CGI); 00448 else 00449 printf("<br><a href='%s?hostgroup=all&style=hostdetail'>View Host Status Detail For All Hosts</a>\n",STATUS_CGI); 00450 } 00451 else if(display_type==DISPLAY_SERVICEGROUPS){ 00452 if(show_all_servicegroups==FALSE){ 00453 00454 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY) 00455 printf("<a href='%s?servicegroup=%s&style=detail'>View Service Status Detail For This Service Group</a><br>\n",STATUS_CGI,url_encode(servicegroup_name)); 00456 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY) 00457 printf("<a href='%s?servicegroup=%s&style=overview'>View Status Overview For This Service Group</a><br>\n",STATUS_CGI,url_encode(servicegroup_name)); 00458 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID) 00459 printf("<a href='%s?servicegroup=%s&style=summary'>View Status Summary For This Service Group</a><br>\n",STATUS_CGI,url_encode(servicegroup_name)); 00460 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY) 00461 printf("<a href='%s?servicegroup=%s&style=grid'>View Service Status Grid For This Service Group</a><br>\n",STATUS_CGI,url_encode(servicegroup_name)); 00462 00463 if(group_style_type==STYLE_SERVICE_DETAIL) 00464 printf("<a href='%s?servicegroup=all&style=detail'>View Service Status Detail For All Service Groups</a><br>\n",STATUS_CGI); 00465 if(group_style_type==STYLE_OVERVIEW) 00466 printf("<a href='%s?servicegroup=all&style=overview'>View Status Overview For All Service Groups</a><br>\n",STATUS_CGI); 00467 if(group_style_type==STYLE_SUMMARY) 00468 printf("<a href='%s?servicegroup=all&style=summary'>View Status Summary For All Service Groups</a><br>\n",STATUS_CGI); 00469 if(group_style_type==STYLE_GRID) 00470 printf("<a href='%s?servicegroup=all&style=grid'>View Service Status Grid For All Service Groups</a><br>\n",STATUS_CGI); 00471 00472 }else{ 00473 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY) 00474 printf("<a href='%s?servicegroup=all&style=detail'>View Service Status Detail For All Service Groups</a><br>\n",STATUS_CGI); 00475 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_SUMMARY) 00476 printf("<a href='%s?servicegroup=all&style=overview'>View Status Overview For All Service Groups</a><br>\n",STATUS_CGI); 00477 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_GRID) 00478 printf("<a href='%s?servicegroup=all&style=summary'>View Status Summary For All Service Groups</a><br>\n",STATUS_CGI); 00479 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY) 00480 printf("<a href='%s?servicegroup=all&style=grid'>View Service Status Grid For All Service Groups</a><br>\n",STATUS_CGI); 00481 } 00482 00483 }else{ 00484 if(show_all_hostgroups==FALSE){ 00485 00486 if(group_style_type==STYLE_SERVICE_DETAIL) 00487 printf("<a href='%s?hostgroup=all&style=detail'>View Service Status Detail For All Host Groups</a><br>\n",STATUS_CGI); 00488 if(group_style_type==STYLE_HOST_DETAIL) 00489 printf("<a href='%s?hostgroup=all&style=hostdetail'>View Host Status Detail For All Host Groups</a><br>\n",STATUS_CGI); 00490 if(group_style_type==STYLE_OVERVIEW) 00491 printf("<a href='%s?hostgroup=all&style=overview'>View Status Overview For All Host Groups</a><br>\n",STATUS_CGI); 00492 if(group_style_type==STYLE_SUMMARY) 00493 printf("<a href='%s?hostgroup=all&style=summary'>View Status Summary For All Host Groups</a><br>\n",STATUS_CGI); 00494 if(group_style_type==STYLE_GRID) 00495 printf("<a href='%s?hostgroup=all&style=grid'>View Status Grid For All Host Groups</a><br>\n",STATUS_CGI); 00496 00497 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL) 00498 printf("<a href='%s?hostgroup=%s&style=detail'>View Service Status Detail For This Host Group</a><br>\n",STATUS_CGI,url_encode(hostgroup_name)); 00499 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID) 00500 printf("<a href='%s?hostgroup=%s&style=hostdetail'>View Host Status Detail For This Host Group</a><br>\n",STATUS_CGI,url_encode(hostgroup_name)); 00501 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL) 00502 printf("<a href='%s?hostgroup=%s&style=overview'>View Status Overview For This Host Group</a><br>\n",STATUS_CGI,url_encode(hostgroup_name)); 00503 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL) 00504 printf("<a href='%s?hostgroup=%s&style=summary'>View Status Summary For This Host Group</a><br>\n",STATUS_CGI,url_encode(hostgroup_name)); 00505 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_HOST_DETAIL) 00506 printf("<a href='%s?hostgroup=%s&style=grid'>View Status Grid For This Host Group</a><br>\n",STATUS_CGI,url_encode(hostgroup_name)); 00507 }else{ 00508 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL) 00509 printf("<a href='%s?hostgroup=all&style=detail'>View Service Status Detail For All Host Groups</a><br>\n",STATUS_CGI); 00510 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID) 00511 printf("<a href='%s?hostgroup=all&style=hostdetail'>View Host Status Detail For All Host Groups</a><br>\n",STATUS_CGI); 00512 if(group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL) 00513 printf("<a href='%s?hostgroup=all&style=overview'>View Status Overview For All Host Groups</a><br>\n",STATUS_CGI); 00514 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_GRID || group_style_type==STYLE_HOST_DETAIL) 00515 printf("<a href='%s?hostgroup=all&style=summary'>View Status Summary For All Host Groups</a><br>\n",STATUS_CGI); 00516 if(group_style_type==STYLE_OVERVIEW || group_style_type==STYLE_SERVICE_DETAIL || group_style_type==STYLE_SUMMARY || group_style_type==STYLE_HOST_DETAIL) 00517 printf("<a href='%s?hostgroup=all&style=grid'>View Status Grid For All Host Groups</a><br>\n",STATUS_CGI); 00518 } 00519 } 00520 00521 printf("</td></tr>\n"); 00522 printf("</table>\n"); 00523 00524 printf("</td>\n"); 00525 00526 /* Command table */ 00527 printf("<td align=right width=50%%>\n"); 00528 if(display_type==DISPLAY_HOSTS) { 00529 if(group_style_type==STYLE_HOST_DETAIL) 00530 show_hostcommand_table(); 00531 else 00532 show_servicecommand_table(); 00533 } 00534 else if(display_type==DISPLAY_SERVICEGROUPS){ 00535 if(group_style_type==STYLE_HOST_DETAIL) 00536 show_servicecommand_table(); 00537 else if(group_style_type==STYLE_OVERVIEW) 00538 printf("<br>"); 00539 else if(group_style_type==STYLE_SUMMARY) 00540 printf("<br>"); 00541 else if(group_style_type==STYLE_GRID) 00542 printf("<br>"); 00543 else 00544 show_servicecommand_table(); 00545 }else{ 00546 if(group_style_type==STYLE_HOST_DETAIL) 00547 show_hostcommand_table(); 00548 else if(group_style_type==STYLE_OVERVIEW) 00549 printf("<br>"); 00550 else if(group_style_type==STYLE_SUMMARY) 00551 printf("<br>"); 00552 else if(group_style_type==STYLE_GRID) 00553 printf("<br>"); 00554 else 00555 show_servicecommand_table(); 00556 } 00557 printf("</td>\n"); 00558 printf("</tr>\n"); 00559 00560 /* end of second table */ 00561 printf("</table>\n"); 00562 } 00563 00564 00565 /* embed sound tag if necessary... */ 00566 if(problem_hosts_unreachable>0 && host_unreachable_sound!=NULL) 00567 sound=host_unreachable_sound; 00568 else if(problem_hosts_down>0 && host_down_sound!=NULL) 00569 sound=host_down_sound; 00570 else if(problem_services_critical>0 && service_critical_sound!=NULL) 00571 sound=service_critical_sound; 00572 else if(problem_services_warning>0 && service_warning_sound!=NULL) 00573 sound=service_warning_sound; 00574 else if(problem_services_unknown>0 && service_unknown_sound!=NULL) 00575 sound=service_unknown_sound; 00576 else if(problem_services_unknown==0 && problem_services_warning==0 && problem_services_critical==0 && problem_hosts_down==0 && problem_hosts_unreachable==0 && normal_sound!=NULL) 00577 sound=normal_sound; 00578 if(sound!=NULL){ 00579 printf("<object type=\"audio/x-wav\" data=\"%s%s\" height=\"0\" width=\"0\">",url_media_path,sound); 00580 printf("<param name=\"filename\" value=\"%s%s\">",url_media_path,sound); 00581 printf("<param name=\"autostart\" value=\"true\">"); 00582 printf("<param name=\"playcount\" value=\"1\">"); 00583 printf("</object>"); 00584 } 00585 00586 00587 // flush the data we allready have 00588 printf(" "); 00589 fflush(NULL); 00590 00591 /* bottom portion of screen - service or hostgroup detail */ 00592 if(display_type==DISPLAY_HOSTS) { 00593 if(group_style_type==STYLE_HOST_DETAIL) 00594 show_host_detail(); 00595 else 00596 show_service_detail(); 00597 } 00598 else if(display_type==DISPLAY_SERVICEGROUPS){ 00599 if(group_style_type==STYLE_OVERVIEW) 00600 show_servicegroup_overviews(); 00601 else if(group_style_type==STYLE_SUMMARY) 00602 show_servicegroup_summaries(); 00603 else if(group_style_type==STYLE_GRID) 00604 show_servicegroup_grids(); 00605 else if(group_style_type==STYLE_HOST_DETAIL) 00606 show_host_detail(); 00607 else 00608 show_service_detail(); 00609 }else{ 00610 if(group_style_type==STYLE_OVERVIEW) 00611 show_hostgroup_overviews(); 00612 else if(group_style_type==STYLE_SUMMARY) 00613 show_hostgroup_summaries(); 00614 else if(group_style_type==STYLE_GRID) 00615 show_hostgroup_grids(); 00616 else if(group_style_type==STYLE_HOST_DETAIL) 00617 show_host_detail(); 00618 else 00619 show_service_detail(); 00620 } 00621 00622 document_footer(CGI_ID); 00623 00624 /* free all allocated memory */ 00625 free_memory(); 00626 free_comment_data(); 00627 00628 /* free memory allocated to the sort lists */ 00629 free_sort_list(); 00630 free_status_data(); 00631 00632 return OK; 00633 } 00634 00635 int process_cgivars(void){ 00636 char **variables; 00637 int error=FALSE; 00638 int x; 00639 00640 variables=getcgivars(); 00641 00642 for(x=0;variables[x]!=NULL;x++){ 00643 00644 /* do some basic length checking on the variable identifier to prevent buffer overflows */ 00645 if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){ 00646 x++; 00647 continue; 00648 } 00649 00650 /* we found the navbar search argument */ 00651 else if(!strcmp(variables[x],"navbarsearch")){ 00652 x++; 00653 if(variables[x]==NULL){ 00654 error=TRUE; 00655 break; 00656 } 00657 navbar_search=TRUE; 00658 } 00659 00660 /* we found the hostgroup argument */ 00661 else if(!strcmp(variables[x],"hostgroup")){ 00662 display_type=DISPLAY_HOSTGROUPS; 00663 x++; 00664 if(variables[x]==NULL){ 00665 error=TRUE; 00666 break; 00667 } 00668 00669 hostgroup_name=(char *)strdup(variables[x]); 00670 strip_html_brackets(hostgroup_name); 00671 00672 if(hostgroup_name!=NULL && !strcmp(hostgroup_name,"all")) 00673 show_all_hostgroups=TRUE; 00674 else 00675 show_all_hostgroups=FALSE; 00676 } 00677 00678 /* we found the servicegroup argument */ 00679 else if(!strcmp(variables[x],"servicegroup")){ 00680 display_type=DISPLAY_SERVICEGROUPS; 00681 x++; 00682 if(variables[x]==NULL){ 00683 error=TRUE; 00684 break; 00685 } 00686 00687 servicegroup_name=strdup(variables[x]); 00688 strip_html_brackets(servicegroup_name); 00689 00690 if(servicegroup_name!=NULL && !strcmp(servicegroup_name,"all")) 00691 show_all_servicegroups=TRUE; 00692 else 00693 show_all_servicegroups=FALSE; 00694 } 00695 00696 /* we found the host argument */ 00697 else if(!strcmp(variables[x],"host")){ 00698 display_type=DISPLAY_HOSTS; 00699 x++; 00700 if(variables[x]==NULL){ 00701 error=TRUE; 00702 break; 00703 } 00704 00705 host_name=strdup(variables[x]); 00706 strip_html_brackets(host_name); 00707 00708 if(host_name!=NULL && !strcmp(host_name,"all")) 00709 show_all_hosts=TRUE; 00710 else 00711 show_all_hosts=FALSE; 00712 } 00713 00714 /* we found the columns argument */ 00715 else if(!strcmp(variables[x],"columns")){ 00716 x++; 00717 if(variables[x]==NULL){ 00718 error=TRUE; 00719 break; 00720 } 00721 00722 overview_columns=atoi(variables[x]); 00723 if(overview_columns<=0) 00724 overview_columns=1; 00725 } 00726 00727 /* we found the service status type argument */ 00728 else if(!strcmp(variables[x],"servicestatustypes")){ 00729 x++; 00730 if(variables[x]==NULL){ 00731 error=TRUE; 00732 break; 00733 } 00734 00735 service_status_types=atoi(variables[x]); 00736 } 00737 00738 /* we found the host status type argument */ 00739 else if(!strcmp(variables[x],"hoststatustypes")){ 00740 x++; 00741 if(variables[x]==NULL){ 00742 error=TRUE; 00743 break; 00744 } 00745 00746 host_status_types=atoi(variables[x]); 00747 } 00748 00749 /* we found the service properties argument */ 00750 else if(!strcmp(variables[x],"serviceprops")){ 00751 x++; 00752 if(variables[x]==NULL){ 00753 error=TRUE; 00754 break; 00755 } 00756 00757 service_properties=strtoul(variables[x],NULL,10); 00758 } 00759 00760 /* we found the host properties argument */ 00761 else if(!strcmp(variables[x],"hostprops")){ 00762 x++; 00763 if(variables[x]==NULL){ 00764 error=TRUE; 00765 break; 00766 } 00767 00768 host_properties=strtoul(variables[x],NULL,10); 00769 } 00770 00771 /* we found the host or service group style argument */ 00772 else if(!strcmp(variables[x],"style")){ 00773 x++; 00774 if(variables[x]==NULL){ 00775 error=TRUE; 00776 break; 00777 } 00778 00779 if(!strcmp(variables[x],"overview")) 00780 group_style_type=STYLE_OVERVIEW; 00781 else if(!strcmp(variables[x],"detail")) 00782 group_style_type=STYLE_SERVICE_DETAIL; 00783 else if(!strcmp(variables[x],"summary")) 00784 group_style_type=STYLE_SUMMARY; 00785 else if(!strcmp(variables[x],"grid")) 00786 group_style_type=STYLE_GRID; 00787 else if(!strcmp(variables[x],"hostdetail")) 00788 group_style_type=STYLE_HOST_DETAIL; 00789 else 00790 group_style_type=STYLE_SERVICE_DETAIL; 00791 } 00792 00793 /* we found the sort type argument */ 00794 else if(!strcmp(variables[x],"sorttype")){ 00795 x++; 00796 if(variables[x]==NULL){ 00797 error=TRUE; 00798 break; 00799 } 00800 00801 sort_type=atoi(variables[x]); 00802 } 00803 00804 /* we found the sort option argument */ 00805 else if(!strcmp(variables[x],"sortoption")){ 00806 x++; 00807 if(variables[x]==NULL){ 00808 error=TRUE; 00809 break; 00810 } 00811 00812 sort_option=atoi(variables[x]); 00813 } 00814 00815 /* we found the embed option */ 00816 else if(!strcmp(variables[x],"embedded")) 00817 embedded=TRUE; 00818 00819 /* we found the noheader option */ 00820 else if(!strcmp(variables[x],"noheader")) 00821 display_header=FALSE; 00822 00823 /* we found the CSV output option */ 00824 else if(!strcmp(variables[x],"csvoutput")){ 00825 display_header=FALSE; 00826 content_type=CSV_CONTENT; 00827 } 00828 00829 /* we found the JSON output option */ 00830 else if(!strcmp(variables[x],"jsonoutput")){ 00831 display_header=FALSE; 00832 content_type=JSON_CONTENT; 00833 } 00834 00835 /* we found the pause option */ 00836 else if(!strcmp(variables[x],"paused")) 00837 refresh=FALSE; 00838 00839 /* we found the nodaemoncheck option */ 00840 else if(!strcmp(variables[x],"nodaemoncheck")) 00841 daemon_check=FALSE; 00842 00843 /* servicefilter cgi var */ 00844 else if(!strcmp(variables[x],"servicefilter")){ 00845 x++; 00846 if(variables[x]==NULL){ 00847 error=TRUE; 00848 break; 00849 } 00850 service_filter=strdup(variables[x]); 00851 strip_html_brackets(service_filter); 00852 } 00853 } 00854 00855 /* free memory allocated to the CGI variables */ 00856 free_cgivars(variables); 00857 00858 return error; 00859 } 00860 00861 00862 /* display table with service status totals... */ 00863 void show_service_status_totals(void){ 00864 int total_ok=0; 00865 int total_warning=0; 00866 int total_unknown=0; 00867 int total_critical=0; 00868 int total_pending=0; 00869 int total_services=0; 00870 int total_problems=0; 00871 servicestatus *temp_servicestatus; 00872 service *temp_service; 00873 host *temp_host; 00874 hoststatus *temp_hoststatus; 00875 int count_service; 00876 00877 00878 /* check the status of all services... */ 00879 for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ 00880 00881 /* find the host and service... */ 00882 temp_host=find_host(temp_servicestatus->host_name); 00883 00884 /* only get count services from hosts witch fit into filter specified */ 00885 temp_hoststatus=find_hoststatus(temp_host->name); 00886 if (!(host_status_types & temp_hoststatus->status )) 00887 continue; 00888 00889 temp_service=find_service(temp_servicestatus->host_name,temp_servicestatus->description); 00890 00891 /* make sure user has rights to see this service... */ 00892 if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) 00893 continue; 00894 00895 count_service=FALSE; 00896 00897 if(display_type==DISPLAY_HOSTS && (show_all_hosts==TRUE || !strcmp(host_name,temp_servicestatus->host_name))) 00898 count_service=TRUE; 00899 else if(display_type==DISPLAY_SERVICEGROUPS && (show_all_servicegroups==TRUE || (is_service_member_of_servicegroup(find_servicegroup(servicegroup_name),temp_service)==TRUE))) 00900 count_service=TRUE; 00901 else if(display_type==DISPLAY_HOSTGROUPS && (show_all_hostgroups==TRUE || (is_host_member_of_hostgroup(find_hostgroup(hostgroup_name),temp_host)==TRUE))) 00902 count_service=TRUE; 00903 00904 if(count_service){ 00905 00906 if(temp_servicestatus->status==SERVICE_CRITICAL){ 00907 total_critical++; 00908 if(temp_servicestatus->problem_has_been_acknowledged==FALSE && (temp_servicestatus->checks_enabled==TRUE || temp_servicestatus->accept_passive_service_checks==TRUE) && temp_servicestatus->notifications_enabled==TRUE && temp_servicestatus->scheduled_downtime_depth==0) 00909 problem_services_critical++; 00910 } 00911 else if(temp_servicestatus->status==SERVICE_WARNING){ 00912 total_warning++; 00913 if(temp_servicestatus->problem_has_been_acknowledged==FALSE && (temp_servicestatus->checks_enabled==TRUE || temp_servicestatus->accept_passive_service_checks==TRUE) && temp_servicestatus->notifications_enabled==TRUE && temp_servicestatus->scheduled_downtime_depth==0) 00914 problem_services_warning++; 00915 } 00916 else if(temp_servicestatus->status==SERVICE_UNKNOWN){ 00917 total_unknown++; 00918 if(temp_servicestatus->problem_has_been_acknowledged==FALSE && (temp_servicestatus->checks_enabled==TRUE || temp_servicestatus->accept_passive_service_checks==TRUE) && temp_servicestatus->notifications_enabled==TRUE && temp_servicestatus->scheduled_downtime_depth==0) 00919 problem_services_unknown++; 00920 } 00921 else if(temp_servicestatus->status==SERVICE_OK) 00922 total_ok++; 00923 else if(temp_servicestatus->status==SERVICE_PENDING) 00924 total_pending++; 00925 else 00926 total_ok++; 00927 } 00928 } 00929 00930 total_services=total_ok+total_unknown+total_warning+total_critical+total_pending; 00931 total_problems=total_unknown+total_warning+total_critical; 00932 00933 00934 printf("<DIV CLASS='serviceTotals'>Service Status Totals</DIV>\n"); 00935 00936 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>\n"); 00937 printf("<TR><TD>\n"); 00938 00939 printf("<TABLE BORDER=1 CLASS='serviceTotals'>\n"); 00940 printf("<TR>\n"); 00941 00942 printf("<TH CLASS='serviceTotals'>"); 00943 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 00944 if(display_type==DISPLAY_HOSTS) 00945 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 00946 else if(display_type==DISPLAY_SERVICEGROUPS) 00947 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 00948 else 00949 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 00950 printf("&servicestatustypes=%d",SERVICE_OK); 00951 printf("&hoststatustypes=%d'>",host_status_types); 00952 printf("Ok</A></TH>\n"); 00953 00954 printf("<TH CLASS='serviceTotals'>"); 00955 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 00956 if(display_type==DISPLAY_HOSTS) 00957 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 00958 else if(display_type==DISPLAY_SERVICEGROUPS) 00959 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 00960 else 00961 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 00962 printf("&servicestatustypes=%d",SERVICE_WARNING); 00963 printf("&hoststatustypes=%d'>",host_status_types); 00964 printf("Warning</A></TH>\n"); 00965 00966 printf("<TH CLASS='serviceTotals'>"); 00967 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 00968 if(display_type==DISPLAY_HOSTS) 00969 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 00970 else if(display_type==DISPLAY_SERVICEGROUPS) 00971 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 00972 else 00973 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 00974 printf("&servicestatustypes=%d",SERVICE_UNKNOWN); 00975 printf("&hoststatustypes=%d'>",host_status_types); 00976 printf("Unknown</A></TH>\n"); 00977 00978 printf("<TH CLASS='serviceTotals'>"); 00979 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 00980 if(display_type==DISPLAY_HOSTS) 00981 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 00982 else if(display_type==DISPLAY_SERVICEGROUPS) 00983 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 00984 else 00985 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 00986 printf("&servicestatustypes=%d",SERVICE_CRITICAL); 00987 printf("&hoststatustypes=%d'>",host_status_types); 00988 printf("Critical</A></TH>\n"); 00989 00990 printf("<TH CLASS='serviceTotals'>"); 00991 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 00992 if(display_type==DISPLAY_HOSTS) 00993 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 00994 else if(display_type==DISPLAY_SERVICEGROUPS) 00995 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 00996 else 00997 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 00998 printf("&servicestatustypes=%d",SERVICE_PENDING); 00999 printf("&hoststatustypes=%d'>",host_status_types); 01000 printf("Pending</A></TH>\n"); 01001 01002 printf("</TR>\n"); 01003 01004 printf("<TR>\n"); 01005 01006 01007 /* total services ok */ 01008 printf("<TD CLASS='serviceTotals%s'>%d</TD>\n",(total_ok>0)?"OK":"",total_ok); 01009 01010 /* total services in warning state */ 01011 printf("<TD CLASS='serviceTotals%s'>%d</TD>\n",(total_warning>0)?"WARNING":"",total_warning); 01012 01013 /* total services in unknown state */ 01014 printf("<TD CLASS='serviceTotals%s'>%d</TD>\n",(total_unknown>0)?"UNKNOWN":"",total_unknown); 01015 01016 /* total services in critical state */ 01017 printf("<TD CLASS='serviceTotals%s'>%d</TD>\n",(total_critical>0)?"CRITICAL":"",total_critical); 01018 01019 /* total services in pending state */ 01020 printf("<TD CLASS='serviceTotals%s'>%d</TD>\n",(total_pending>0)?"PENDING":"",total_pending); 01021 01022 01023 printf("</TR>\n"); 01024 printf("</TABLE>\n"); 01025 01026 printf("</TD></TR><TR><TD ALIGN=CENTER>\n"); 01027 01028 printf("<TABLE BORDER=1 CLASS='serviceTotals'>\n"); 01029 printf("<TR>\n"); 01030 01031 printf("<TH CLASS='serviceTotals'>"); 01032 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 01033 if(display_type==DISPLAY_HOSTS) 01034 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01035 else if(display_type==DISPLAY_SERVICEGROUPS) 01036 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 01037 else 01038 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 01039 printf("&servicestatustypes=%d",SERVICE_UNKNOWN|SERVICE_WARNING|SERVICE_CRITICAL); 01040 printf("&hoststatustypes=%d'>",host_status_types); 01041 printf("<I>All Problems</I></A></TH>\n"); 01042 01043 printf("<TH CLASS='serviceTotals'>"); 01044 printf("<A CLASS='serviceTotals' HREF='%s?",STATUS_CGI); 01045 if(display_type==DISPLAY_HOSTS) 01046 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01047 else if(display_type==DISPLAY_SERVICEGROUPS) 01048 printf("servicegroup=%s&style=detail",url_encode(servicegroup_name)); 01049 else 01050 printf("hostgroup=%s&style=detail",url_encode(hostgroup_name)); 01051 printf("&hoststatustypes=%d'>",host_status_types); 01052 printf("<I>All Types</I></A></TH>\n"); 01053 01054 01055 printf("</TR><TR>\n"); 01056 01057 /* total service problems */ 01058 printf("<TD CLASS='serviceTotals%s'>%d</TD>\n",(total_problems>0)?"PROBLEMS":"",total_problems); 01059 01060 /* total services */ 01061 printf("<TD CLASS='serviceTotals'>%d</TD>\n",total_services); 01062 01063 printf("</TR>\n"); 01064 printf("</TABLE>\n"); 01065 01066 printf("</TD></TR>\n"); 01067 printf("</TABLE>\n"); 01068 01069 return; 01070 } 01071 01072 01073 /* display a table with host status totals... */ 01074 void show_host_status_totals(void){ 01075 int total_up=0; 01076 int total_down=0; 01077 int total_unreachable=0; 01078 int total_pending=0; 01079 int total_hosts=0; 01080 int total_problems=0; 01081 hoststatus *temp_hoststatus; 01082 host *temp_host; 01083 servicestatus *temp_servicestatus; 01084 int count_host; 01085 int host_has_service; 01086 01087 01088 /* check the status of all hosts... */ 01089 for(temp_hoststatus=hoststatus_list;temp_hoststatus!=NULL;temp_hoststatus=temp_hoststatus->next){ 01090 01091 /* find the host... */ 01092 temp_host=find_host(temp_hoststatus->host_name); 01093 01094 /* Skip hosts with no serivces attached in service detail view */ 01095 if (group_style_type==STYLE_SERVICE_DETAIL) { 01096 host_has_service=FALSE; 01097 for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ 01098 if (!strcmp(temp_host->name,temp_servicestatus->host_name)) { 01099 host_has_service=TRUE; 01100 break; 01101 } 01102 } 01103 if (host_has_service==FALSE) 01104 continue; 01105 } 01106 01107 /* make sure user has rights to view this host */ 01108 if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 01109 continue; 01110 01111 count_host=0; 01112 01113 if(display_type==DISPLAY_HOSTS && (show_all_hosts==TRUE || !strcmp(host_name,temp_hoststatus->host_name))) 01114 count_host=1; 01115 01116 else if(display_type==DISPLAY_SERVICEGROUPS){ 01117 01118 if(show_all_servicegroups==TRUE) { 01119 count_host=1; 01120 } else if(is_host_member_of_servicegroup(find_servicegroup(servicegroup_name),temp_host)==TRUE){ 01121 count_host=1; 01122 } 01123 } 01124 else if(display_type==DISPLAY_HOSTGROUPS && (show_all_hostgroups==TRUE || (is_host_member_of_hostgroup(find_hostgroup(hostgroup_name),temp_host)==TRUE))) 01125 count_host=1; 01126 01127 if(count_host){ 01128 01129 if(temp_hoststatus->status==HOST_UP) 01130 total_up++; 01131 01132 else if(temp_hoststatus->status==HOST_DOWN){ 01133 total_down++; 01134 01135 if(temp_hoststatus->problem_has_been_acknowledged==FALSE && temp_hoststatus->notifications_enabled==TRUE && temp_hoststatus->checks_enabled==TRUE && temp_hoststatus->scheduled_downtime_depth==0) 01136 problem_hosts_down++; 01137 } 01138 else if(temp_hoststatus->status==HOST_UNREACHABLE){ 01139 total_unreachable++; 01140 if(temp_hoststatus->problem_has_been_acknowledged==FALSE && temp_hoststatus->notifications_enabled==TRUE && temp_hoststatus->checks_enabled==TRUE && temp_hoststatus->scheduled_downtime_depth==0) 01141 problem_hosts_unreachable++; 01142 } 01143 01144 else if(temp_hoststatus->status==HOST_PENDING) 01145 total_pending++; 01146 else 01147 total_up++; 01148 } 01149 } 01150 01151 total_hosts=total_up+total_down+total_unreachable+total_pending; 01152 total_problems=total_down+total_unreachable; 01153 01154 printf("<DIV CLASS='hostTotals'>Host Status Totals</DIV>\n"); 01155 01156 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>\n"); 01157 printf("<TR><TD>\n"); 01158 01159 01160 printf("<TABLE BORDER=1 CLASS='hostTotals'>\n"); 01161 printf("<TR>\n"); 01162 01163 printf("<TH CLASS='hostTotals'>"); 01164 printf("<A CLASS='hostTotals' HREF='%s?",STATUS_CGI); 01165 if(display_type==DISPLAY_HOSTS) 01166 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01167 else if(display_type==DISPLAY_SERVICEGROUPS) 01168 printf("servicegroup=%s",url_encode(servicegroup_name)); 01169 else{ 01170 printf("hostgroup=%s",url_encode(hostgroup_name)); 01171 if((service_status_types!=all_service_status_types) || group_style_type==STYLE_SERVICE_DETAIL) 01172 printf("&style=detail"); 01173 else if(group_style_type==STYLE_HOST_DETAIL) 01174 printf("&style=hostdetail"); 01175 } 01176 if(service_status_types!=all_service_status_types) 01177 printf("&servicestatustypes=%d",service_status_types); 01178 printf("&hoststatustypes=%d'>",HOST_UP); 01179 printf("Up</A></TH>\n"); 01180 01181 printf("<TH CLASS='hostTotals'>"); 01182 printf("<A CLASS='hostTotals' HREF='%s?",STATUS_CGI); 01183 if(display_type==DISPLAY_HOSTS) 01184 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01185 else if(display_type==DISPLAY_SERVICEGROUPS) 01186 printf("servicegroup=%s",url_encode(servicegroup_name)); 01187 else{ 01188 printf("hostgroup=%s",url_encode(hostgroup_name)); 01189 if((service_status_types!=all_service_status_types) || group_style_type==STYLE_SERVICE_DETAIL) 01190 printf("&style=detail"); 01191 else if(group_style_type==STYLE_HOST_DETAIL) 01192 printf("&style=hostdetail"); 01193 } 01194 if(service_status_types!=all_service_status_types) 01195 printf("&servicestatustypes=%d",service_status_types); 01196 printf("&hoststatustypes=%d'>",HOST_DOWN); 01197 printf("Down</A></TH>\n"); 01198 01199 printf("<TH CLASS='hostTotals'>"); 01200 printf("<A CLASS='hostTotals' HREF='%s?",STATUS_CGI); 01201 if(display_type==DISPLAY_HOSTS) 01202 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01203 else if(display_type==DISPLAY_SERVICEGROUPS) 01204 printf("servicegroup=%s",url_encode(servicegroup_name)); 01205 else{ 01206 printf("hostgroup=%s",url_encode(hostgroup_name)); 01207 if((service_status_types!=all_service_status_types) || group_style_type==STYLE_SERVICE_DETAIL) 01208 printf("&style=detail"); 01209 else if(group_style_type==STYLE_HOST_DETAIL) 01210 printf("&style=hostdetail"); 01211 } 01212 if(service_status_types!=all_service_status_types) 01213 printf("&servicestatustypes=%d",service_status_types); 01214 printf("&hoststatustypes=%d'>",HOST_UNREACHABLE); 01215 printf("Unreachable</A></TH>\n"); 01216 01217 printf("<TH CLASS='hostTotals'>"); 01218 printf("<A CLASS='hostTotals' HREF='%s?",STATUS_CGI); 01219 if(display_type==DISPLAY_HOSTS) 01220 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01221 else if(display_type==DISPLAY_SERVICEGROUPS) 01222 printf("servicegroup=%s",url_encode(servicegroup_name)); 01223 else{ 01224 printf("hostgroup=%s",url_encode(hostgroup_name)); 01225 if((service_status_types!=all_service_status_types) || group_style_type==STYLE_SERVICE_DETAIL) 01226 printf("&style=detail"); 01227 else if(group_style_type==STYLE_HOST_DETAIL) 01228 printf("&style=hostdetail"); 01229 } 01230 if(service_status_types!=all_service_status_types) 01231 printf("&servicestatustypes=%d",service_status_types); 01232 printf("&hoststatustypes=%d'>",HOST_PENDING); 01233 printf("Pending</A></TH>\n"); 01234 01235 printf("</TR>\n"); 01236 01237 01238 printf("<TR>\n"); 01239 01240 /* total hosts up */ 01241 printf("<TD CLASS='hostTotals%s'>%d</TD>\n",(total_up>0)?"UP":"",total_up); 01242 01243 /* total hosts down */ 01244 printf("<TD CLASS='hostTotals%s'>%d</TD>\n",(total_down>0)?"DOWN":"",total_down); 01245 01246 /* total hosts unreachable */ 01247 printf("<TD CLASS='hostTotals%s'>%d</TD>\n",(total_unreachable>0)?"UNREACHABLE":"",total_unreachable); 01248 01249 /* total hosts pending */ 01250 printf("<TD CLASS='hostTotals%s'>%d</TD>\n",(total_pending>0)?"PENDING":"",total_pending); 01251 01252 printf("</TR>\n"); 01253 printf("</TABLE>\n"); 01254 01255 printf("</TD></TR><TR><TD ALIGN=CENTER>\n"); 01256 01257 printf("<TABLE BORDER=1 CLASS='hostTotals'>\n"); 01258 printf("<TR>\n"); 01259 01260 printf("<TH CLASS='hostTotals'>"); 01261 printf("<A CLASS='hostTotals' HREF='%s?",STATUS_CGI); 01262 if(display_type==DISPLAY_HOSTS) 01263 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01264 else if(display_type==DISPLAY_SERVICEGROUPS) 01265 printf("servicegroup=%s",url_encode(servicegroup_name)); 01266 else{ 01267 printf("hostgroup=%s",url_encode(hostgroup_name)); 01268 if((service_status_types!=all_service_status_types) || group_style_type==STYLE_SERVICE_DETAIL) 01269 printf("&style=detail"); 01270 else if(group_style_type==STYLE_HOST_DETAIL) 01271 printf("&style=hostdetail"); 01272 } 01273 if(service_status_types!=all_service_status_types) 01274 printf("&servicestatustypes=%d",service_status_types); 01275 printf("&hoststatustypes=%d'>",HOST_DOWN|HOST_UNREACHABLE); 01276 printf("<I>All Problems</I></A></TH>\n"); 01277 01278 printf("<TH CLASS='hostTotals'>"); 01279 printf("<A CLASS='hostTotals' HREF='%s?",STATUS_CGI); 01280 if(display_type==DISPLAY_HOSTS) 01281 printf("host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01282 else if(display_type==DISPLAY_SERVICEGROUPS) 01283 printf("servicegroup=%s",url_encode(servicegroup_name)); 01284 else{ 01285 printf("hostgroup=%s",url_encode(hostgroup_name)); 01286 if((service_status_types!=all_service_status_types) || group_style_type==STYLE_SERVICE_DETAIL) 01287 printf("&style=detail"); 01288 else if(group_style_type==STYLE_HOST_DETAIL) 01289 printf("&style=hostdetail"); 01290 } 01291 if(service_status_types!=all_service_status_types) 01292 printf("&servicestatustypes=%d",service_status_types); 01293 printf("'>"); 01294 printf("<I>All Types</I></A></TH>\n"); 01295 01296 printf("</TR><TR>\n"); 01297 01298 /* total hosts with problems */ 01299 printf("<TD CLASS='hostTotals%s'>%d</TD>\n",(total_problems>0)?"PROBLEMS":"",total_problems); 01300 01301 /* total hosts */ 01302 printf("<TD CLASS='hostTotals'>%d</TD>\n",total_hosts); 01303 01304 printf("</TR>\n"); 01305 printf("</TABLE>\n"); 01306 01307 printf("</TD></TR>\n"); 01308 printf("</TABLE>\n"); 01309 01310 return; 01311 } 01312 01313 01314 /* display a detailed listing of the status of all services... */ 01315 void show_service_detail(void){ 01316 char *status=NULL; 01317 char temp_buffer[MAX_INPUT_BUFFER]; 01318 char temp_url[MAX_INPUT_BUFFER]; 01319 char *processed_string=NULL; 01320 char *status_class=""; 01321 char *status_bg_class=""; 01322 char *host_status_bg_class=""; 01323 char *last_host=""; 01324 int new_host=FALSE; 01325 hoststatus *temp_hoststatus=NULL; 01326 host *temp_host=NULL; 01327 service *temp_service=NULL; 01328 int odd=0; 01329 int total_comments=0; 01330 sort *temp_sort=NULL; 01331 int use_sort=FALSE; 01332 int result=OK; 01333 int first_entry=TRUE; 01334 int total_entries=0; 01335 statusdata *temp_status=NULL; 01336 int json_start=TRUE; 01337 01338 /* grap requested data */ 01339 grab_statusdata(); 01340 01341 /* sort status data if necessary */ 01342 if(sort_type!=SORT_NONE){ 01343 result=sort_status_data(SERVICE_STATUS,sort_type,sort_option); 01344 if(result==ERROR) 01345 use_sort=FALSE; 01346 else 01347 use_sort=TRUE; 01348 } else 01349 use_sort=FALSE; 01350 01351 01352 if (content_type==HTML_CONTENT) { 01353 01354 printf("<P>\n"); 01355 01356 printf("<table border=0 width=100%%>\n"); 01357 printf("<tr>\n"); 01358 01359 printf("<td valign=top align=left width=33%%>\n"); 01360 01361 if(display_header==TRUE) 01362 show_filters(); 01363 01364 printf("</td>"); 01365 01366 printf("<td valign=top align=center width=33%%>\n"); 01367 01368 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Service Status Details For "); 01369 if(display_type==DISPLAY_HOSTS){ 01370 if(show_all_hosts==TRUE) 01371 printf("All Hosts"); 01372 else 01373 printf("Host '%s'",host_name); 01374 } 01375 else if(display_type==DISPLAY_SERVICEGROUPS){ 01376 if(show_all_servicegroups==TRUE) 01377 printf("All Service Groups"); 01378 else 01379 printf("Service Group '%s'",servicegroup_name); 01380 }else{ 01381 if(show_all_hostgroups==TRUE) 01382 printf("All Host Groups"); 01383 else 01384 printf("Host Group '%s'",hostgroup_name); 01385 } 01386 printf("</DIV>\n"); 01387 01388 if(use_sort==TRUE){ 01389 printf("<DIV ALIGN=CENTER CLASS='statusSort'>Entries sorted by <b>"); 01390 if(sort_option==SORT_HOSTNAME) 01391 printf("host name"); 01392 else if(sort_option==SORT_SERVICENAME) 01393 printf("service name"); 01394 else if(sort_option==SORT_SERVICESTATUS) 01395 printf("service status"); 01396 else if(sort_option==SORT_LASTCHECKTIME) 01397 printf("last check time"); 01398 else if(sort_option==SORT_CURRENTATTEMPT) 01399 printf("attempt number"); 01400 else if(sort_option==SORT_STATEDURATION) 01401 printf("state duration"); 01402 printf("</b> (%s)\n",(sort_type==SORT_ASCENDING)?"ascending":"descending"); 01403 printf("</DIV>\n"); 01404 } 01405 01406 if(service_filter!=NULL) 01407 printf("<DIV ALIGN=CENTER CLASS='statusSort'>Filtered By Services Matching \'%s\'</DIV>",service_filter); 01408 01409 printf("<br>"); 01410 01411 printf("</td>\n"); 01412 01413 /* add export to csv link */ 01414 printf("<td valign=bottom width=33%%><div class='csv_export_link'><a href='%s' target='_blank'>Export to CSV</a></div></td>\n",get_export_csv_link(STATUS_CGI)); 01415 01416 printf("</tr>\n"); 01417 printf("</table>\n"); 01418 } 01419 01420 01421 01422 01423 snprintf(temp_url,sizeof(temp_url)-1,"%s?",STATUS_CGI); 01424 temp_url[sizeof(temp_url)-1]='\x0'; 01425 if(display_type==DISPLAY_HOSTS) 01426 snprintf(temp_buffer,sizeof(temp_buffer)-1,"host=%s",(host_name==NULL)?"all":url_encode(host_name)); 01427 else if(display_type==DISPLAY_SERVICEGROUPS) 01428 snprintf(temp_buffer,sizeof(temp_buffer)-1,"servicegroup=%s&style=detail",url_encode(servicegroup_name)); 01429 else 01430 snprintf(temp_buffer,sizeof(temp_buffer)-1,"hostgroup=%s&style=detail",url_encode(hostgroup_name)); 01431 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01432 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01433 temp_url[sizeof(temp_url)-1]='\x0'; 01434 if(service_status_types!=all_service_status_types){ 01435 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&servicestatustypes=%d",service_status_types); 01436 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01437 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01438 temp_url[sizeof(temp_url)-1]='\x0'; 01439 } 01440 if(host_status_types!=all_host_status_types){ 01441 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&hoststatustypes=%d",host_status_types); 01442 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01443 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01444 temp_url[sizeof(temp_url)-1]='\x0'; 01445 } 01446 if(service_properties!=0){ 01447 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&serviceprops=%lu",service_properties); 01448 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01449 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01450 temp_url[sizeof(temp_url)-1]='\x0'; 01451 } 01452 if(host_properties!=0){ 01453 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&hostprops=%lu",host_properties); 01454 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01455 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01456 temp_url[sizeof(temp_url)-1]='\x0'; 01457 } 01458 01459 if(content_type==JSON_CONTENT) 01460 printf("\"service_status\": [\n"); 01461 else if(content_type==CSV_CONTENT) { 01462 printf("%sHost%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01463 printf("%sService%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01464 printf("%sStatus%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01465 printf("%sLast_Check%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01466 printf("%sDuration%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01467 printf("%sAttempt%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01468 printf("%sStatus_Information%s\n",csv_data_enclosure,csv_data_enclosure); 01469 } else { 01470 /* the main list of services */ 01471 printf("<DIV ALIGN='center'>\n"); 01472 printf("<TABLE BORDER=0 width=100%% CLASS='status'>\n"); 01473 printf("<TR>\n"); 01474 01475 printf("<TH CLASS='status'>Host <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (ascending)' TITLE='Sort by host name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (descending)' TITLE='Sort by host name (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_HOSTNAME,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_HOSTNAME,url_images_path,DOWN_ARROW_ICON); 01476 01477 printf("<TH CLASS='status'>Service <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service name (ascending)' TITLE='Sort by service name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service name (descending)' TITLE='Sort by service name (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_SERVICENAME,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_SERVICENAME,url_images_path,DOWN_ARROW_ICON); 01478 01479 printf("<TH CLASS='status'>Status <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service status (ascending)' TITLE='Sort by service status (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service status (descending)' TITLE='Sort by service status (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_SERVICESTATUS,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_SERVICESTATUS,url_images_path,DOWN_ARROW_ICON); 01480 01481 printf("<TH CLASS='status'>Last Check <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (ascending)' TITLE='Sort by last check time (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (descending)' TITLE='Sort by last check time (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_LASTCHECKTIME,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_LASTCHECKTIME,url_images_path,DOWN_ARROW_ICON); 01482 01483 printf("<TH CLASS='status'>Duration <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by state duration (ascending)' TITLE='Sort by state duration (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by state duration time (descending)' TITLE='Sort by state duration time (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_STATEDURATION,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_STATEDURATION,url_images_path,DOWN_ARROW_ICON); 01484 01485 printf("<TH CLASS='status'>Attempt <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by current attempt (ascending)' TITLE='Sort by current attempt (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by current attempt (descending)' TITLE='Sort by current attempt (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_CURRENTATTEMPT,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_CURRENTATTEMPT,url_images_path,DOWN_ARROW_ICON); 01486 01487 printf("<TH CLASS='status'>Status Information</TH>\n"); 01488 01489 if (is_authorized_for_read_only(¤t_authdata)==FALSE){ 01490 /* Add checkbox so every service can be checked */ 01491 printf("<TH CLASS='status' width='16'><input type='checkbox' value=all onclick=\"checkAll('tableform');isValidForSubmit('tableform');\"></TH>\n"); 01492 } 01493 01494 printf("</TR>\n"); 01495 } 01496 01497 01498 while(1){ 01499 01500 /* get the next service to display */ 01501 if(use_sort==TRUE){ 01502 if(first_entry==TRUE) 01503 temp_sort=statussort_list; 01504 else 01505 temp_sort=temp_sort->next; 01506 if(temp_sort==NULL) 01507 break; 01508 temp_status=temp_sort->status; 01509 }else{ 01510 if(first_entry==TRUE) 01511 temp_status=statusdata_list; 01512 else 01513 temp_status=temp_status->next; 01514 } 01515 01516 if(temp_status==NULL) 01517 break; 01518 01519 first_entry=FALSE; 01520 01521 /* find the host */ 01522 temp_host=find_host(temp_status->host_name); 01523 01524 /* find the service */ 01525 temp_service=find_service(temp_status->host_name,temp_status->svc_description); 01526 01527 01528 if(strcmp(last_host,temp_status->host_name)) 01529 new_host=TRUE; 01530 else 01531 new_host=FALSE; 01532 01533 if(new_host==TRUE && content_type!=CSV_CONTENT && content_type!=JSON_CONTENT ){ 01534 if(strcmp(last_host,"")) 01535 printf("<TR><TD colspan=6></TD></TR>\n"); 01536 } 01537 01538 if(odd) 01539 odd=0; 01540 else 01541 odd=1; 01542 01543 /* keep track of total number of services we're displaying */ 01544 total_entries++; 01545 01546 status=temp_status->status_string; 01547 status_class=temp_status->status_string; 01548 if(temp_status->status==SERVICE_PENDING){ 01549 status_bg_class=(odd)?"Even":"Odd"; 01550 } 01551 else if(temp_status->status==SERVICE_OK){ 01552 status_bg_class=(odd)?"Even":"Odd"; 01553 } 01554 else if(temp_status->status==SERVICE_WARNING){ 01555 if(temp_status->problem_has_been_acknowledged==TRUE) 01556 status_bg_class="BGWARNINGACK"; 01557 else if(temp_status->scheduled_downtime_depth>0) 01558 status_bg_class="BGWARNINGSCHED"; 01559 else 01560 status_bg_class="BGWARNING"; 01561 } 01562 else if(temp_status->status==SERVICE_UNKNOWN){ 01563 if(temp_status->problem_has_been_acknowledged==TRUE) 01564 status_bg_class="BGUNKNOWNACK"; 01565 else if(temp_status->scheduled_downtime_depth>0) 01566 status_bg_class="BGUNKNOWNSCHED"; 01567 else 01568 status_bg_class="BGUNKNOWN"; 01569 } 01570 else if(temp_status->status==SERVICE_CRITICAL){ 01571 if(temp_status->problem_has_been_acknowledged==TRUE) 01572 status_bg_class="BGCRITICALACK"; 01573 else if(temp_status->scheduled_downtime_depth>0) 01574 status_bg_class="BGCRITICALSCHED"; 01575 else 01576 status_bg_class="BGCRITICAL"; 01577 } 01578 01579 if(content_type==HTML_CONTENT) { 01580 01581 printf("<TR>\n"); 01582 01583 /* host name column */ 01584 if(new_host==TRUE){ 01585 01586 /* get the host status information */ 01587 temp_hoststatus=find_hoststatus(temp_status->host_name); 01588 01589 /* grab macros */ 01590 grab_host_macros_r(mac, temp_host); 01591 01592 if(temp_hoststatus->status==HOST_DOWN){ 01593 if(temp_hoststatus->problem_has_been_acknowledged==TRUE) 01594 host_status_bg_class="HOSTDOWNACK"; 01595 else if(temp_hoststatus->scheduled_downtime_depth>0) 01596 host_status_bg_class="HOSTDOWNSCHED"; 01597 else 01598 host_status_bg_class="HOSTDOWN"; 01599 } 01600 else if(temp_hoststatus->status==HOST_UNREACHABLE){ 01601 if(temp_hoststatus->problem_has_been_acknowledged==TRUE) 01602 host_status_bg_class="HOSTUNREACHABLEACK"; 01603 else if(temp_hoststatus->scheduled_downtime_depth>0) 01604 host_status_bg_class="HOSTUNREACHABLESCHED"; 01605 else 01606 host_status_bg_class="HOSTUNREACHABLE"; 01607 }else 01608 host_status_bg_class=(odd)?"Even":"Odd"; 01609 01610 printf("<TD CLASS='status%s'>",host_status_bg_class); 01611 01612 printf("<TABLE BORDER=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n"); 01613 printf("<TR>\n"); 01614 printf("<TD ALIGN=LEFT>\n"); 01615 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 01616 printf("<TR>\n"); 01617 if(!strcmp(temp_host->address6,temp_host->name)) 01618 printf("<TD align=left valign=center CLASS='status%s'><A HREF='%s?type=%d&host=%s' title='%s'>%s</A></TD>\n",host_status_bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),temp_host->address,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 01619 else 01620 printf("<TD align=left valign=center CLASS='status%s'><A HREF='%s?type=%d&host=%s' title='%s,%s'>%s</A></TD>\n",host_status_bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),temp_host->address,temp_host->address6,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 01621 01622 printf("</TR>\n"); 01623 printf("</TABLE>\n"); 01624 printf("</TD>\n"); 01625 printf("<TD align=right valign=center>\n"); 01626 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 01627 printf("<TR>\n"); 01628 total_comments=number_of_host_comments(temp_host->name); 01629 if(temp_hoststatus->problem_has_been_acknowledged==TRUE){ 01630 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This host problem has been acknowledged' TITLE='This host problem has been acknowledged'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),url_images_path,ACKNOWLEDGEMENT_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01631 } 01632 /* only show comments if this is a non-read-only user */ 01633 if(is_authorized_for_read_only(¤t_authdata)==FALSE){ 01634 if(total_comments>0) 01635 print_comment_icon(temp_host->name,NULL); 01636 } 01637 if(temp_hoststatus->notifications_enabled==FALSE){ 01638 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Notifications for this host have been disabled' TITLE='Notifications for this host have been disabled'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),url_images_path,NOTIFICATIONS_DISABLED_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01639 } 01640 if(temp_hoststatus->checks_enabled==FALSE){ 01641 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Checks of this host have been disabled'd TITLE='Checks of this host have been disabled'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),url_images_path,DISABLED_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01642 } 01643 if(temp_hoststatus->is_flapping==TRUE){ 01644 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This host is flapping between states' TITLE='This host is flapping between states'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),url_images_path,FLAPPING_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01645 } 01646 if(temp_hoststatus->scheduled_downtime_depth>0){ 01647 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This host is currently in a period of scheduled downtime' TITLE='This host is currently in a period of scheduled downtime'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name),url_images_path,SCHEDULED_DOWNTIME_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01648 } 01649 if(temp_host->notes_url!=NULL){ 01650 process_macros_r(mac, temp_host->notes_url,&processed_string,0); 01651 BEGIN_MULTIURL_LOOP 01652 printf("<TD align=center valign=center>"); 01653 printf("<A HREF='"); 01654 printf("%s",processed_string); 01655 printf("' TARGET='%s'>",(notes_url_target==NULL)?"_blank":notes_url_target); 01656 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,NOTES_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extra Host Notes","View Extra Host Notes"); 01657 printf("</A>"); 01658 printf("</TD>\n"); 01659 END_MULTIURL_LOOP 01660 free(processed_string); 01661 } 01662 if(temp_host->action_url!=NULL){ 01663 process_macros_r(mac, temp_host->action_url,&processed_string,0); 01664 BEGIN_MULTIURL_LOOP 01665 printf("<TD align=center valign=center>"); 01666 printf("<A HREF='"); 01667 printf("%s",processed_string); 01668 printf("' TARGET='%s'>",(action_url_target==NULL)?"_blank":action_url_target); 01669 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,ACTION_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Perform Extra Host Actions","Perform Extra Host Actions"); 01670 printf("</A>"); 01671 printf("</TD>\n"); 01672 END_MULTIURL_LOOP 01673 free(processed_string); 01674 } 01675 if(temp_host->icon_image!=NULL){ 01676 printf("<TD align=center valign=center>"); 01677 printf("<A HREF='%s?type=%d&host=%s'>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_status->host_name)); 01678 printf("<IMG SRC='%s",url_logo_images_path); 01679 process_macros_r(mac, temp_host->icon_image,&processed_string,0); 01680 printf("%s",processed_string); 01681 free(processed_string); 01682 printf("' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt); 01683 printf("</A>"); 01684 printf("</TD>\n"); 01685 } 01686 printf("</TR>\n"); 01687 printf("</TABLE>\n"); 01688 printf("</TD>\n"); 01689 printf("</TR>\n"); 01690 printf("</TABLE>\n"); 01691 }else 01692 printf("<TD>"); 01693 printf("</TD>\n"); 01694 01695 /* grab macros */ 01696 grab_service_macros_r(mac, temp_service); 01697 01698 /* service name column */ 01699 printf("<TD CLASS='status%s'>",status_bg_class); 01700 printf("<TABLE BORDER=0 WIDTH='100%%' CELLSPACING=0 CELLPADDING=0>"); 01701 printf("<TR>"); 01702 printf("<TD ALIGN=LEFT>"); 01703 printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>\n"); 01704 printf("<TR>\n"); 01705 printf("<TD ALIGN=LEFT valign=center CLASS='status%s'><A HREF='%s?type=%d&host=%s",status_bg_class,EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01706 printf("&service=%s'>",url_encode(temp_status->svc_description)); 01707 printf("%s</A></TD>",(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description); 01708 printf("</TR>\n"); 01709 printf("</TABLE>\n"); 01710 printf("</TD>\n"); 01711 printf("<TD ALIGN=RIGHT CLASS='status%s'>\n",status_bg_class); 01712 printf("<TABLE BORDER=0 cellspacing=0 cellpadding=0>\n"); 01713 printf("<TR>\n"); 01714 total_comments=number_of_service_comments(temp_service->host_name,temp_service->description); 01715 /* only show comments if this is a non-read-only user */ 01716 if(is_authorized_for_read_only(¤t_authdata)==FALSE){ 01717 if(total_comments>0){ 01718 print_comment_icon(temp_host->name,temp_service->description); 01719 } 01720 } 01721 if(temp_status->problem_has_been_acknowledged==TRUE){ 01722 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01723 printf("&service=%s#comments'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This service problem has been acknowledged' TITLE='This service problem has been acknowledged'></A></TD>",url_encode(temp_status->svc_description),url_images_path,ACKNOWLEDGEMENT_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01724 } 01725 if(temp_status->checks_enabled==FALSE && temp_service->accept_passive_service_checks==FALSE){ 01726 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01727 printf("&service=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Active and passive checks have been disabled for this service' TITLE='Active and passive checks have been disabled for this service'></A></TD>",url_encode(temp_status->svc_description),url_images_path,DISABLED_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01728 } 01729 else if(temp_status->checks_enabled==FALSE){ 01730 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01731 printf("&service=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Active checks of the service have been disabled - only passive checks are being accepted' TITLE='Active checks of the service have been disabled - only passive checks are being accepted'></A></TD>",url_encode(temp_status->svc_description),url_images_path,PASSIVE_ONLY_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01732 } 01733 if(temp_status->notifications_enabled==FALSE){ 01734 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01735 printf("&service=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Notifications for this service have been disabled' TITLE='Notifications for this service have been disabled'></A></TD>",url_encode(temp_status->svc_description),url_images_path,NOTIFICATIONS_DISABLED_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01736 } 01737 if(temp_status->is_flapping==TRUE){ 01738 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01739 printf("&service=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This service is flapping between states' TITLE='This service is flapping between states'></A></TD>",url_encode(temp_status->svc_description),url_images_path,FLAPPING_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01740 } 01741 if(temp_status->scheduled_downtime_depth>0){ 01742 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_status->host_name)); 01743 printf("&service=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This service is currently in a period of scheduled downtime' TITLE='This service is currently in a period of scheduled downtime'></A></TD>",url_encode(temp_status->svc_description),url_images_path,SCHEDULED_DOWNTIME_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 01744 } 01745 if(temp_service->notes_url!=NULL){ 01746 process_macros_r(mac, temp_service->notes_url,&processed_string,0); 01747 BEGIN_MULTIURL_LOOP 01748 printf("<TD align=center valign=center>"); 01749 printf("<A HREF='"); 01750 printf("%s",processed_string); 01751 printf("' TARGET='%s'>",(notes_url_target==NULL)?"_blank":notes_url_target); 01752 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,NOTES_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extra Service Notes","View Extra Service Notes"); 01753 printf("</A>"); 01754 printf("</TD>\n"); 01755 END_MULTIURL_LOOP 01756 free(processed_string); 01757 } 01758 if(temp_service->action_url!=NULL){ 01759 process_macros_r(mac, temp_service->action_url,&processed_string,0); 01760 BEGIN_MULTIURL_LOOP 01761 printf("<TD align=center valign=center>"); 01762 printf("<A HREF='"); 01763 printf("%s",processed_string); 01764 printf("' TARGET='%s'>",(action_url_target==NULL)?"_blank":action_url_target); 01765 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,ACTION_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Perform Extra Service Actions","Perform Extra Service Actions"); 01766 printf("</A>"); 01767 printf("</TD>\n"); 01768 END_MULTIURL_LOOP 01769 free(processed_string); 01770 } 01771 if(temp_service->icon_image!=NULL){ 01772 printf("<TD ALIGN=center valign=center>"); 01773 printf("<A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_service->host_name)); 01774 printf("&service=%s'>",url_encode(temp_service->description)); 01775 printf("<IMG SRC='%s",url_logo_images_path); 01776 process_macros_r(mac, temp_service->icon_image,&processed_string,0); 01777 printf("%s",processed_string); 01778 free(processed_string); 01779 printf("' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,(temp_service->icon_image_alt==NULL)?"":temp_service->icon_image_alt,(temp_service->icon_image_alt==NULL)?"":temp_service->icon_image_alt); 01780 printf("</A>"); 01781 printf("</TD>\n"); 01782 } 01783 if(enable_splunk_integration==TRUE){ 01784 printf("<TD ALIGN=center valign=center>"); 01785 display_splunk_service_url(temp_service); 01786 printf("</TD>\n"); 01787 } 01788 printf("</TR>\n"); 01789 printf("</TABLE>\n"); 01790 printf("</TD>\n"); 01791 printf("</TR>"); 01792 printf("</TABLE>"); 01793 printf("</TD>\n"); 01794 01795 01796 /* the rest of the columns... */ 01797 printf("<TD CLASS='status%s'>%s</TD>\n",status_class,temp_status->status_string); 01798 printf("<TD CLASS='status%s' nowrap>%s</TD>\n",status_bg_class,temp_status->last_check); 01799 printf("<TD CLASS='status%s' nowrap>%s</TD>\n",status_bg_class,temp_status->state_duration); 01800 printf("<TD CLASS='status%s'>%s</TD>\n",status_bg_class,temp_status->attempts); 01801 printf("<TD CLASS='status%s' valign='center'>%s</TD>\n",status_bg_class,temp_status->plugin_output); 01802 01803 if (is_authorized_for_read_only(¤t_authdata)==FALSE){ 01804 /* Checkbox for service(s) */ 01805 printf("<TD CLASS='status%s' nowrap align='center'><input onclick=\"isValidForSubmit('tableform');\" type='checkbox' name='checkbox' value='&host=%s",status_bg_class,url_encode(temp_status->host_name)); 01806 printf("&service=%s'></TD>\n",url_encode(temp_status->svc_description)); 01807 } 01808 01809 01810 if(enable_splunk_integration==TRUE) 01811 display_splunk_service_url(temp_service); 01812 01813 01814 printf("</TR>\n"); 01815 } 01816 01817 /* print list in json format */ 01818 if(content_type==JSON_CONTENT) { 01819 // always add a comma, except for the first line 01820 if (json_start==FALSE) 01821 printf(",\n"); 01822 json_start=FALSE; 01823 printf("{ \"host\": \"%s\", ",(temp_host->display_name!=NULL)?json_encode(temp_host->display_name):json_encode(temp_host->name)); 01824 printf("\"service\": \"%s\", ",(temp_service->display_name!=NULL)?json_encode(temp_service->display_name):json_encode(temp_service->description)); 01825 printf("\"status\": \"%s\", ",temp_status->status_string); 01826 printf("\"last_check\": \"%s\", ",temp_status->last_check); 01827 printf("\"duration\": \"%s\", ",temp_status->state_duration); 01828 printf("\"attempts\": \"%s\", ",temp_status->attempts); 01829 if (temp_status->plugin_output==NULL) 01830 printf("\"status_information\": null }"); 01831 else 01832 printf("\"status_information\": \"%s\"}",json_encode(temp_status->plugin_output)); 01833 01834 /* print list in csv format */ 01835 }else if(content_type==CSV_CONTENT) { 01836 printf("%s%s%s%s",csv_data_enclosure,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name,csv_data_enclosure,csv_delimiter); 01837 printf("%s%s%s%s",csv_data_enclosure,(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description,csv_data_enclosure,csv_delimiter); 01838 01839 printf("%s%s%s%s",csv_data_enclosure,temp_status->status_string,csv_data_enclosure,csv_delimiter); 01840 printf("%s%s%s%s",csv_data_enclosure,temp_status->last_check,csv_data_enclosure,csv_delimiter); 01841 printf("%s%s%s%s",csv_data_enclosure,temp_status->state_duration,csv_data_enclosure,csv_delimiter); 01842 printf("%s%s%s%s",csv_data_enclosure,temp_status->attempts,csv_data_enclosure,csv_delimiter); 01843 printf("%s%s%s\n",csv_data_enclosure,(temp_status->plugin_output==NULL)?"":temp_status->plugin_output,csv_data_enclosure); 01844 } 01845 01846 last_host=temp_status->host_name; 01847 } 01848 01849 if(content_type!=CSV_CONTENT && content_type!=JSON_CONTENT){ 01850 printf("</TABLE>\n"); 01851 printf("</DIV>\n"); 01852 01853 /* if user couldn't see anything, print out some helpful info... */ 01854 if(total_entries==0 && user_is_authorized_for_statusdata==FALSE) 01855 print_generic_error_message("It appears as though you do not have permission to view information for any of the services you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 01856 else 01857 printf("<BR><DIV CLASS='itemTotalsTitle'>%d Matching Service Entries Displayed</DIV>\n",total_entries); 01858 }else if (content_type==JSON_CONTENT) 01859 printf("\n]\n"); 01860 01861 return; 01862 } 01863 01864 01865 /* display a detailed listing of the status of all hosts... */ 01866 void show_host_detail(void){ 01867 char *status=NULL; 01868 char temp_buffer[MAX_INPUT_BUFFER]; 01869 char temp_url[MAX_INPUT_BUFFER]; 01870 char *processed_string=NULL; 01871 char *status_class=""; 01872 char *status_bg_class=""; 01873 host *temp_host=NULL; 01874 sort *temp_sort=NULL; 01875 int odd=0; 01876 int total_comments=0; 01877 int use_sort=FALSE; 01878 int result=OK; 01879 int first_entry=TRUE; 01880 int total_entries=0; 01881 statusdata *temp_statusdata=NULL; 01882 int json_start=TRUE; 01883 01884 01885 /* grap requested data */ 01886 grab_statusdata(); 01887 01888 /* sort status data if necessary */ 01889 if(sort_type!=SORT_NONE){ 01890 result=sort_status_data(HOST_STATUS,sort_type,sort_option); 01891 if(result==ERROR) 01892 use_sort=FALSE; 01893 else 01894 use_sort=TRUE; 01895 }else 01896 use_sort=FALSE; 01897 01898 01899 if (content_type==HTML_CONTENT) { 01900 printf("<P>\n"); 01901 01902 printf("<table border=0 width=100%%>\n"); 01903 printf("<tr>\n"); 01904 01905 printf("<td valign=top align=left width=33%%>\n"); 01906 01907 if(display_header==TRUE) 01908 show_filters(); 01909 01910 printf("</td>"); 01911 01912 printf("<td valign=top align=center width=33%%>\n"); 01913 01914 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Host Status Details For "); 01915 01916 if(show_all_hosts==FALSE) 01917 printf("Host '%s'",host_name); 01918 else if(show_all_hostgroups==TRUE) 01919 printf("All Host Groups"); 01920 else 01921 printf("Host Group '%s'",hostgroup_name); 01922 printf("</DIV>\n"); 01923 01924 if(use_sort==TRUE){ 01925 printf("<DIV ALIGN=CENTER CLASS='statusSort'>Entries sorted by <b>"); 01926 if(sort_option==SORT_HOSTNAME) 01927 printf("host name"); 01928 else if(sort_option==SORT_HOSTSTATUS) 01929 printf("host status"); 01930 else if(sort_option==SORT_LASTCHECKTIME) 01931 printf("last check time"); 01932 else if(sort_option==SORT_CURRENTATTEMPT) 01933 printf("attempt number"); 01934 else if(sort_option==SORT_STATEDURATION) 01935 printf("state duration"); 01936 printf("</b> (%s)\n",(sort_type==SORT_ASCENDING)?"ascending":"descending"); 01937 printf("</DIV>\n"); 01938 } 01939 01940 printf("<br>"); 01941 01942 printf("</td>\n"); 01943 01944 /* add export to csv link */ 01945 printf("<td valign=bottom width=33%%><div class='csv_export_link'><a href='%s' target='_blank'>Export to CSV</a></div></td>\n",get_export_csv_link(STATUS_CGI)); 01946 01947 printf("</tr>\n"); 01948 printf("</table>\n"); 01949 } 01950 01951 01952 snprintf(temp_url,sizeof(temp_url)-1,"%s?",STATUS_CGI); 01953 temp_url[sizeof(temp_url)-1]='\x0'; 01954 if(display_type==DISPLAY_HOSTS) 01955 snprintf(temp_buffer,sizeof(temp_buffer)-1,"host=%s&style=hostdetail",(host_name==NULL)?"all":url_encode(host_name)); 01956 else 01957 snprintf(temp_buffer,sizeof(temp_buffer)-1,"hostgroup=%s&style=hostdetail",url_encode(hostgroup_name)); 01958 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01959 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01960 temp_url[sizeof(temp_url)-1]='\x0'; 01961 if(service_status_types!=all_service_status_types){ 01962 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&servicestatustypes=%d",service_status_types); 01963 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01964 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01965 temp_url[sizeof(temp_url)-1]='\x0'; 01966 } 01967 if(host_status_types!=all_host_status_types){ 01968 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&hoststatustypes=%d",host_status_types); 01969 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01970 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01971 temp_url[sizeof(temp_url)-1]='\x0'; 01972 } 01973 if(service_properties!=0){ 01974 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&serviceprops=%lu",service_properties); 01975 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01976 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01977 temp_url[sizeof(temp_url)-1]='\x0'; 01978 } 01979 if(host_properties!=0){ 01980 snprintf(temp_buffer,sizeof(temp_buffer)-1,"&hostprops=%lu",host_properties); 01981 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 01982 strncat(temp_url,temp_buffer,sizeof(temp_url)-strlen(temp_url)-1); 01983 temp_url[sizeof(temp_url)-1]='\x0'; 01984 } 01985 01986 if(content_type==JSON_CONTENT) 01987 printf("\"host_status\": [\n"); 01988 else if(content_type==CSV_CONTENT) { 01989 printf("%sHost%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01990 printf("%sStatus%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01991 printf("%sLast_Check%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01992 printf("%sDuration%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01993 printf("%sAttempt%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 01994 printf("%sStatus_Information%s\n",csv_data_enclosure,csv_data_enclosure); 01995 } else { 01996 /* the main list of hosts */ 01997 printf("<DIV ALIGN='center'>\n"); 01998 printf("<TABLE BORDER=0 CLASS='status' WIDTH=100%%>\n"); 01999 printf("<TR>\n"); 02000 02001 printf("<TH CLASS='status'>Host <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (ascending)' TITLE='Sort by host name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (descending)' TITLE='Sort by host name (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_HOSTNAME,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_HOSTNAME,url_images_path,DOWN_ARROW_ICON); 02002 02003 printf("<TH CLASS='status'>Status <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host status (ascending)' TITLE='Sort by host status (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host status (descending)' TITLE='Sort by host status (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_HOSTSTATUS,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_HOSTSTATUS,url_images_path,DOWN_ARROW_ICON); 02004 02005 printf("<TH CLASS='status'>Last Check <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (ascending)' TITLE='Sort by last check time (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (descending)' TITLE='Sort by last check time (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_LASTCHECKTIME,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_LASTCHECKTIME,url_images_path,DOWN_ARROW_ICON); 02006 02007 printf("<TH CLASS='status'>Duration <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by state duration (ascending)' TITLE='Sort by state duration (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by state duration time (descending)' TITLE='Sort by state duration time (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_STATEDURATION,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_STATEDURATION,url_images_path,DOWN_ARROW_ICON); 02008 02009 printf("<TH CLASS='status'>Attempt <A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by current attempt (ascending)' TITLE='Sort by current attempt (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by current attempt (descending)' TITLE='Sort by current attempt (descending)'></A></TH>",temp_url,SORT_ASCENDING,SORT_CURRENTATTEMPT,url_images_path,UP_ARROW_ICON,temp_url,SORT_DESCENDING,SORT_CURRENTATTEMPT,url_images_path,DOWN_ARROW_ICON); 02010 02011 printf("<TH CLASS='status'>Status Information</TH>\n"); 02012 02013 if (is_authorized_for_read_only(¤t_authdata)==FALSE){ 02014 /* Add a checkbox so every host can be checked */ 02015 printf("<TH CLASS='status' width='16'><input type='checkbox' value=all onclick=\"checkAll('tableform');isValidForSubmit('tableform');\"></TH>\n"); 02016 } 02017 02018 printf("</TR>\n"); 02019 } 02020 02021 02022 02023 /* check all hosts... */ 02024 02025 if(display_type==DISPLAY_HOSTGROUPS||display_type==DISPLAY_HOSTS){ 02026 02027 while (1) { 02028 02029 /* get the next host to display */ 02030 if(use_sort==TRUE){ 02031 if(first_entry==TRUE) 02032 temp_sort=statussort_list; 02033 else 02034 temp_sort=temp_sort->next; 02035 if(temp_sort==NULL) 02036 break; 02037 temp_statusdata=temp_sort->status; 02038 }else{ 02039 if(first_entry==TRUE) 02040 temp_statusdata=statusdata_list; 02041 else 02042 temp_statusdata=temp_statusdata->next; 02043 } 02044 02045 if(temp_statusdata==NULL) 02046 break; 02047 02048 first_entry=FALSE; 02049 02050 temp_host=find_host(temp_statusdata->host_name); 02051 02052 if(temp_host==NULL) 02053 continue; 02054 02055 if(odd) 02056 odd=0; 02057 else 02058 odd=1; 02059 02060 total_entries++; 02061 02062 status=temp_statusdata->status_string; 02063 02064 if(temp_statusdata->status==HOST_PENDING){ 02065 status_class="PENDING"; 02066 status_bg_class=(odd)?"Even":"Odd"; 02067 } 02068 else if(temp_statusdata->status==HOST_UP){ 02069 status_class="HOSTUP"; 02070 status_bg_class=(odd)?"Even":"Odd"; 02071 } 02072 else if(temp_statusdata->status==HOST_DOWN){ 02073 status_class="HOSTDOWN"; 02074 if(temp_statusdata->problem_has_been_acknowledged==TRUE) 02075 status_bg_class="BGDOWNACK"; 02076 else if(temp_statusdata->scheduled_downtime_depth>0) 02077 status_bg_class="BGDOWNSCHED"; 02078 else 02079 status_bg_class="BGDOWN"; 02080 } 02081 else if(temp_statusdata->status==HOST_UNREACHABLE){ 02082 status_class="HOSTUNREACHABLE"; 02083 if(temp_statusdata->problem_has_been_acknowledged==TRUE) 02084 status_bg_class="BGUNREACHABLEACK"; 02085 else if(temp_statusdata->scheduled_downtime_depth>0) 02086 status_bg_class="BGUNREACHABLESCHED"; 02087 else 02088 status_bg_class="BGUNREACHABLE"; 02089 } 02090 02091 grab_host_macros(temp_host); 02092 02093 if(content_type==HTML_CONTENT) { 02094 02095 printf("<TR>\n"); 02096 02097 02098 /**** host name column ****/ 02099 02100 printf("<TD CLASS='status%s'>",status_class); 02101 02102 printf("<TABLE BORDER=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n"); 02103 printf("<TR>\n"); 02104 printf("<TD ALIGN=LEFT>\n"); 02105 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 02106 printf("<TR>\n"); 02107 if(!strcmp(temp_host->address6,temp_host->name)) 02108 printf("<TD align=left valign=center CLASS='status%s'><A HREF='%s?type=%d&host=%s' title='%s'>%s</A> </TD>\n",status_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),temp_host->address,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 02109 else 02110 printf("<TD align=left valign=center CLASS='status%s'><A HREF='%s?type=%d&host=%s' title='%s,%s'>%s</A> </TD>\n",status_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),temp_host->address,temp_host->address6,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 02111 02112 printf("</TR>\n"); 02113 printf("</TABLE>\n"); 02114 printf("</TD>\n"); 02115 printf("<TD align=right valign=center>\n"); 02116 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 02117 printf("<TR>\n"); 02118 total_comments=number_of_host_comments(temp_host->name); 02119 if(temp_statusdata->problem_has_been_acknowledged==TRUE){ 02120 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This host problem has been acknowledged' TITLE='This host problem has been acknowledged'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),url_images_path,ACKNOWLEDGEMENT_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 02121 } 02122 if(total_comments>0) 02123 print_comment_icon(temp_host->name,NULL); 02124 if(temp_statusdata->notifications_enabled==FALSE){ 02125 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Notifications for this host have been disabled' TITLE='Notifications for this host have been disabled'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),url_images_path,NOTIFICATIONS_DISABLED_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 02126 } 02127 if(temp_statusdata->checks_enabled==FALSE){ 02128 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='Checks of this host have been disabled' TITLE='Checks of this host have been disabled'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),url_images_path,DISABLED_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 02129 } 02130 if(temp_statusdata->is_flapping==TRUE){ 02131 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This host is flapping between states' TITLE='This host is flapping between states'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),url_images_path,FLAPPING_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 02132 } 02133 if(temp_statusdata->scheduled_downtime_depth>0){ 02134 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='This host is currently in a period of scheduled downtime' TITLE='This host is currently in a period of scheduled downtime'></A></TD>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name),url_images_path,SCHEDULED_DOWNTIME_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 02135 } 02136 if(temp_host->notes_url!=NULL){ 02137 process_macros_r(mac, temp_host->notes_url,&processed_string,0); 02138 BEGIN_MULTIURL_LOOP 02139 printf("<TD align=center valign=center>"); 02140 printf("<A HREF='"); 02141 printf("%s",processed_string); 02142 printf("' TARGET='%s'>",(notes_url_target==NULL)?"_blank":notes_url_target); 02143 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,NOTES_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extra Host Notes","View Extra Host Notes"); 02144 printf("</A>"); 02145 printf("</TD>\n"); 02146 END_MULTIURL_LOOP 02147 free(processed_string); 02148 } 02149 if(temp_host->action_url!=NULL){ 02150 process_macros_r(mac, temp_host->action_url,&processed_string,0); 02151 BEGIN_MULTIURL_LOOP 02152 printf("<TD align=center valign=center>"); 02153 printf("<A HREF='"); 02154 printf("%s",processed_string); 02155 printf("' TARGET='%s'>",(action_url_target==NULL)?"_blank":action_url_target); 02156 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,ACTION_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Perform Extra Host Actions","Perform Extra Host Actions"); 02157 printf("</A>"); 02158 printf("</TD>\n"); 02159 END_MULTIURL_LOOP 02160 free(processed_string); 02161 } 02162 if(temp_host->icon_image!=NULL){ 02163 printf("<TD align=center valign=center>"); 02164 printf("<A HREF='%s?type=%d&host=%s'>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_statusdata->host_name)); 02165 printf("<IMG SRC='%s",url_logo_images_path); 02166 process_macros_r(mac, temp_host->icon_image,&processed_string,0); 02167 printf("%s",processed_string); 02168 free(processed_string); 02169 printf("' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt); 02170 printf("</A>"); 02171 printf("</TD>\n"); 02172 } 02173 if(enable_splunk_integration==TRUE){ 02174 printf("<TD ALIGN=center valign=center>"); 02175 display_splunk_host_url(temp_host); 02176 printf("</TD>\n"); 02177 } 02178 printf("<TD>"); 02179 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>",STATUS_CGI,url_encode(temp_statusdata->host_name),url_images_path,STATUS_DETAIL_ICON); 02180 printf("</TD>\n"); 02181 printf("</TR>\n"); 02182 printf("</TABLE>\n"); 02183 printf("</TD>\n"); 02184 printf("</TR>\n"); 02185 printf("</TABLE>\n"); 02186 02187 printf("</TD>\n"); 02188 02189 /* the rest of the columns... */ 02190 printf("<TD CLASS='status%s'>%s</TD>\n",status_class,temp_statusdata->status_string); 02191 printf("<TD CLASS='status%s' nowrap>%s</TD>\n",status_bg_class,temp_statusdata->last_check); 02192 printf("<TD CLASS='status%s' nowrap>%s</TD>\n",status_bg_class,temp_statusdata->state_duration); 02193 printf("<TD CLASS='status%s'>%s</TD>\n",status_bg_class,temp_statusdata->attempts); 02194 printf("<TD CLASS='status%s' valign='center'>%s</TD>\n",status_bg_class,temp_statusdata->plugin_output); 02195 02196 /* Checkbox for host(s) */ 02197 if (is_authorized_for_read_only(¤t_authdata)==FALSE) 02198 printf("<TD CLASS='status%s' valign='center' align='center'><input onClick=\"isValidForSubmit('tableform');\" type='checkbox' name='checkbox' value='&host=%s'></TD>\n",status_bg_class,url_encode(temp_statusdata->host_name)); 02199 02200 02201 02202 if(enable_splunk_integration==TRUE) 02203 display_splunk_host_url(temp_host); 02204 02205 02206 printf("</TR>\n"); 02207 } 02208 02209 /* print list in json format */ 02210 if(content_type==JSON_CONTENT) { 02211 // always add a comma, except for the first line 02212 if (json_start==FALSE) 02213 printf(",\n"); 02214 json_start=FALSE; 02215 printf("{ \"host\": \"%s\", ",(temp_host->display_name!=NULL)?json_encode(temp_host->display_name):json_encode(temp_host->name)); 02216 printf("\"status\": \"%s\", ",temp_statusdata->status_string); 02217 printf("\"last_check\": \"%s\", ",temp_statusdata->last_check); 02218 printf("\"duration\": \"%s\", ",temp_statusdata->state_duration); 02219 printf("\"attempts\": \"%s\", ",temp_statusdata->attempts); 02220 if (temp_statusdata->plugin_output==NULL) 02221 printf("\"status_information\": null }"); 02222 else 02223 printf("\"status_information\": \"%s\"}",json_encode(temp_statusdata->plugin_output)); 02224 02225 /* print list in csv format */ 02226 }else if(content_type==CSV_CONTENT) { 02227 printf("%s%s%s%s",csv_data_enclosure,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name,csv_data_enclosure,csv_delimiter); 02228 02229 printf("%s%s%s%s",csv_data_enclosure,temp_statusdata->status_string,csv_data_enclosure,csv_delimiter); 02230 printf("%s%s%s%s",csv_data_enclosure,temp_statusdata->last_check,csv_data_enclosure,csv_delimiter); 02231 printf("%s%s%s%s",csv_data_enclosure,temp_statusdata->state_duration,csv_data_enclosure,csv_delimiter); 02232 printf("%s%s%s%s",csv_data_enclosure,temp_statusdata->attempts,csv_data_enclosure,csv_delimiter); 02233 printf("%s%s%s\n",csv_data_enclosure,(temp_statusdata->plugin_output==NULL)?"":temp_statusdata->plugin_output,csv_data_enclosure); 02234 } 02235 } 02236 } 02237 02238 if(content_type!=CSV_CONTENT && content_type!=JSON_CONTENT){ 02239 printf("</TABLE>\n"); 02240 printf("</DIV>\n"); 02241 02242 /* if user couldn't see anything, print out some helpful info... */ 02243 if(total_entries==0 && user_is_authorized_for_statusdata==FALSE) 02244 print_generic_error_message("It appears as though you do not have permission to view information for any of the hosts you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 02245 else 02246 printf("<BR><DIV CLASS='itemTotalsTitle'>%d Matching Host Entries Displayed</DIV>\n",total_entries); 02247 }else if (content_type==JSON_CONTENT) 02248 printf("\n]\n"); 02249 02250 return; 02251 } 02252 02253 02254 /* show an overview of servicegroup(s)... */ 02255 void show_servicegroup_overviews(void){ 02256 servicegroup *temp_servicegroup=NULL; 02257 int current_column; 02258 int user_has_seen_something=FALSE; 02259 int servicegroup_error=FALSE; 02260 char error_text[MAX_INPUT_BUFFER]=""; 02261 int json_start=TRUE; 02262 02263 if(content_type==JSON_CONTENT) { 02264 printf("\"servicegroup_overview\": [\n"); 02265 02266 /* display status overviews for all servicegroups */ 02267 if(show_all_servicegroups==TRUE){ 02268 02269 for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){ 02270 02271 /* make sure the user is authorized to view at least one host in this servicegroup */ 02272 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE) 02273 continue; 02274 02275 // always add a comma, except for the first line 02276 if (json_start==FALSE) 02277 printf(",\n"); 02278 json_start=FALSE; 02279 02280 show_servicegroup_overview(temp_servicegroup); 02281 02282 user_has_seen_something=TRUE; 02283 } 02284 } else { 02285 temp_servicegroup=find_servicegroup(servicegroup_name); 02286 if(temp_servicegroup==NULL) 02287 servicegroup_error=TRUE; 02288 else{ 02289 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==TRUE){ 02290 02291 show_servicegroup_overview(temp_servicegroup); 02292 02293 user_has_seen_something=TRUE; 02294 } 02295 } 02296 } 02297 }else{ 02298 printf("<P>\n"); 02299 02300 printf("<table border=0 width=100%%>\n"); 02301 printf("<tr>\n"); 02302 02303 printf("<td valign=top align=left width=33%%>\n"); 02304 02305 show_filters(); 02306 02307 printf("</td>"); 02308 02309 printf("<td valign=top align=center width=33%%>\n"); 02310 02311 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Service Overview For "); 02312 if(show_all_servicegroups==TRUE) 02313 printf("All Service Groups"); 02314 else 02315 printf("Service Group '%s'",servicegroup_name); 02316 printf("</DIV>\n"); 02317 02318 printf("<br>"); 02319 02320 printf("</td>\n"); 02321 02322 printf("<td valign=top align=right width=33%%></td>\n"); 02323 02324 printf("</tr>\n"); 02325 printf("</table>\n"); 02326 02327 printf("</P>\n"); 02328 02329 /* display status overviews for all servicegroups */ 02330 if(show_all_servicegroups==TRUE){ 02331 02332 02333 printf("<DIV ALIGN=center>\n"); 02334 printf("<TABLE BORDER=0 CELLPADDING=10>\n"); 02335 02336 current_column=1; 02337 02338 /* loop through all servicegroups... */ 02339 for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){ 02340 02341 /* make sure the user is authorized to view at least one host in this servicegroup */ 02342 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE) 02343 continue; 02344 02345 if(current_column==1) 02346 printf("<TR>\n"); 02347 printf("<TD VALIGN=top ALIGN=center>\n"); 02348 02349 show_servicegroup_overview(temp_servicegroup); 02350 02351 user_has_seen_something=TRUE; 02352 02353 printf("</TD>\n"); 02354 if(current_column==overview_columns) 02355 printf("</TR>\n"); 02356 02357 if(current_column<overview_columns) 02358 current_column++; 02359 else 02360 current_column=1; 02361 } 02362 02363 if(current_column!=1){ 02364 02365 for(;current_column<=overview_columns;current_column++) 02366 printf("<TD></TD>\n"); 02367 printf("</TR>\n"); 02368 } 02369 02370 printf("</TABLE>\n"); 02371 printf("</DIV>\n"); 02372 } 02373 02374 /* else display overview for just a specific servicegroup */ 02375 else{ 02376 02377 temp_servicegroup=find_servicegroup(servicegroup_name); 02378 if(temp_servicegroup==NULL) 02379 servicegroup_error=TRUE; 02380 else{ 02381 02382 printf("<P>\n"); 02383 printf("<DIV ALIGN=CENTER>\n"); 02384 printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD ALIGN=CENTER>\n"); 02385 02386 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==TRUE){ 02387 02388 show_servicegroup_overview(temp_servicegroup); 02389 02390 user_has_seen_something=TRUE; 02391 } 02392 02393 printf("</TD></TR></TABLE>\n"); 02394 printf("</DIV>\n"); 02395 printf("</P>\n"); 02396 } 02397 } 02398 } 02399 02400 if(content_type==JSON_CONTENT) 02401 printf(" ]\n"); 02402 02403 /* if user couldn't see anything, print out some helpful info... */ 02404 if(user_has_seen_something==FALSE && servicegroup_error==FALSE){ 02405 02406 if(content_type==JSON_CONTENT) 02407 printf(",\n"); 02408 02409 if(servicegroup_list!=NULL) 02410 print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 02411 else 02412 print_generic_error_message("There are no service groups defined.",NULL,0); 02413 } 02414 02415 /* we couldn't find the servicegroup */ 02416 else if(servicegroup_error==TRUE){ 02417 if(content_type==JSON_CONTENT) 02418 printf(",\n"); 02419 02420 snprintf(error_text,sizeof(error_text),"Sorry, but service group '%s' doesn't seem to exist...",servicegroup_name); 02421 error_text[sizeof(error_text)-1]='\x0'; 02422 print_generic_error_message(error_text,NULL,0); 02423 } 02424 02425 return; 02426 } 02427 02428 02429 /* shows an overview of a specific servicegroup... */ 02430 void show_servicegroup_overview(servicegroup *temp_servicegroup){ 02431 servicesmember *temp_member; 02432 host *temp_host; 02433 host *last_host; 02434 hoststatus *temp_hoststatus=NULL; 02435 int odd=0; 02436 int json_start=TRUE; 02437 02438 /* make sure the user is authorized to view this hostgroup */ 02439 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE) 02440 return; 02441 02442 /* print json format */ 02443 if(content_type==JSON_CONTENT) { 02444 printf("{ \"servicegroup_name\": \"%s\",\n",json_encode(temp_servicegroup->group_name)); 02445 printf("\"members\": [ \n"); 02446 }else{ 02447 printf("<DIV CLASS='status'>\n"); 02448 printf("<A HREF='%s?servicegroup=%s&style=detail'>%s</A>",STATUS_CGI,url_encode(temp_servicegroup->group_name),temp_servicegroup->alias); 02449 printf(" (<A HREF='%s?type=%d&servicegroup=%s'>%s</A>)",EXTINFO_CGI,DISPLAY_SERVICEGROUP_INFO,url_encode(temp_servicegroup->group_name),temp_servicegroup->group_name); 02450 printf("</DIV>\n"); 02451 02452 printf("<DIV CLASS='status'>\n"); 02453 printf("<table border=1 CLASS='status'>\n"); 02454 02455 printf("<TR>\n"); 02456 printf("<TH CLASS='status'>Host</TH><TH CLASS='status'>Status</TH><TH CLASS='status'>Services</TH><TH CLASS='status'>Actions</TH>\n"); 02457 printf("</TR>\n"); 02458 } 02459 02460 /* find all hosts that have services that are members of the servicegroup */ 02461 last_host=NULL; 02462 for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){ 02463 02464 /* find the host */ 02465 temp_host=find_host(temp_member->host_name); 02466 if(temp_host==NULL) 02467 continue; 02468 02469 /* skip this if it isn't a new host... */ 02470 if(temp_host==last_host) 02471 continue; 02472 02473 /* find the host status */ 02474 temp_hoststatus=find_hoststatus(temp_host->name); 02475 if(temp_hoststatus==NULL) 02476 continue; 02477 02478 /* make sure we only display hosts of the specified status levels */ 02479 if(!(host_status_types & temp_hoststatus->status)) 02480 continue; 02481 02482 /* make sure we only display hosts that have the desired properties */ 02483 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 02484 continue; 02485 02486 if(odd) 02487 odd=0; 02488 else 02489 odd=1; 02490 02491 if(content_type==JSON_CONTENT) { 02492 if (json_start==FALSE) 02493 printf(",\n"); 02494 json_start=FALSE; 02495 } 02496 02497 show_servicegroup_hostgroup_member_overview(temp_hoststatus,odd,temp_servicegroup); 02498 02499 last_host=temp_host; 02500 } 02501 02502 if(content_type==JSON_CONTENT) 02503 printf(" ] }\n"); 02504 else{ 02505 printf("</table>\n"); 02506 printf("</DIV>\n"); 02507 } 02508 02509 return; 02510 } 02511 02512 02513 /* show a summary of servicegroup(s)... */ 02514 void show_servicegroup_summaries(void){ 02515 servicegroup *temp_servicegroup=NULL; 02516 int user_has_seen_something=FALSE; 02517 int servicegroup_error=FALSE; 02518 int odd=0; 02519 char error_text[MAX_INPUT_BUFFER]=""; 02520 int json_start=TRUE; 02521 02522 if(content_type==JSON_CONTENT) { 02523 printf("\"servicegroup_summary\": [\n"); 02524 }else{ 02525 printf("<P>\n"); 02526 02527 printf("<table border=0 width=100%%>\n"); 02528 printf("<tr>\n"); 02529 02530 printf("<td valign=top align=left width=33%%>\n"); 02531 02532 show_filters(); 02533 02534 printf("</td>"); 02535 02536 printf("<td valign=top align=center width=33%%>\n"); 02537 02538 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Status Summary For "); 02539 if(show_all_servicegroups==TRUE) 02540 printf("All Service Groups"); 02541 else 02542 printf("Service Group '%s'",servicegroup_name); 02543 printf("</DIV>\n"); 02544 02545 printf("<br>"); 02546 02547 printf("</td>\n"); 02548 02549 printf("<td valign=top align=right width=33%%></td>\n"); 02550 02551 printf("</tr>\n"); 02552 printf("</table>\n"); 02553 02554 printf("</P>\n"); 02555 02556 02557 printf("<DIV ALIGN=center>\n"); 02558 printf("<table border=1 CLASS='status'>\n"); 02559 02560 printf("<TR>\n"); 02561 printf("<TH CLASS='status'>Service Group</TH><TH CLASS='status'>Host Status Summary</TH><TH CLASS='status'>Service Status Summary</TH>\n"); 02562 printf("</TR>\n"); 02563 } 02564 02565 /* display status summary for all servicegroups */ 02566 if(show_all_servicegroups==TRUE){ 02567 02568 /* loop through all servicegroups... */ 02569 for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){ 02570 02571 /* make sure the user is authorized to view at least one host in this servicegroup */ 02572 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE) 02573 continue; 02574 02575 if(odd==0) 02576 odd=1; 02577 else 02578 odd=0; 02579 02580 if(content_type==JSON_CONTENT){ 02581 // always add a comma, except for the first line 02582 if (json_start==FALSE) 02583 printf(",\n"); 02584 json_start=FALSE; 02585 } 02586 02587 /* show summary for this servicegroup */ 02588 show_servicegroup_summary(temp_servicegroup,odd); 02589 02590 user_has_seen_something=TRUE; 02591 } 02592 02593 } 02594 02595 /* else just show summary for a specific servicegroup */ 02596 else{ 02597 temp_servicegroup=find_servicegroup(servicegroup_name); 02598 if(temp_servicegroup==NULL) 02599 servicegroup_error=TRUE; 02600 else{ 02601 show_servicegroup_summary(temp_servicegroup,1); 02602 user_has_seen_something=TRUE; 02603 } 02604 } 02605 02606 if(content_type==JSON_CONTENT) 02607 printf(" ]\n"); 02608 else { 02609 printf("</TABLE>\n"); 02610 printf("</DIV>\n"); 02611 } 02612 02613 /* if user couldn't see anything, print out some helpful info... */ 02614 if(user_has_seen_something==FALSE && servicegroup_error==FALSE){ 02615 02616 if(content_type==JSON_CONTENT) 02617 printf(",\n"); 02618 02619 if(servicegroup_list!=NULL) 02620 print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 02621 else 02622 print_generic_error_message("There are no service groups defined.",NULL,0); 02623 } 02624 02625 /* we couldn't find the servicegroup */ 02626 else if(servicegroup_error==TRUE){ 02627 if(content_type==JSON_CONTENT) 02628 printf(",\n"); 02629 02630 snprintf(error_text,sizeof(error_text),"Sorry, but servicegroup '%s' doesn't seem to exist...",servicegroup_name); 02631 error_text[sizeof(error_text)-1]='\x0'; 02632 print_generic_error_message(error_text,NULL,0); 02633 } 02634 02635 return; 02636 } 02637 02638 02639 /* displays status summary information for a specific servicegroup */ 02640 void show_servicegroup_summary(servicegroup *temp_servicegroup,int odd){ 02641 char *status_bg_class=""; 02642 02643 if(content_type==JSON_CONTENT) { 02644 printf("{ \"servicegroup_name\": \"%s\",\n",json_encode(temp_servicegroup->group_name)); 02645 show_servicegroup_host_totals_summary(temp_servicegroup); 02646 show_servicegroup_service_totals_summary(temp_servicegroup); 02647 printf("}\n"); 02648 }else{ 02649 if(odd==1) 02650 status_bg_class="Even"; 02651 else 02652 status_bg_class="Odd"; 02653 02654 printf("<TR CLASS='status%s'><TD CLASS='status%s'>\n",status_bg_class,status_bg_class); 02655 printf("<A HREF='%s?servicegroup=%s&style=overview'>%s</A> ",STATUS_CGI,url_encode(temp_servicegroup->group_name),temp_servicegroup->alias); 02656 printf("(<A HREF='%s?type=%d&servicegroup=%s'>%s</a>)",EXTINFO_CGI,DISPLAY_SERVICEGROUP_INFO,url_encode(temp_servicegroup->group_name),temp_servicegroup->group_name); 02657 printf("</TD>"); 02658 02659 printf("<TD CLASS='status%s' ALIGN=CENTER VALIGN=CENTER>",status_bg_class); 02660 show_servicegroup_host_totals_summary(temp_servicegroup); 02661 printf("</TD>"); 02662 02663 printf("<TD CLASS='status%s' ALIGN=CENTER VALIGN=CENTER>",status_bg_class); 02664 show_servicegroup_service_totals_summary(temp_servicegroup); 02665 printf("</TD>"); 02666 02667 printf("</TR>\n"); 02668 } 02669 02670 return; 02671 } 02672 02673 02674 /* shows host total summary information for a specific servicegroup */ 02675 void show_servicegroup_host_totals_summary(servicegroup *temp_servicegroup){ 02676 servicesmember *temp_member; 02677 int hosts_up=0; 02678 int hosts_down=0; 02679 int hosts_unreachable=0; 02680 int hosts_pending=0; 02681 int hosts_down_scheduled=0; 02682 int hosts_down_acknowledged=0; 02683 int hosts_down_disabled=0; 02684 int hosts_down_unacknowledged=0; 02685 int hosts_unreachable_scheduled=0; 02686 int hosts_unreachable_acknowledged=0; 02687 int hosts_unreachable_disabled=0; 02688 int hosts_unreachable_unacknowledged=0; 02689 hoststatus *temp_hoststatus=NULL; 02690 host *temp_host=NULL; 02691 host *last_host=NULL; 02692 int problem=FALSE; 02693 02694 /* find all the hosts that belong to the servicegroup */ 02695 for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){ 02696 02697 /* find the host... */ 02698 temp_host=find_host(temp_member->host_name); 02699 if(temp_host==NULL) 02700 continue; 02701 02702 /* skip this if it isn't a new host... */ 02703 if(temp_host==last_host) 02704 continue; 02705 02706 /* find the host status */ 02707 temp_hoststatus=find_hoststatus(temp_host->name); 02708 if(temp_hoststatus==NULL) 02709 continue; 02710 02711 /* make sure we only display hosts of the specified status levels */ 02712 if(!(host_status_types & temp_hoststatus->status)) 02713 continue; 02714 02715 /* make sure we only display hosts that have the desired properties */ 02716 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 02717 continue; 02718 02719 problem=TRUE; 02720 02721 if(temp_hoststatus->status==HOST_UP) 02722 hosts_up++; 02723 02724 else if(temp_hoststatus->status==HOST_DOWN){ 02725 if(temp_hoststatus->scheduled_downtime_depth>0){ 02726 hosts_down_scheduled++; 02727 problem=FALSE; 02728 } 02729 if(temp_hoststatus->problem_has_been_acknowledged==TRUE){ 02730 hosts_down_acknowledged++; 02731 problem=FALSE; 02732 } 02733 if(temp_hoststatus->checks_enabled==FALSE){ 02734 hosts_down_disabled++; 02735 problem=FALSE; 02736 } 02737 if(problem==TRUE) 02738 hosts_down_unacknowledged++; 02739 hosts_down++; 02740 } 02741 02742 else if(temp_hoststatus->status==HOST_UNREACHABLE){ 02743 if(temp_hoststatus->scheduled_downtime_depth>0){ 02744 hosts_unreachable_scheduled++; 02745 problem=FALSE; 02746 } 02747 if(temp_hoststatus->problem_has_been_acknowledged==TRUE){ 02748 hosts_unreachable_acknowledged++; 02749 problem=FALSE; 02750 } 02751 if(temp_hoststatus->checks_enabled==FALSE){ 02752 hosts_unreachable_disabled++; 02753 problem=FALSE; 02754 } 02755 if(problem==TRUE) 02756 hosts_unreachable_unacknowledged++; 02757 hosts_unreachable++; 02758 }else 02759 hosts_pending++; 02760 02761 last_host=temp_host; 02762 } 02763 02764 if(content_type==JSON_CONTENT) { 02765 printf("\"hosts_up\": %d, ",hosts_up); 02766 printf("\"hosts_down\": %d, ",hosts_down); 02767 printf("\"hosts_down_unacknowledged\": %d, ",hosts_down_unacknowledged); 02768 printf("\"hosts_down_scheduled\": %d, ",hosts_down_scheduled); 02769 printf("\"hosts_down_acknowledged\": %d, ",hosts_down_acknowledged); 02770 printf("\"hosts_down_disabled\": %d, ",hosts_down_disabled); 02771 printf("\"hosts_unreachable\": %d, ",hosts_unreachable); 02772 printf("\"hosts_unreachable_unacknowledged\": %d, ",hosts_unreachable_unacknowledged); 02773 printf("\"hosts_unreachable_scheduled\": %d, ",hosts_unreachable_scheduled); 02774 printf("\"hosts_unreachable_acknowledged\": %d, ",hosts_unreachable_acknowledged); 02775 printf("\"hosts_unreachable_disabled\": %d, ",hosts_unreachable_disabled); 02776 printf("\"hosts_pending\": %d, ",hosts_pending); 02777 }else{ 02778 printf("<TABLE BORDER='0'>\n"); 02779 02780 if(hosts_up>0){ 02781 printf("<TR>"); 02782 printf("<TD CLASS='miniStatusUP'><A HREF='%s?servicegroup=%s&style=detail&&hoststatustypes=%d&hostprops=%lu'>%d UP</A></TD>",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_UP,host_properties,hosts_up); 02783 printf("</TR>\n"); 02784 } 02785 02786 if(hosts_down>0){ 02787 printf("<TR>\n"); 02788 printf("<TD CLASS='miniStatusDOWN'><TABLE BORDER='0'>\n"); 02789 printf("<TR>\n"); 02790 02791 printf("<TD CLASS='miniStatusDOWN'><A HREF='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%lu'>%d DOWN</A> :</TD>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_DOWN,host_properties,hosts_down); 02792 02793 printf("<TD><TABLE BORDER='0'>\n"); 02794 02795 if(hosts_down_unacknowledged>0) 02796 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_DOWN,HOST_NO_SCHEDULED_DOWNTIME|HOST_STATE_UNACKNOWLEDGED|HOST_CHECKS_ENABLED,hosts_down_unacknowledged); 02797 02798 if(hosts_down_scheduled>0) 02799 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_DOWN,HOST_SCHEDULED_DOWNTIME,hosts_down_scheduled); 02800 02801 if(hosts_down_acknowledged>0) 02802 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_DOWN,HOST_STATE_ACKNOWLEDGED,hosts_down_acknowledged); 02803 02804 if(hosts_down_disabled>0) 02805 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_DOWN,HOST_CHECKS_DISABLED,hosts_down_disabled); 02806 02807 printf("</TABLE></TD>\n"); 02808 02809 printf("</TR>\n"); 02810 printf("</TABLE></TD>\n"); 02811 printf("</TR>\n"); 02812 } 02813 02814 if(hosts_unreachable>0){ 02815 printf("<TR>\n"); 02816 printf("<TD CLASS='miniStatusUNREACHABLE'><TABLE BORDER='0'>\n"); 02817 printf("<TR>\n"); 02818 02819 printf("<TD CLASS='miniStatusUNREACHABLE'><A HREF='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%lu'>%d UNREACHABLE</A> :</TD>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_UNREACHABLE,host_properties,hosts_unreachable); 02820 02821 printf("<TD><TABLE BORDER='0'>\n"); 02822 02823 if(hosts_unreachable_unacknowledged>0) 02824 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_UNREACHABLE,HOST_NO_SCHEDULED_DOWNTIME|HOST_STATE_UNACKNOWLEDGED|HOST_CHECKS_ENABLED,hosts_unreachable_unacknowledged); 02825 02826 if(hosts_unreachable_scheduled>0) 02827 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_UNREACHABLE,HOST_SCHEDULED_DOWNTIME,hosts_unreachable_scheduled); 02828 02829 if(hosts_unreachable_acknowledged>0) 02830 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_UNREACHABLE,HOST_STATE_ACKNOWLEDGED,hosts_unreachable_acknowledged); 02831 02832 if(hosts_unreachable_disabled>0) 02833 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_UNREACHABLE,HOST_CHECKS_DISABLED,hosts_unreachable_disabled); 02834 02835 printf("</TABLE></TD>\n"); 02836 02837 printf("</TR>\n"); 02838 printf("</TABLE></TD>\n"); 02839 printf("</TR>\n"); 02840 } 02841 02842 if(hosts_pending>0) 02843 printf("<TR><TD CLASS='miniStatusPENDING'><A HREF='%s?servicegroup=%s&style=detail&hoststatustypes=%d&hostprops=%lu'>%d PENDING</A></TD></TR>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),HOST_PENDING,host_properties,hosts_pending); 02844 02845 printf("</TABLE>\n"); 02846 02847 if((hosts_up + hosts_down + hosts_unreachable + hosts_pending)==0) 02848 printf("No matching hosts"); 02849 } 02850 02851 return; 02852 } 02853 02854 02855 /* shows service total summary information for a specific servicegroup */ 02856 void show_servicegroup_service_totals_summary(servicegroup *temp_servicegroup){ 02857 int services_ok=0; 02858 int services_warning=0; 02859 int services_unknown=0; 02860 int services_critical=0; 02861 int services_pending=0; 02862 int services_warning_host_problem=0; 02863 int services_warning_scheduled=0; 02864 int services_warning_acknowledged=0; 02865 int services_warning_disabled=0; 02866 int services_warning_unacknowledged=0; 02867 int services_unknown_host_problem=0; 02868 int services_unknown_scheduled=0; 02869 int services_unknown_acknowledged=0; 02870 int services_unknown_disabled=0; 02871 int services_unknown_unacknowledged=0; 02872 int services_critical_host_problem=0; 02873 int services_critical_scheduled=0; 02874 int services_critical_acknowledged=0; 02875 int services_critical_disabled=0; 02876 int services_critical_unacknowledged=0; 02877 servicesmember *temp_member=NULL; 02878 servicestatus *temp_servicestatus=NULL; 02879 hoststatus *temp_hoststatus=NULL; 02880 service *temp_service=NULL; 02881 int problem=FALSE; 02882 02883 02884 /* find all the services that belong to the servicegroup */ 02885 for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){ 02886 02887 /* find the service */ 02888 temp_service=find_service(temp_member->host_name,temp_member->service_description); 02889 if(temp_service==NULL) 02890 continue; 02891 02892 /* find the service status */ 02893 temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description); 02894 if(temp_servicestatus==NULL) 02895 continue; 02896 02897 /* find the status of the associated host */ 02898 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 02899 if(temp_hoststatus==NULL) 02900 continue; 02901 02902 /* make sure we only display hosts of the specified status levels */ 02903 if(!(host_status_types & temp_hoststatus->status)) 02904 continue; 02905 02906 /* make sure we only display hosts that have the desired properties */ 02907 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 02908 continue; 02909 02910 /* make sure we only display services of the specified status levels */ 02911 if(!(service_status_types & temp_servicestatus->status)) 02912 continue; 02913 02914 /* make sure we only display services that have the desired properties */ 02915 if(passes_service_properties_filter(temp_servicestatus)==FALSE) 02916 continue; 02917 02918 problem=TRUE; 02919 02920 if(temp_servicestatus->status==SERVICE_OK) 02921 services_ok++; 02922 02923 else if(temp_servicestatus->status==SERVICE_WARNING){ 02924 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 02925 if(temp_hoststatus!=NULL && (temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)){ 02926 services_warning_host_problem++; 02927 problem=FALSE; 02928 } 02929 if(temp_servicestatus->scheduled_downtime_depth>0){ 02930 services_warning_scheduled++; 02931 problem=FALSE; 02932 } 02933 if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ 02934 services_warning_acknowledged++; 02935 problem=FALSE; 02936 } 02937 if(temp_servicestatus->checks_enabled==FALSE){ 02938 services_warning_disabled++; 02939 problem=FALSE; 02940 } 02941 if(problem==TRUE) 02942 services_warning_unacknowledged++; 02943 services_warning++; 02944 } 02945 02946 else if(temp_servicestatus->status==SERVICE_UNKNOWN){ 02947 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 02948 if(temp_hoststatus!=NULL && (temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)){ 02949 services_unknown_host_problem++; 02950 problem=FALSE; 02951 } 02952 if(temp_servicestatus->scheduled_downtime_depth>0){ 02953 services_unknown_scheduled++; 02954 problem=FALSE; 02955 } 02956 if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ 02957 services_unknown_acknowledged++; 02958 problem=FALSE; 02959 } 02960 if(temp_servicestatus->checks_enabled==FALSE){ 02961 services_unknown_disabled++; 02962 problem=FALSE; 02963 } 02964 if(problem==TRUE) 02965 services_unknown_unacknowledged++; 02966 services_unknown++; 02967 } 02968 02969 else if(temp_servicestatus->status==SERVICE_CRITICAL){ 02970 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 02971 if(temp_hoststatus!=NULL && (temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)){ 02972 services_critical_host_problem++; 02973 problem=FALSE; 02974 } 02975 if(temp_servicestatus->scheduled_downtime_depth>0){ 02976 services_critical_scheduled++; 02977 problem=FALSE; 02978 } 02979 if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ 02980 services_critical_acknowledged++; 02981 problem=FALSE; 02982 } 02983 if(temp_servicestatus->checks_enabled==FALSE){ 02984 services_critical_disabled++; 02985 problem=FALSE; 02986 } 02987 if(problem==TRUE) 02988 services_critical_unacknowledged++; 02989 services_critical++; 02990 } 02991 02992 else if(temp_servicestatus->status==SERVICE_PENDING) 02993 services_pending++; 02994 } 02995 02996 if(content_type==JSON_CONTENT) { 02997 printf("\"services_ok\": %d, ",services_ok); 02998 printf("\"services_warning\": %d, ",services_warning); 02999 printf("\"services_warning_unacknowledged\": %d, ",services_warning_unacknowledged); 03000 printf("\"services_warning_host_problem\": %d, ",services_warning_host_problem); 03001 printf("\"services_warning_scheduled\": %d, ",services_warning_scheduled); 03002 printf("\"services_warning_acknowledged\": %d, ",services_warning_acknowledged); 03003 printf("\"services_warning_disabled\": %d, ",services_warning_disabled); 03004 printf("\"services_unknown\": %d, ",services_unknown); 03005 printf("\"services_unknown_unacknowledged\": %d, ",services_unknown_unacknowledged); 03006 printf("\"services_unknown_host_problem\": %d, ",services_unknown_host_problem); 03007 printf("\"services_unknown_scheduled\": %d, ",services_unknown_scheduled); 03008 printf("\"services_unknown_acknowledged\": %d, ",services_unknown_acknowledged); 03009 printf("\"services_unknown_disabled\": %d, ",services_unknown_disabled); 03010 printf("\"services_critical\": %d, ",services_critical); 03011 printf("\"services_critical_unacknowledged\": %d, ",services_critical_unacknowledged); 03012 printf("\"services_critical_host_problem\": %d, ",services_critical_host_problem); 03013 printf("\"services_critical_scheduled\": %d, ",services_critical_scheduled); 03014 printf("\"services_critical_acknowledged\": %d, ",services_critical_acknowledged); 03015 printf("\"services_critical_disabled\": %d, ",services_critical_disabled); 03016 printf("\"services_pending\": %d ",services_pending); 03017 }else{ 03018 printf("<TABLE BORDER=0>\n"); 03019 03020 if(services_ok>0) 03021 printf("<TR><TD CLASS='miniStatusOK'><A HREF='%s?servicegroup=%s&style=detail&&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d OK</A></TD></TR>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_OK,host_status_types,service_properties,host_properties,services_ok); 03022 03023 if(services_warning>0){ 03024 printf("<TR>\n"); 03025 printf("<TD CLASS='miniStatusWARNING'><TABLE BORDER='0'>\n"); 03026 printf("<TR>\n"); 03027 03028 printf("<TD CLASS='miniStatusWARNING'><A HREF='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d WARNING</A> :</TD>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_WARNING,host_status_types,service_properties,host_properties,services_warning); 03029 03030 printf("<TD><TABLE BORDER='0'>\n"); 03031 03032 if(services_warning_unacknowledged>0) 03033 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_WARNING,HOST_UP|HOST_PENDING,SERVICE_NO_SCHEDULED_DOWNTIME|SERVICE_STATE_UNACKNOWLEDGED|SERVICE_CHECKS_ENABLED,services_warning_unacknowledged); 03034 03035 if(services_warning_host_problem>0) 03036 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_WARNING,HOST_DOWN|HOST_UNREACHABLE,services_warning_host_problem); 03037 03038 if(services_warning_scheduled>0) 03039 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_WARNING,SERVICE_SCHEDULED_DOWNTIME,services_warning_scheduled); 03040 03041 if(services_warning_acknowledged>0) 03042 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_WARNING,SERVICE_STATE_ACKNOWLEDGED,services_warning_acknowledged); 03043 03044 if(services_warning_disabled>0) 03045 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_WARNING,SERVICE_CHECKS_DISABLED,services_warning_disabled); 03046 03047 printf("</TABLE></TD>\n"); 03048 03049 printf("</TR>\n"); 03050 printf("</TABLE></TD>\n"); 03051 printf("</TR>\n"); 03052 } 03053 03054 if(services_unknown>0){ 03055 printf("<TR>\n"); 03056 printf("<TD CLASS='miniStatusUNKNOWN'><TABLE BORDER='0'>\n"); 03057 printf("<TR>\n"); 03058 03059 printf("<TD CLASS='miniStatusUNKNOWN'><A HREF='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d UNKNOWN</A> :</TD>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_UNKNOWN,host_status_types,service_properties,host_properties,services_unknown); 03060 03061 printf("<TD><TABLE BORDER='0'>\n"); 03062 03063 if(services_unknown_unacknowledged>0) 03064 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_UNKNOWN,HOST_UP|HOST_PENDING,SERVICE_NO_SCHEDULED_DOWNTIME|SERVICE_STATE_UNACKNOWLEDGED|SERVICE_CHECKS_ENABLED,services_unknown_unacknowledged); 03065 03066 if(services_unknown_host_problem>0) 03067 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_UNKNOWN,HOST_DOWN|HOST_UNREACHABLE,services_unknown_host_problem); 03068 03069 if(services_unknown_scheduled>0) 03070 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_UNKNOWN,SERVICE_SCHEDULED_DOWNTIME,services_unknown_scheduled); 03071 03072 if(services_unknown_acknowledged>0) 03073 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_UNKNOWN,SERVICE_STATE_ACKNOWLEDGED,services_unknown_acknowledged); 03074 03075 if(services_unknown_disabled>0) 03076 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_UNKNOWN,SERVICE_CHECKS_DISABLED,services_unknown_disabled); 03077 03078 printf("</TABLE></TD>\n"); 03079 03080 printf("</TR>\n"); 03081 printf("</TABLE></TD>\n"); 03082 printf("</TR>\n"); 03083 } 03084 03085 if(services_critical>0){ 03086 printf("<TR>\n"); 03087 printf("<TD CLASS='miniStatusCRITICAL'><TABLE BORDER='0'>\n"); 03088 printf("<TR>\n"); 03089 03090 printf("<TD CLASS='miniStatusCRITICAL'><A HREF='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d CRITICAL</A> :</TD>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_CRITICAL,host_status_types,service_properties,host_properties,services_critical); 03091 03092 printf("<TD><TABLE BORDER='0'>\n"); 03093 03094 if(services_critical_unacknowledged>0) 03095 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_CRITICAL,HOST_UP|HOST_PENDING,SERVICE_NO_SCHEDULED_DOWNTIME|SERVICE_STATE_UNACKNOWLEDGED|SERVICE_CHECKS_ENABLED,services_critical_unacknowledged); 03096 03097 if(services_critical_host_problem>0) 03098 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_CRITICAL,HOST_DOWN|HOST_UNREACHABLE,services_critical_host_problem); 03099 03100 if(services_critical_scheduled>0) 03101 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_CRITICAL,SERVICE_SCHEDULED_DOWNTIME,services_critical_scheduled); 03102 03103 if(services_critical_acknowledged>0) 03104 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_CRITICAL,SERVICE_STATE_ACKNOWLEDGED,services_critical_acknowledged); 03105 03106 if(services_critical_disabled>0) 03107 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?servicegroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_CRITICAL,SERVICE_CHECKS_DISABLED,services_critical_disabled); 03108 03109 printf("</TABLE></TD>\n"); 03110 03111 printf("</TR>\n"); 03112 printf("</TABLE></TD>\n"); 03113 printf("</TR>\n"); 03114 } 03115 03116 if(services_pending>0) 03117 printf("<TR><TD CLASS='miniStatusPENDING'><A HREF='%s?servicegroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d PENDING</A></TD></TR>\n",STATUS_CGI,url_encode(temp_servicegroup->group_name),SERVICE_PENDING,host_status_types,service_properties,host_properties,services_pending); 03118 03119 printf("</TABLE>\n"); 03120 03121 if((services_ok + services_warning + services_unknown + services_critical + services_pending)==0) 03122 printf("No matching services"); 03123 } 03124 03125 return; 03126 } 03127 03128 03129 /* show a grid layout of servicegroup(s)... */ 03130 void show_servicegroup_grids(void){ 03131 servicegroup *temp_servicegroup=NULL; 03132 int user_has_seen_something=FALSE; 03133 int servicegroup_error=FALSE; 03134 int odd=0; 03135 char error_text[MAX_INPUT_BUFFER]=""; 03136 int json_start=TRUE; 03137 03138 if(content_type==JSON_CONTENT) { 03139 printf("\"servicegroup_grid\": [\n"); 03140 }else{ 03141 printf("<P>\n"); 03142 03143 printf("<table border=0 width=100%%>\n"); 03144 printf("<tr>\n"); 03145 03146 printf("<td valign=top align=left width=33%%>\n"); 03147 03148 show_filters(); 03149 03150 printf("</td>"); 03151 03152 printf("<td valign=top align=center width=33%%>\n"); 03153 03154 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Status Grid For "); 03155 if(show_all_servicegroups==TRUE) 03156 printf("All Service Groups"); 03157 else 03158 printf("Service Group '%s'",servicegroup_name); 03159 printf("</DIV>\n"); 03160 03161 printf("<br>"); 03162 03163 printf("</td>\n"); 03164 03165 printf("<td valign=top align=right width=33%%></td>\n"); 03166 03167 printf("</tr>\n"); 03168 printf("</table>\n"); 03169 03170 printf("</P>\n"); 03171 } 03172 03173 /* display status grids for all servicegroups */ 03174 if(show_all_servicegroups==TRUE){ 03175 03176 /* loop through all servicegroups... */ 03177 for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){ 03178 03179 /* make sure the user is authorized to view at least one host in this servicegroup */ 03180 if(is_authorized_for_servicegroup(temp_servicegroup,¤t_authdata)==FALSE) 03181 continue; 03182 03183 if(odd==0) 03184 odd=1; 03185 else 03186 odd=0; 03187 03188 if(content_type==JSON_CONTENT){ 03189 // always add a comma, except for the first line 03190 if (json_start==FALSE) 03191 printf(",\n"); 03192 json_start=FALSE; 03193 } 03194 03195 /* show grid for this servicegroup */ 03196 show_servicegroup_grid(temp_servicegroup); 03197 03198 user_has_seen_something=TRUE; 03199 } 03200 03201 } 03202 03203 /* else just show grid for a specific servicegroup */ 03204 else{ 03205 temp_servicegroup=find_servicegroup(servicegroup_name); 03206 if(temp_servicegroup==NULL) 03207 servicegroup_error=TRUE; 03208 else{ 03209 show_servicegroup_grid(temp_servicegroup); 03210 user_has_seen_something=TRUE; 03211 } 03212 } 03213 03214 if(content_type==JSON_CONTENT) 03215 printf(" ]\n"); 03216 03217 /* if user couldn't see anything, print out some helpful info... */ 03218 if(user_has_seen_something==FALSE && servicegroup_error==FALSE){ 03219 03220 if(content_type==JSON_CONTENT) 03221 printf(",\n"); 03222 03223 if(servicegroup_list!=NULL) 03224 print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 03225 else 03226 print_generic_error_message("There are no service groups defined.",NULL,0); 03227 } 03228 03229 /* we couldn't find the servicegroup */ 03230 else if(servicegroup_error==TRUE){ 03231 if(content_type==JSON_CONTENT) 03232 printf(",\n"); 03233 03234 snprintf(error_text,sizeof(error_text),"Sorry, but servicegroup '%s' doesn't seem to exist...",servicegroup_name); 03235 error_text[sizeof(error_text)-1]='\x0'; 03236 print_generic_error_message(error_text,NULL,0); 03237 } 03238 03239 return; 03240 } 03241 03242 03243 /* displays status grid for a specific servicegroup */ 03244 void show_servicegroup_grid(servicegroup *temp_servicegroup){ 03245 char *status_bg_class=""; 03246 char *status=""; 03247 char *host_status_class=""; 03248 char *service_status_class=""; 03249 char *processed_string=NULL; 03250 servicesmember *temp_member; 03251 servicesmember *temp_member2; 03252 host *temp_host; 03253 host *last_host; 03254 hoststatus *temp_hoststatus; 03255 servicestatus *temp_servicestatus; 03256 int odd=0; 03257 int current_item; 03258 int json_start=TRUE; 03259 int json_start2=TRUE; 03260 03261 if(content_type==JSON_CONTENT){ 03262 printf("{ \"servicegroup_name\": \"%s\",\n",json_encode(temp_servicegroup->group_name)); 03263 printf("\"members\": [ \n"); 03264 }else{ 03265 printf("<P>\n"); 03266 printf("<DIV ALIGN=CENTER>\n"); 03267 03268 printf("<DIV CLASS='status'><A HREF='%s?servicegroup=%s&style=detail'>%s</A>",STATUS_CGI,url_encode(temp_servicegroup->group_name),temp_servicegroup->alias); 03269 printf(" (<A HREF='%s?type=%d&servicegroup=%s'>%s</A>)</DIV>",EXTINFO_CGI,DISPLAY_SERVICEGROUP_INFO,url_encode(temp_servicegroup->group_name),temp_servicegroup->group_name); 03270 03271 printf("<TABLE BORDER=1 CLASS='status' ALIGN=CENTER>\n"); 03272 printf("<TR><TH CLASS='status'>Host</TH><TH CLASS='status'>Services</a></TH><TH CLASS='status'>Actions</TH></TR>\n"); 03273 } 03274 03275 /* find all hosts that have services that are members of the servicegroup */ 03276 last_host=NULL; 03277 for(temp_member=temp_servicegroup->members;temp_member!=NULL;temp_member=temp_member->next){ 03278 03279 /* find the host */ 03280 temp_host=find_host(temp_member->host_name); 03281 if(temp_host==NULL) 03282 continue; 03283 03284 /* get the status of the host */ 03285 temp_hoststatus=find_hoststatus(temp_host->name); 03286 if(temp_hoststatus==NULL) 03287 continue; 03288 03289 /* skip this if it isn't a new host... */ 03290 if(temp_host==last_host) 03291 continue; 03292 03293 if(odd==1){ 03294 status_bg_class="Even"; 03295 odd=0; 03296 }else{ 03297 status_bg_class="Odd"; 03298 odd=1; 03299 } 03300 03301 if(content_type!=JSON_CONTENT) 03302 printf("<TR CLASS='status%s'>\n",status_bg_class); 03303 03304 if(temp_hoststatus->status==HOST_DOWN) { 03305 status="DOWN"; 03306 host_status_class="HOSTDOWN"; 03307 }else if(temp_hoststatus->status==HOST_UNREACHABLE){ 03308 status="UNREACHABLE"; 03309 host_status_class="HOSTUNREACHABLE"; 03310 }else{ 03311 status="OK"; 03312 host_status_class=status_bg_class; 03313 } 03314 03315 if(content_type==JSON_CONTENT) { 03316 if (json_start==FALSE) 03317 printf(",\n"); 03318 json_start=FALSE; 03319 03320 printf("{ \"host_name\": \"%s\",\n",json_encode(temp_host->name)); 03321 printf("\"host_status\": \"%s\",\n",status); 03322 printf("\"services\": [ \n"); 03323 }else{ 03324 printf("<TD CLASS='status%s'>",host_status_class); 03325 03326 printf("<TABLE BORDER=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n"); 03327 printf("<TR>\n"); 03328 printf("<TD ALIGN=LEFT>\n"); 03329 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 03330 printf("<TR>\n"); 03331 printf("<TD align=left valign=center CLASS='status%s'>",host_status_class); 03332 printf("<A HREF='%s?type=%d&host=%s'>%s</A>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_host->name),(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 03333 printf("</TD>\n"); 03334 printf("</TR>\n"); 03335 printf("</TABLE>\n"); 03336 printf("</TD>\n"); 03337 printf("<TD align=right valign=center nowrap>\n"); 03338 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 03339 printf("<TR>\n"); 03340 03341 if(temp_host->icon_image!=NULL){ 03342 printf("<TD align=center valign=center>"); 03343 printf("<A HREF='%s?type=%d&host=%s'>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_host->name)); 03344 printf("<IMG SRC='%s",url_logo_images_path); 03345 process_macros_r(mac, temp_host->icon_image,&processed_string,0); 03346 printf("%s",processed_string); 03347 free(processed_string); 03348 printf("' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt); 03349 printf("</A>"); 03350 printf("<TD>\n"); 03351 } 03352 03353 printf("</TR>\n"); 03354 printf("</TABLE>\n"); 03355 printf("</TD>\n"); 03356 printf("</TR>\n"); 03357 printf("</TABLE>\n"); 03358 03359 printf("</TD>\n"); 03360 03361 printf("<TD CLASS='status%s'>",host_status_class); 03362 } 03363 03364 /* display all services on the host that are part of the hostgroup */ 03365 current_item=1; 03366 json_start2=TRUE; 03367 for(temp_member2=temp_member;temp_member2!=NULL;temp_member2=temp_member2->next){ 03368 03369 /* bail out if we've reached the end of the services that are associated with this servicegroup */ 03370 if(strcmp(temp_member2->host_name,temp_host->name)) 03371 break; 03372 03373 /* get the status of the service */ 03374 temp_servicestatus=find_servicestatus(temp_member2->host_name,temp_member2->service_description); 03375 if(temp_servicestatus==NULL) 03376 service_status_class="NULL"; 03377 else if(temp_servicestatus->status==SERVICE_OK) 03378 service_status_class="OK"; 03379 else if(temp_servicestatus->status==SERVICE_WARNING) 03380 service_status_class="WARNING"; 03381 else if(temp_servicestatus->status==SERVICE_UNKNOWN) 03382 service_status_class="UNKNOWN"; 03383 else if(temp_servicestatus->status==SERVICE_CRITICAL) 03384 service_status_class="CRITICAL"; 03385 else 03386 service_status_class="PENDING"; 03387 03388 if(content_type==JSON_CONTENT) { 03389 if (json_start2==FALSE) 03390 printf(",\n"); 03391 json_start2=FALSE; 03392 03393 printf("{ \"service_description\": \"%s\",\n",json_encode(temp_servicestatus->description)); 03394 if(temp_servicestatus==NULL) 03395 printf("\"service_status\": null } "); 03396 else 03397 printf("\"service_status\": \"%s\" } ",service_status_class); 03398 }else{ 03399 if(current_item>max_grid_width && max_grid_width>0){ 03400 printf("<BR>\n"); 03401 current_item=1; 03402 } 03403 03404 printf("<A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_servicestatus->host_name)); 03405 printf("&service=%s' CLASS='status%s'>%s</A> ",url_encode(temp_servicestatus->description),service_status_class,temp_servicestatus->description); 03406 03407 current_item++; 03408 } 03409 } 03410 03411 if(content_type==JSON_CONTENT) { 03412 printf(" ] } \n"); 03413 }else{ 03414 /* actions */ 03415 printf("<TD CLASS='status%s'>",host_status_class); 03416 03417 /* grab macros */ 03418 grab_host_macros_r(mac, temp_host); 03419 03420 printf("<A HREF='%s?type=%d&host=%s'>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_host->name)); 03421 printf("<IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,DETAIL_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extended Information For This Host","View Extended Information For This Host"); 03422 printf("</A>"); 03423 03424 if(temp_host->notes_url!=NULL){ 03425 process_macros_r(mac, temp_host->notes_url,&processed_string,0); 03426 BEGIN_MULTIURL_LOOP 03427 printf("<A HREF='"); 03428 printf("%s",processed_string); 03429 printf("' TARGET='%s'>",(notes_url_target==NULL)?"_blank":notes_url_target); 03430 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,NOTES_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extra Host Notes","View Extra Host Notes"); 03431 printf("</A>"); 03432 END_MULTIURL_LOOP 03433 free(processed_string); 03434 } 03435 if(temp_host->action_url!=NULL){ 03436 process_macros_r(mac, temp_host->action_url,&processed_string,0); 03437 BEGIN_MULTIURL_LOOP 03438 printf("<A HREF='"); 03439 printf("%s",processed_string); 03440 printf("' TARGET='%s'>",(action_url_target==NULL)?"blank":action_url_target); 03441 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,ACTION_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Perform Extra Host Actions","Perform Extra Host Actions"); 03442 printf("</A>"); 03443 END_MULTIURL_LOOP 03444 free(processed_string); 03445 } 03446 03447 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>\n",STATUS_CGI,url_encode(temp_host->name),url_images_path,STATUS_DETAIL_ICON); 03448 03449 #ifdef USE_STATUSMAP 03450 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'></A>",STATUSMAP_CGI,url_encode(temp_host->name),url_images_path,STATUSMAP_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Locate Host On Map","Locate Host On Map"); 03451 #endif 03452 printf("</TD>\n"); 03453 printf("</TR>\n"); 03454 } 03455 03456 last_host=temp_host; 03457 } 03458 03459 if(content_type==JSON_CONTENT) 03460 printf(" ] } \n"); 03461 else { 03462 printf("</TABLE>\n"); 03463 printf("</DIV>\n"); 03464 printf("</P>\n"); 03465 } 03466 03467 return; 03468 } 03469 03470 03471 /* show an overview of hostgroup(s)... */ 03472 void show_hostgroup_overviews(void){ 03473 hostgroup *temp_hostgroup=NULL; 03474 int current_column; 03475 int user_has_seen_something=FALSE; 03476 int hostgroup_error=FALSE; 03477 char error_text[MAX_INPUT_BUFFER]=""; 03478 int json_start=TRUE; 03479 03480 if(content_type==JSON_CONTENT) { 03481 printf("\"hostgroup_overview\": [\n"); 03482 03483 if(show_all_hostgroups==TRUE){ 03484 for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ 03485 03486 /* make sure the user is authorized to view this hostgroup */ 03487 if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE) 03488 continue; 03489 03490 // always add a comma, except for the first line 03491 if (json_start==FALSE) 03492 printf(",\n"); 03493 json_start=FALSE; 03494 03495 show_hostgroup_overview(temp_hostgroup); 03496 03497 user_has_seen_something=TRUE; 03498 } 03499 }else{ 03500 temp_hostgroup=find_hostgroup(hostgroup_name); 03501 if(temp_hostgroup==NULL) 03502 hostgroup_error=TRUE; 03503 else { 03504 if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==TRUE){ 03505 03506 show_hostgroup_overview(temp_hostgroup); 03507 03508 user_has_seen_something=TRUE; 03509 } 03510 } 03511 } 03512 }else{ 03513 printf("<P>\n"); 03514 03515 printf("<table border=0 width=100%%>\n"); 03516 printf("<tr>\n"); 03517 03518 printf("<td valign=top align=left width=33%%>\n"); 03519 03520 show_filters(); 03521 03522 printf("</td>"); 03523 03524 printf("<td valign=top align=center width=33%%>\n"); 03525 03526 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Service Overview For "); 03527 if(show_all_hostgroups==TRUE) 03528 printf("All Host Groups"); 03529 else 03530 printf("Host Group '%s'",hostgroup_name); 03531 printf("</DIV>\n"); 03532 03533 printf("<br>"); 03534 03535 printf("</td>\n"); 03536 03537 printf("<td valign=top align=right width=33%%></td>\n"); 03538 03539 printf("</tr>\n"); 03540 printf("</table>\n"); 03541 03542 printf("</P>\n"); 03543 03544 03545 /* display status overviews for all hostgroups */ 03546 if(show_all_hostgroups==TRUE){ 03547 03548 03549 printf("<DIV ALIGN=center>\n"); 03550 printf("<TABLE BORDER=0 CELLPADDING=10>\n"); 03551 03552 current_column=1; 03553 03554 /* loop through all hostgroups... */ 03555 for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ 03556 03557 /* make sure the user is authorized to view this hostgroup */ 03558 if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE) 03559 continue; 03560 03561 if(current_column==1) 03562 printf("<TR>\n"); 03563 printf("<TD VALIGN=top ALIGN=center>\n"); 03564 03565 show_hostgroup_overview(temp_hostgroup); 03566 03567 user_has_seen_something=TRUE; 03568 03569 printf("</TD>\n"); 03570 if(current_column==overview_columns) 03571 printf("</TR>\n"); 03572 03573 if(current_column<overview_columns) 03574 current_column++; 03575 else 03576 current_column=1; 03577 } 03578 03579 if(current_column!=1){ 03580 03581 for(;current_column<=overview_columns;current_column++) 03582 printf("<TD></TD>\n"); 03583 printf("</TR>\n"); 03584 } 03585 03586 printf("</TABLE>\n"); 03587 printf("</DIV>\n"); 03588 } 03589 03590 /* else display overview for just a specific hostgroup */ 03591 else{ 03592 03593 temp_hostgroup=find_hostgroup(hostgroup_name); 03594 if(temp_hostgroup==NULL) 03595 hostgroup_error=TRUE; 03596 else { 03597 printf("<P>\n"); 03598 printf("<DIV ALIGN=CENTER>\n"); 03599 printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD ALIGN=CENTER>\n"); 03600 03601 if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==TRUE){ 03602 03603 show_hostgroup_overview(temp_hostgroup); 03604 03605 user_has_seen_something=TRUE; 03606 } 03607 03608 printf("</TD></TR></TABLE>\n"); 03609 printf("</DIV>\n"); 03610 printf("</P>\n"); 03611 } 03612 } 03613 } 03614 03615 if(content_type==JSON_CONTENT) 03616 printf(" ]\n"); 03617 03618 /* if user couldn't see anything, print out some helpful info... */ 03619 if(user_has_seen_something==FALSE && hostgroup_error==FALSE){ 03620 03621 if(content_type==JSON_CONTENT) 03622 printf(",\n"); 03623 03624 if(hostgroup_list!=NULL) 03625 print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 03626 else 03627 print_generic_error_message("There are no host groups defined.",NULL,0); 03628 } 03629 03630 /* we couldn't find the hostgroup */ 03631 else if(hostgroup_error==TRUE){ 03632 if(content_type==JSON_CONTENT) 03633 printf(",\n"); 03634 03635 snprintf(error_text,sizeof(error_text),"Sorry, but host group '%s' doesn't seem to exist...",hostgroup_name); 03636 error_text[sizeof(error_text)-1]='\x0'; 03637 print_generic_error_message(error_text,NULL,0); 03638 } 03639 03640 return; 03641 } 03642 03643 03644 /* shows an overview of a specific hostgroup... */ 03645 void show_hostgroup_overview(hostgroup *hstgrp){ 03646 hostsmember *temp_member=NULL; 03647 host *temp_host=NULL; 03648 hoststatus *temp_hoststatus=NULL; 03649 int odd=0; 03650 int json_start=TRUE; 03651 03652 /* make sure the user is authorized to view this hostgroup */ 03653 if(is_authorized_for_hostgroup(hstgrp,¤t_authdata)==FALSE) 03654 return; 03655 03656 /* print json format */ 03657 if(content_type==JSON_CONTENT) { 03658 printf("{ \"hostgroup_name\": \"%s\",\n",json_encode(hstgrp->group_name)); 03659 printf("\"members\": [ \n"); 03660 }else{ 03661 printf("<DIV CLASS='status'>\n"); 03662 printf("<A HREF='%s?hostgroup=%s&style=detail'>%s</A>",STATUS_CGI,url_encode(hstgrp->group_name),hstgrp->alias); 03663 printf(" (<A HREF='%s?type=%d&hostgroup=%s'>%s</A>)",EXTINFO_CGI,DISPLAY_HOSTGROUP_INFO,url_encode(hstgrp->group_name),hstgrp->group_name); 03664 printf("</DIV>\n"); 03665 03666 printf("<DIV CLASS='status'>\n"); 03667 printf("<table border=1 CLASS='status'>\n"); 03668 03669 printf("<TR>\n"); 03670 printf("<TH CLASS='status'>Host</TH><TH CLASS='status'>Status</TH><TH CLASS='status'>Services</TH><TH CLASS='status'>Actions</TH>\n"); 03671 printf("</TR>\n"); 03672 } 03673 03674 /* find all the hosts that belong to the hostgroup */ 03675 for(temp_member=hstgrp->members;temp_member!=NULL;temp_member=temp_member->next){ 03676 03677 /* find the host... */ 03678 temp_host=find_host(temp_member->host_name); 03679 if(temp_host==NULL) 03680 continue; 03681 03682 /* find the host status */ 03683 temp_hoststatus=find_hoststatus(temp_host->name); 03684 if(temp_hoststatus==NULL) 03685 continue; 03686 03687 /* make sure we only display hosts of the specified status levels */ 03688 if(!(host_status_types & temp_hoststatus->status)) 03689 continue; 03690 03691 /* make sure we only display hosts that have the desired properties */ 03692 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 03693 continue; 03694 03695 if(odd) 03696 odd=0; 03697 else 03698 odd=1; 03699 03700 if(content_type==JSON_CONTENT) { 03701 if (json_start==FALSE) 03702 printf(",\n"); 03703 json_start=FALSE; 03704 } 03705 03706 show_servicegroup_hostgroup_member_overview(temp_hoststatus,odd,NULL); 03707 } 03708 03709 if(content_type==JSON_CONTENT) 03710 printf(" ] }\n"); 03711 else{ 03712 printf("</table>\n"); 03713 printf("</DIV>\n"); 03714 } 03715 03716 return; 03717 } 03718 03719 03720 /* shows a host status overview... */ 03721 void show_servicegroup_hostgroup_member_overview(hoststatus *hststatus,int odd,void *data){ 03722 char status[MAX_INPUT_BUFFER]; 03723 char *status_bg_class=""; 03724 char *status_class=""; 03725 host *temp_host=NULL; 03726 char *processed_string=NULL; 03727 03728 temp_host=find_host(hststatus->host_name); 03729 03730 /* grab macros */ 03731 grab_host_macros_r(mac, temp_host); 03732 03733 if(hststatus->status==HOST_PENDING){ 03734 strncpy(status,"PENDING",sizeof(status)); 03735 status_class="HOSTPENDING"; 03736 status_bg_class=(odd)?"Even":"Odd"; 03737 } 03738 else if(hststatus->status==HOST_UP){ 03739 strncpy(status,"UP",sizeof(status)); 03740 status_class="HOSTUP"; 03741 status_bg_class=(odd)?"Even":"Odd"; 03742 } 03743 else if(hststatus->status==HOST_DOWN){ 03744 strncpy(status,"DOWN",sizeof(status)); 03745 status_class="HOSTDOWN"; 03746 status_bg_class="HOSTDOWN"; 03747 } 03748 else if(hststatus->status==HOST_UNREACHABLE){ 03749 strncpy(status,"UNREACHABLE",sizeof(status)); 03750 status_class="HOSTUNREACHABLE"; 03751 status_bg_class="HOSTUNREACHABLE"; 03752 } 03753 03754 status[sizeof(status)-1]='\x0'; 03755 03756 if(content_type==JSON_CONTENT) { 03757 printf("{ \"host_name\": \"%s\", ",json_encode(hststatus->host_name)); 03758 printf("\"host_status\": \"%s\", ",status); 03759 show_servicegroup_hostgroup_member_service_status_totals(hststatus->host_name,data); 03760 printf("}\n"); 03761 }else{ 03762 printf("<TR CLASS='status%s'>\n",status_bg_class); 03763 03764 printf("<TD CLASS='status%s'>\n",status_bg_class); 03765 03766 printf("<TABLE BORDER=0 WIDTH=100%% cellpadding=0 cellspacing=0>\n"); 03767 printf("<TR CLASS='status%s'>\n",status_bg_class); 03768 if(!strcmp(temp_host->address6,temp_host->name)) 03769 printf("<TD CLASS='status%s'><A HREF='%s?host=%s&style=detail' title='%s'>%s</A></TD>\n",status_bg_class,STATUS_CGI,url_encode(hststatus->host_name),temp_host->address,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 03770 else 03771 printf("<TD CLASS='status%s'><A HREF='%s?host=%s&style=detail' title='%s,%s'>%s</A></TD>\n",status_bg_class,STATUS_CGI,url_encode(hststatus->host_name),temp_host->address,temp_host->address6,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 03772 03773 if(temp_host->icon_image!=NULL){ 03774 printf("<TD CLASS='status%s' WIDTH=5></TD>\n",status_bg_class); 03775 printf("<TD CLASS='status%s' ALIGN=right>",status_bg_class); 03776 printf("<a href='%s?type=%d&host=%s'>",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(hststatus->host_name)); 03777 printf("<IMG SRC='%s",url_logo_images_path); 03778 process_macros_r(mac, temp_host->icon_image,&processed_string,0); 03779 printf("%s",processed_string); 03780 free(processed_string); 03781 printf("' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt); 03782 printf("</A>"); 03783 printf("</TD>\n"); 03784 } 03785 printf("</TR>\n"); 03786 printf("</TABLE>\n"); 03787 printf("</TD>\n"); 03788 03789 printf("<td CLASS='status%s'>%s</td>\n",status_class,status); 03790 03791 printf("<td CLASS='status%s'>\n",status_bg_class); 03792 show_servicegroup_hostgroup_member_service_status_totals(hststatus->host_name,data); 03793 printf("</td>\n"); 03794 03795 printf("<td valign=center CLASS='status%s'>",status_bg_class); 03796 printf("<a href='%s?type=%d&host=%s'><img src='%s%s' border=0 alt='View Extended Information For This Host' title='View Extended Information For This Host'></a>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(hststatus->host_name),url_images_path,DETAIL_ICON); 03797 03798 if(temp_host->notes_url!=NULL){ 03799 process_macros_r(mac, temp_host->notes_url,&processed_string,0); 03800 BEGIN_MULTIURL_LOOP 03801 printf("<A HREF='"); 03802 printf("%s",processed_string); 03803 printf("' TARGET='%s'>",(notes_url_target==NULL)?"_blank":notes_url_target); 03804 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,NOTES_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extra Host Notes","View Extra Host Notes"); 03805 printf("</A>"); 03806 END_MULTIURL_LOOP 03807 free(processed_string); 03808 } 03809 if(temp_host->action_url!=NULL){ 03810 process_macros_r(mac, temp_host->action_url,&processed_string,0); 03811 BEGIN_MULTIURL_LOOP 03812 printf("<A HREF='"); 03813 printf("%s",processed_string); 03814 printf("' TARGET='%s'>",(action_url_target==NULL)?"_blank":action_url_target); 03815 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,ACTION_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Perform Extra Host Actions","Perform Extra Host Actions"); 03816 printf("</A>"); 03817 END_MULTIURL_LOOP 03818 free(processed_string); 03819 } 03820 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>\n",STATUS_CGI,url_encode(hststatus->host_name),url_images_path,STATUS_DETAIL_ICON); 03821 #ifdef USE_STATUSMAP 03822 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'></A>",STATUSMAP_CGI,url_encode(hststatus->host_name),url_images_path,STATUSMAP_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Locate Host On Map","Locate Host On Map"); 03823 #endif 03824 printf("</TD>"); 03825 03826 printf("</TR>\n"); 03827 } 03828 03829 return; 03830 } 03831 03832 03833 void show_servicegroup_hostgroup_member_service_status_totals(char *host_name,void *data){ 03834 int total_ok=0; 03835 int total_warning=0; 03836 int total_unknown=0; 03837 int total_critical=0; 03838 int total_pending=0; 03839 servicestatus *temp_servicestatus; 03840 service *temp_service; 03841 servicegroup *temp_servicegroup=NULL; 03842 char temp_buffer[MAX_INPUT_BUFFER]; 03843 03844 03845 if(display_type==DISPLAY_SERVICEGROUPS) 03846 temp_servicegroup=(servicegroup *)data; 03847 03848 /* check all services... */ 03849 for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ 03850 03851 if(!strcmp(host_name,temp_servicestatus->host_name)){ 03852 03853 /* make sure the user is authorized to see this service... */ 03854 temp_service=find_service(temp_servicestatus->host_name,temp_servicestatus->description); 03855 if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) 03856 continue; 03857 03858 if(display_type==DISPLAY_SERVICEGROUPS){ 03859 03860 /* is this service a member of the servicegroup? */ 03861 if(is_service_member_of_servicegroup(temp_servicegroup,temp_service)==FALSE) 03862 continue; 03863 } 03864 03865 /* make sure we only display services of the specified status levels */ 03866 if(!(service_status_types & temp_servicestatus->status)) 03867 continue; 03868 03869 /* make sure we only display services that have the desired properties */ 03870 if(passes_service_properties_filter(temp_servicestatus)==FALSE) 03871 continue; 03872 03873 if(temp_servicestatus->status==SERVICE_CRITICAL) 03874 total_critical++; 03875 else if(temp_servicestatus->status==SERVICE_WARNING) 03876 total_warning++; 03877 else if(temp_servicestatus->status==SERVICE_UNKNOWN) 03878 total_unknown++; 03879 else if(temp_servicestatus->status==SERVICE_OK) 03880 total_ok++; 03881 else if(temp_servicestatus->status==SERVICE_PENDING) 03882 total_pending++; 03883 else 03884 total_ok++; 03885 } 03886 } 03887 03888 03889 if(content_type==JSON_CONTENT) { 03890 printf("\"services_status_ok\": %d, ",total_ok); 03891 printf("\"services_status_warning\": %d, ",total_warning); 03892 printf("\"services_status_unknown\": %d, ",total_unknown); 03893 printf("\"services_status_critical\": %d, ",total_critical); 03894 printf("\"services_status_pending\": %d ",total_pending); 03895 }else{ 03896 printf("<TABLE BORDER=0 WIDTH=100%%>\n"); 03897 03898 if(display_type==DISPLAY_SERVICEGROUPS) 03899 snprintf(temp_buffer,sizeof(temp_buffer)-1,"servicegroup=%s&style=detail",url_encode(temp_servicegroup->group_name)); 03900 else 03901 snprintf(temp_buffer,sizeof(temp_buffer)-1,"host=%s",url_encode(host_name)); 03902 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 03903 03904 if(total_ok>0) 03905 printf("<TR><TD CLASS='miniStatusOK'><A HREF='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d OK</A></TD></TR>\n",STATUS_CGI,temp_buffer,SERVICE_OK,host_status_types,service_properties,host_properties,total_ok); 03906 if(total_warning>0) 03907 printf("<TR><TD CLASS='miniStatusWARNING'><A HREF='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d WARNING</A></TD></TR>\n",STATUS_CGI,temp_buffer,SERVICE_WARNING,host_status_types,service_properties,host_properties,total_warning); 03908 if(total_unknown>0) 03909 printf("<TR><TD CLASS='miniStatusUNKNOWN'><A HREF='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d UNKNOWN</A></TD></TR>\n",STATUS_CGI,temp_buffer,SERVICE_UNKNOWN,host_status_types,service_properties,host_properties,total_unknown); 03910 if(total_critical>0) 03911 printf("<TR><TD CLASS='miniStatusCRITICAL'><A HREF='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d CRITICAL</A></TD></TR>\n",STATUS_CGI,temp_buffer,SERVICE_CRITICAL,host_status_types,service_properties,host_properties,total_critical); 03912 if(total_pending>0) 03913 printf("<TR><TD CLASS='miniStatusPENDING'><A HREF='%s?%s&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d PENDING</A></TD></TR>\n",STATUS_CGI,temp_buffer,SERVICE_PENDING,host_status_types,service_properties,host_properties,total_pending); 03914 03915 printf("</TABLE>\n"); 03916 03917 if((total_ok + total_warning + total_unknown + total_critical + total_pending)==0) 03918 printf("No matching services"); 03919 } 03920 03921 return; 03922 } 03923 03924 03925 /* show a summary of hostgroup(s)... */ 03926 void show_hostgroup_summaries(void){ 03927 hostgroup *temp_hostgroup=NULL; 03928 int user_has_seen_something=FALSE; 03929 int hostgroup_error=FALSE; 03930 int odd=0; 03931 char error_text[MAX_INPUT_BUFFER]=""; 03932 int json_start=TRUE; 03933 03934 if(content_type==JSON_CONTENT) { 03935 printf("\"hostgroup_summary\": [\n"); 03936 }else{ 03937 printf("<P>\n"); 03938 03939 printf("<table border=0 width=100%%>\n"); 03940 printf("<tr>\n"); 03941 03942 printf("<td valign=top align=left width=33%%>\n"); 03943 03944 show_filters(); 03945 03946 printf("</td>"); 03947 03948 printf("<td valign=top align=center width=33%%>\n"); 03949 03950 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Status Summary For "); 03951 if(show_all_hostgroups==TRUE) 03952 printf("All Host Groups"); 03953 else 03954 printf("Host Group '%s'",hostgroup_name); 03955 printf("</DIV>\n"); 03956 03957 printf("<br>"); 03958 03959 printf("</td>\n"); 03960 03961 printf("<td valign=top align=right width=33%%></td>\n"); 03962 03963 printf("</tr>\n"); 03964 printf("</table>\n"); 03965 03966 printf("</P>\n"); 03967 03968 03969 printf("<DIV ALIGN=center>\n"); 03970 printf("<table border=1 CLASS='status'>\n"); 03971 03972 printf("<TR>\n"); 03973 printf("<TH CLASS='status'>Host Group</TH><TH CLASS='status'>Host Status Summary</TH><TH CLASS='status'>Service Status Summary</TH>\n"); 03974 printf("</TR>\n"); 03975 } 03976 03977 /* display status summary for all hostgroups */ 03978 if(show_all_hostgroups==TRUE){ 03979 03980 /* loop through all hostgroups... */ 03981 for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ 03982 03983 /* make sure the user is authorized to view this hostgroup */ 03984 if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE) 03985 continue; 03986 03987 if(odd==0) 03988 odd=1; 03989 else 03990 odd=0; 03991 03992 if(content_type==JSON_CONTENT){ 03993 // always add a comma, except for the first line 03994 if (json_start==FALSE) 03995 printf(",\n"); 03996 json_start=FALSE; 03997 } 03998 03999 /* show summary for this hostgroup */ 04000 show_hostgroup_summary(temp_hostgroup,odd); 04001 04002 user_has_seen_something=TRUE; 04003 } 04004 04005 } 04006 04007 /* else just show summary for a specific hostgroup */ 04008 else{ 04009 temp_hostgroup=find_hostgroup(hostgroup_name); 04010 if(temp_hostgroup==NULL) 04011 hostgroup_error=TRUE; 04012 else{ 04013 show_hostgroup_summary(temp_hostgroup,1); 04014 user_has_seen_something=TRUE; 04015 } 04016 } 04017 04018 if(content_type==JSON_CONTENT) 04019 printf(" ]\n"); 04020 else { 04021 printf("</TABLE>\n"); 04022 printf("</DIV>\n"); 04023 } 04024 04025 /* if user couldn't see anything, print out some helpful info... */ 04026 if(user_has_seen_something==FALSE && hostgroup_error==FALSE){ 04027 04028 if(content_type==JSON_CONTENT) 04029 printf(",\n"); 04030 04031 if(hoststatus_list!=NULL) 04032 print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 04033 else 04034 print_generic_error_message("There are no host groups defined.",NULL,0); 04035 } 04036 04037 /* we couldn't find the hostgroup */ 04038 else if(hostgroup_error==TRUE){ 04039 if(content_type==JSON_CONTENT) 04040 printf(",\n"); 04041 04042 snprintf(error_text,sizeof(error_text),"Sorry, but host group '%s' doesn't seem to exist...",hostgroup_name); 04043 error_text[sizeof(error_text)-1]='\x0'; 04044 print_generic_error_message(error_text,NULL,0); 04045 } 04046 04047 return; 04048 } 04049 04050 04051 /* displays status summary information for a specific hostgroup */ 04052 void show_hostgroup_summary(hostgroup *temp_hostgroup,int odd){ 04053 char *status_bg_class=""; 04054 04055 if(content_type==JSON_CONTENT) { 04056 printf("{ \"hostgroup_name\": \"%s\",\n",json_encode(temp_hostgroup->group_name)); 04057 show_hostgroup_host_totals_summary(temp_hostgroup); 04058 show_hostgroup_service_totals_summary(temp_hostgroup); 04059 printf("}\n"); 04060 }else{ 04061 if(odd==1) 04062 status_bg_class="Even"; 04063 else 04064 status_bg_class="Odd"; 04065 04066 printf("<TR CLASS='status%s'><TD CLASS='status%s'>\n",status_bg_class,status_bg_class); 04067 printf("<A HREF='%s?hostgroup=%s&style=overview'>%s</A> ",STATUS_CGI,url_encode(temp_hostgroup->group_name),temp_hostgroup->alias); 04068 printf("(<A HREF='%s?type=%d&hostgroup=%s'>%s</a>)",EXTINFO_CGI,DISPLAY_HOSTGROUP_INFO,url_encode(temp_hostgroup->group_name),temp_hostgroup->group_name); 04069 printf("</TD>"); 04070 04071 printf("<TD CLASS='status%s' ALIGN=CENTER VALIGN=CENTER>",status_bg_class); 04072 show_hostgroup_host_totals_summary(temp_hostgroup); 04073 printf("</TD>"); 04074 04075 printf("<TD CLASS='status%s' ALIGN=CENTER VALIGN=CENTER>",status_bg_class); 04076 show_hostgroup_service_totals_summary(temp_hostgroup); 04077 printf("</TD>"); 04078 04079 printf("</TR>\n"); 04080 } 04081 04082 return; 04083 } 04084 04085 04086 /* shows host total summary information for a specific hostgroup */ 04087 void show_hostgroup_host_totals_summary(hostgroup *temp_hostgroup){ 04088 hostsmember *temp_member; 04089 int hosts_up=0; 04090 int hosts_down=0; 04091 int hosts_unreachable=0; 04092 int hosts_pending=0; 04093 int hosts_down_scheduled=0; 04094 int hosts_down_acknowledged=0; 04095 int hosts_down_disabled=0; 04096 int hosts_down_unacknowledged=0; 04097 int hosts_unreachable_scheduled=0; 04098 int hosts_unreachable_acknowledged=0; 04099 int hosts_unreachable_disabled=0; 04100 int hosts_unreachable_unacknowledged=0; 04101 hoststatus *temp_hoststatus; 04102 host *temp_host; 04103 int problem=FALSE; 04104 04105 /* find all the hosts that belong to the hostgroup */ 04106 for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){ 04107 04108 /* find the host... */ 04109 temp_host=find_host(temp_member->host_name); 04110 if(temp_host==NULL) 04111 continue; 04112 04113 /* find the host status */ 04114 temp_hoststatus=find_hoststatus(temp_host->name); 04115 if(temp_hoststatus==NULL) 04116 continue; 04117 04118 /* make sure we only display hosts of the specified status levels */ 04119 if(!(host_status_types & temp_hoststatus->status)) 04120 continue; 04121 04122 /* make sure we only display hosts that have the desired properties */ 04123 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 04124 continue; 04125 04126 problem=TRUE; 04127 04128 if(temp_hoststatus->status==HOST_UP) 04129 hosts_up++; 04130 04131 else if(temp_hoststatus->status==HOST_DOWN){ 04132 if(temp_hoststatus->scheduled_downtime_depth>0){ 04133 hosts_down_scheduled++; 04134 problem=FALSE; 04135 } 04136 if(temp_hoststatus->problem_has_been_acknowledged==TRUE){ 04137 hosts_down_acknowledged++; 04138 problem=FALSE; 04139 } 04140 if(temp_hoststatus->checks_enabled==FALSE){ 04141 hosts_down_disabled++; 04142 problem=FALSE; 04143 } 04144 if(problem==TRUE) 04145 hosts_down_unacknowledged++; 04146 hosts_down++; 04147 } 04148 04149 else if(temp_hoststatus->status==HOST_UNREACHABLE){ 04150 if(temp_hoststatus->scheduled_downtime_depth>0){ 04151 hosts_unreachable_scheduled++; 04152 problem=FALSE; 04153 } 04154 if(temp_hoststatus->problem_has_been_acknowledged==TRUE){ 04155 hosts_unreachable_acknowledged++; 04156 problem=FALSE; 04157 } 04158 if(temp_hoststatus->checks_enabled==FALSE){ 04159 hosts_unreachable_disabled++; 04160 problem=FALSE; 04161 } 04162 if(problem==TRUE) 04163 hosts_unreachable_unacknowledged++; 04164 hosts_unreachable++; 04165 } 04166 04167 else 04168 hosts_pending++; 04169 } 04170 04171 if(content_type==JSON_CONTENT) { 04172 printf("\"hosts_up\": %d, ",hosts_up); 04173 printf("\"hosts_down\": %d, ",hosts_down); 04174 printf("\"hosts_down_unacknowledged\": %d, ",hosts_down_unacknowledged); 04175 printf("\"hosts_down_scheduled\": %d, ",hosts_down_scheduled); 04176 printf("\"hosts_down_acknowledged\": %d, ",hosts_down_acknowledged); 04177 printf("\"hosts_down_disabled\": %d, ",hosts_down_disabled); 04178 printf("\"hosts_unreachable\": %d, ",hosts_unreachable); 04179 printf("\"hosts_unreachable_unacknowledged\": %d, ",hosts_unreachable_unacknowledged); 04180 printf("\"hosts_unreachable_scheduled\": %d, ",hosts_unreachable_scheduled); 04181 printf("\"hosts_unreachable_acknowledged\": %d, ",hosts_unreachable_acknowledged); 04182 printf("\"hosts_unreachable_disabled\": %d, ",hosts_unreachable_disabled); 04183 printf("\"hosts_pending\": %d, ",hosts_pending); 04184 }else{ 04185 printf("<TABLE BORDER='0'>\n"); 04186 04187 if(hosts_up>0){ 04188 printf("<TR>"); 04189 printf("<TD CLASS='miniStatusUP'><A HREF='%s?hostgroup=%s&style=hostdetail&&hoststatustypes=%d&hostprops=%lu'>%d UP</A></TD>",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_UP,host_properties,hosts_up); 04190 printf("</TR>\n"); 04191 } 04192 04193 if(hosts_down>0){ 04194 printf("<TR>\n"); 04195 printf("<TD CLASS='miniStatusDOWN'><TABLE BORDER='0'>\n"); 04196 printf("<TR>\n"); 04197 04198 printf("<TD CLASS='miniStatusDOWN'><A HREF='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%lu'>%d DOWN</A> :</TD>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_DOWN,host_properties,hosts_down); 04199 04200 printf("<TD><TABLE BORDER='0'>\n"); 04201 04202 if(hosts_down_unacknowledged>0) 04203 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_DOWN,HOST_NO_SCHEDULED_DOWNTIME|HOST_STATE_UNACKNOWLEDGED|HOST_CHECKS_ENABLED,hosts_down_unacknowledged); 04204 04205 if(hosts_down_scheduled>0) 04206 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_DOWN,HOST_SCHEDULED_DOWNTIME,hosts_down_scheduled); 04207 04208 if(hosts_down_acknowledged>0) 04209 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_DOWN,HOST_STATE_ACKNOWLEDGED,hosts_down_acknowledged); 04210 04211 if(hosts_down_disabled>0) 04212 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_DOWN,HOST_CHECKS_DISABLED,hosts_down_disabled); 04213 04214 printf("</TABLE></TD>\n"); 04215 04216 printf("</TR>\n"); 04217 printf("</TABLE></TD>\n"); 04218 printf("</TR>\n"); 04219 } 04220 04221 if(hosts_unreachable>0){ 04222 printf("<TR>\n"); 04223 printf("<TD CLASS='miniStatusUNREACHABLE'><TABLE BORDER='0'>\n"); 04224 printf("<TR>\n"); 04225 04226 printf("<TD CLASS='miniStatusUNREACHABLE'><A HREF='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%lu'>%d UNREACHABLE</A> :</TD>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_UNREACHABLE,host_properties,hosts_unreachable); 04227 04228 printf("<TD><TABLE BORDER='0'>\n"); 04229 04230 if(hosts_unreachable_unacknowledged>0) 04231 printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_UNREACHABLE,HOST_NO_SCHEDULED_DOWNTIME|HOST_STATE_UNACKNOWLEDGED|HOST_CHECKS_ENABLED,hosts_unreachable_unacknowledged); 04232 04233 if(hosts_unreachable_scheduled>0) 04234 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_UNREACHABLE,HOST_SCHEDULED_DOWNTIME,hosts_unreachable_scheduled); 04235 04236 if(hosts_unreachable_acknowledged>0) 04237 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_UNREACHABLE,HOST_STATE_ACKNOWLEDGED,hosts_unreachable_acknowledged); 04238 04239 if(hosts_unreachable_disabled>0) 04240 printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_UNREACHABLE,HOST_CHECKS_DISABLED,hosts_unreachable_disabled); 04241 04242 printf("</TABLE></TD>\n"); 04243 04244 printf("</TR>\n"); 04245 printf("</TABLE></TD>\n"); 04246 printf("</TR>\n"); 04247 } 04248 04249 if(hosts_pending>0) 04250 printf("<TR><TD CLASS='miniStatusPENDING'><A HREF='%s?hostgroup=%s&style=hostdetail&hoststatustypes=%d&hostprops=%lu'>%d PENDING</A></TD></TR>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),HOST_PENDING,host_properties,hosts_pending); 04251 04252 printf("</TABLE>\n"); 04253 04254 if((hosts_up + hosts_down + hosts_unreachable + hosts_pending)==0) 04255 printf("No matching hosts"); 04256 } 04257 04258 return; 04259 } 04260 04261 04262 /* shows service total summary information for a specific hostgroup */ 04263 void show_hostgroup_service_totals_summary(hostgroup *temp_hostgroup){ 04264 int services_ok=0; 04265 int services_warning=0; 04266 int services_unknown=0; 04267 int services_critical=0; 04268 int services_pending=0; 04269 int services_warning_host_problem=0; 04270 int services_warning_scheduled=0; 04271 int services_warning_acknowledged=0; 04272 int services_warning_disabled=0; 04273 int services_warning_unacknowledged=0; 04274 int services_unknown_host_problem=0; 04275 int services_unknown_scheduled=0; 04276 int services_unknown_acknowledged=0; 04277 int services_unknown_disabled=0; 04278 int services_unknown_unacknowledged=0; 04279 int services_critical_host_problem=0; 04280 int services_critical_scheduled=0; 04281 int services_critical_acknowledged=0; 04282 int services_critical_disabled=0; 04283 int services_critical_unacknowledged=0; 04284 servicestatus *temp_servicestatus=NULL; 04285 hoststatus *temp_hoststatus=NULL; 04286 host *temp_host=NULL; 04287 int problem=FALSE; 04288 04289 04290 /* check all services... */ 04291 for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ 04292 04293 /* find the host this service is associated with */ 04294 temp_host=find_host(temp_servicestatus->host_name); 04295 if(temp_host==NULL) 04296 continue; 04297 04298 /* see if this service is associated with a host in the specified hostgroup */ 04299 if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE) 04300 continue; 04301 04302 /* find the status of the associated host */ 04303 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 04304 if(temp_hoststatus==NULL) 04305 continue; 04306 04307 /* find the status of the associated host */ 04308 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 04309 if(temp_hoststatus==NULL) 04310 continue; 04311 04312 /* make sure we only display hosts of the specified status levels */ 04313 if(!(host_status_types & temp_hoststatus->status)) 04314 continue; 04315 04316 /* make sure we only display hosts that have the desired properties */ 04317 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 04318 continue; 04319 04320 /* make sure we only display services of the specified status levels */ 04321 if(!(service_status_types & temp_servicestatus->status)) 04322 continue; 04323 04324 /* make sure we only display services that have the desired properties */ 04325 if(passes_service_properties_filter(temp_servicestatus)==FALSE) 04326 continue; 04327 04328 problem=TRUE; 04329 04330 if(temp_servicestatus->status==SERVICE_OK) 04331 services_ok++; 04332 04333 else if(temp_servicestatus->status==SERVICE_WARNING){ 04334 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 04335 if(temp_hoststatus!=NULL && (temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)){ 04336 services_warning_host_problem++; 04337 problem=FALSE; 04338 } 04339 if(temp_servicestatus->scheduled_downtime_depth>0){ 04340 services_warning_scheduled++; 04341 problem=FALSE; 04342 } 04343 if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ 04344 services_warning_acknowledged++; 04345 problem=FALSE; 04346 } 04347 if(temp_servicestatus->checks_enabled==FALSE){ 04348 services_warning_disabled++; 04349 problem=FALSE; 04350 } 04351 if(problem==TRUE) 04352 services_warning_unacknowledged++; 04353 services_warning++; 04354 } 04355 04356 else if(temp_servicestatus->status==SERVICE_UNKNOWN){ 04357 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 04358 if(temp_hoststatus!=NULL && (temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)){ 04359 services_unknown_host_problem++; 04360 problem=FALSE; 04361 } 04362 if(temp_servicestatus->scheduled_downtime_depth>0){ 04363 services_unknown_scheduled++; 04364 problem=FALSE; 04365 } 04366 if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ 04367 services_unknown_acknowledged++; 04368 problem=FALSE; 04369 } 04370 if(temp_servicestatus->checks_enabled==FALSE){ 04371 services_unknown_disabled++; 04372 problem=FALSE; 04373 } 04374 if(problem==TRUE) 04375 services_unknown_unacknowledged++; 04376 services_unknown++; 04377 } 04378 04379 else if(temp_servicestatus->status==SERVICE_CRITICAL){ 04380 temp_hoststatus=find_hoststatus(temp_servicestatus->host_name); 04381 if(temp_hoststatus!=NULL && (temp_hoststatus->status==HOST_DOWN || temp_hoststatus->status==HOST_UNREACHABLE)){ 04382 services_critical_host_problem++; 04383 problem=FALSE; 04384 } 04385 if(temp_servicestatus->scheduled_downtime_depth>0){ 04386 services_critical_scheduled++; 04387 problem=FALSE; 04388 } 04389 if(temp_servicestatus->problem_has_been_acknowledged==TRUE){ 04390 services_critical_acknowledged++; 04391 problem=FALSE; 04392 } 04393 if(temp_servicestatus->checks_enabled==FALSE){ 04394 services_critical_disabled++; 04395 problem=FALSE; 04396 } 04397 if(problem==TRUE) 04398 services_critical_unacknowledged++; 04399 services_critical++; 04400 } 04401 04402 else if(temp_servicestatus->status==SERVICE_PENDING) 04403 services_pending++; 04404 } 04405 04406 if(content_type==JSON_CONTENT) { 04407 printf("\"services_ok\": %d, ",services_ok); 04408 printf("\"services_warning\": %d, ",services_warning); 04409 printf("\"services_warning_unacknowledged\": %d, ",services_warning_unacknowledged); 04410 printf("\"services_warning_host_problem\": %d, ",services_warning_host_problem); 04411 printf("\"services_warning_scheduled\": %d, ",services_warning_scheduled); 04412 printf("\"services_warning_acknowledged\": %d, ",services_warning_acknowledged); 04413 printf("\"services_warning_disabled\": %d, ",services_warning_disabled); 04414 printf("\"services_unknown\": %d, ",services_unknown); 04415 printf("\"services_unknown_unacknowledged\": %d, ",services_unknown_unacknowledged); 04416 printf("\"services_unknown_host_problem\": %d, ",services_unknown_host_problem); 04417 printf("\"services_unknown_scheduled\": %d, ",services_unknown_scheduled); 04418 printf("\"services_unknown_acknowledged\": %d, ",services_unknown_acknowledged); 04419 printf("\"services_unknown_disabled\": %d, ",services_unknown_disabled); 04420 printf("\"services_critical\": %d, ",services_critical); 04421 printf("\"services_critical_unacknowledged\": %d, ",services_critical_unacknowledged); 04422 printf("\"services_critical_host_problem\": %d, ",services_critical_host_problem); 04423 printf("\"services_critical_scheduled\": %d, ",services_critical_scheduled); 04424 printf("\"services_critical_acknowledged\": %d, ",services_critical_acknowledged); 04425 printf("\"services_critical_disabled\": %d, ",services_critical_disabled); 04426 printf("\"services_pending\": %d ",services_pending); 04427 }else{ 04428 printf("<TABLE BORDER=0>\n"); 04429 04430 if(services_ok>0) 04431 printf("<TR><TD CLASS='miniStatusOK'><A HREF='%s?hostgroup=%s&style=detail&&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d OK</A></TD></TR>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_OK,host_status_types,service_properties,host_properties,services_ok); 04432 04433 if(services_warning>0){ 04434 printf("<TR>\n"); 04435 printf("<TD CLASS='miniStatusWARNING'><TABLE BORDER='0'>\n"); 04436 printf("<TR>\n"); 04437 04438 printf("<TD CLASS='miniStatusWARNING'><A HREF='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d WARNING</A> :</TD>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_WARNING,host_status_types,service_properties,host_properties,services_warning); 04439 04440 printf("<TD><TABLE BORDER='0'>\n"); 04441 04442 if(services_warning_unacknowledged>0) 04443 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_WARNING,HOST_UP|HOST_PENDING,SERVICE_NO_SCHEDULED_DOWNTIME|SERVICE_STATE_UNACKNOWLEDGED|SERVICE_CHECKS_ENABLED,services_warning_unacknowledged); 04444 04445 if(services_warning_host_problem>0) 04446 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_WARNING,HOST_DOWN|HOST_UNREACHABLE,services_warning_host_problem); 04447 04448 if(services_warning_scheduled>0) 04449 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_WARNING,SERVICE_SCHEDULED_DOWNTIME,services_warning_scheduled); 04450 04451 if(services_warning_acknowledged>0) 04452 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_WARNING,SERVICE_STATE_ACKNOWLEDGED,services_warning_acknowledged); 04453 04454 if(services_warning_disabled>0) 04455 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_WARNING,SERVICE_CHECKS_DISABLED,services_warning_disabled); 04456 04457 printf("</TABLE></TD>\n"); 04458 04459 printf("</TR>\n"); 04460 printf("</TABLE></TD>\n"); 04461 printf("</TR>\n"); 04462 } 04463 04464 if(services_unknown>0){ 04465 printf("<TR>\n"); 04466 printf("<TD CLASS='miniStatusUNKNOWN'><TABLE BORDER='0'>\n"); 04467 printf("<TR>\n"); 04468 04469 printf("<TD CLASS='miniStatusUNKNOWN'><A HREF='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d UNKNOWN</A> :</TD>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_UNKNOWN,host_status_types,service_properties,host_properties,services_unknown); 04470 04471 printf("<TD><TABLE BORDER='0'>\n"); 04472 04473 if(services_unknown_unacknowledged>0) 04474 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_UNKNOWN,HOST_UP|HOST_PENDING,SERVICE_NO_SCHEDULED_DOWNTIME|SERVICE_STATE_UNACKNOWLEDGED|SERVICE_CHECKS_ENABLED,services_unknown_unacknowledged); 04475 04476 if(services_unknown_host_problem>0) 04477 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_UNKNOWN,HOST_DOWN|HOST_UNREACHABLE,services_unknown_host_problem); 04478 04479 if(services_unknown_scheduled>0) 04480 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_UNKNOWN,SERVICE_SCHEDULED_DOWNTIME,services_unknown_scheduled); 04481 04482 if(services_unknown_acknowledged>0) 04483 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_UNKNOWN,SERVICE_STATE_ACKNOWLEDGED,services_unknown_acknowledged); 04484 04485 if(services_unknown_disabled>0) 04486 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_UNKNOWN,SERVICE_CHECKS_DISABLED,services_unknown_disabled); 04487 04488 printf("</TABLE></TD>\n"); 04489 04490 printf("</TR>\n"); 04491 printf("</TABLE></TD>\n"); 04492 printf("</TR>\n"); 04493 } 04494 04495 if(services_critical>0){ 04496 printf("<TR>\n"); 04497 printf("<TD CLASS='miniStatusCRITICAL'><TABLE BORDER='0'>\n"); 04498 printf("<TR>\n"); 04499 04500 printf("<TD CLASS='miniStatusCRITICAL'><A HREF='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d CRITICAL</A> :</TD>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_CRITICAL,host_status_types,service_properties,host_properties,services_critical); 04501 04502 printf("<TD><TABLE BORDER='0'>\n"); 04503 04504 if(services_critical_unacknowledged>0) 04505 printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_CRITICAL,HOST_UP|HOST_PENDING,SERVICE_NO_SCHEDULED_DOWNTIME|SERVICE_STATE_UNACKNOWLEDGED|SERVICE_CHECKS_ENABLED,services_critical_unacknowledged); 04506 04507 if(services_critical_host_problem>0) 04508 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_CRITICAL,HOST_DOWN|HOST_UNREACHABLE,services_critical_host_problem); 04509 04510 if(services_critical_scheduled>0) 04511 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_CRITICAL,SERVICE_SCHEDULED_DOWNTIME,services_critical_scheduled); 04512 04513 if(services_critical_acknowledged>0) 04514 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Acknowledged</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_CRITICAL,SERVICE_STATE_ACKNOWLEDGED,services_critical_acknowledged); 04515 04516 if(services_critical_disabled>0) 04517 printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?hostgroup=%s&style=detail&servicestatustypes=%d&serviceprops=%d'>%d Disabled</a></td></tr>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_CRITICAL,SERVICE_CHECKS_DISABLED,services_critical_disabled); 04518 04519 printf("</TABLE></TD>\n"); 04520 04521 printf("</TR>\n"); 04522 printf("</TABLE></TD>\n"); 04523 printf("</TR>\n"); 04524 } 04525 04526 if(services_pending>0) 04527 printf("<TR><TD CLASS='miniStatusPENDING'><A HREF='%s?hostgroup=%s&style=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%lu&hostprops=%lu'>%d PENDING</A></TD></TR>\n",STATUS_CGI,url_encode(temp_hostgroup->group_name),SERVICE_PENDING,host_status_types,service_properties,host_properties,services_pending); 04528 04529 printf("</TABLE>\n"); 04530 04531 if((services_ok + services_warning + services_unknown + services_critical + services_pending)==0) 04532 printf("No matching services"); 04533 } 04534 04535 return; 04536 } 04537 04538 04539 /* show a grid layout of hostgroup(s)... */ 04540 void show_hostgroup_grids(void){ 04541 hostgroup *temp_hostgroup=NULL; 04542 int user_has_seen_something=FALSE; 04543 int hostgroup_error=FALSE; 04544 int odd=0; 04545 char error_text[MAX_INPUT_BUFFER]=""; 04546 int json_start=TRUE; 04547 04548 if(content_type==JSON_CONTENT) { 04549 printf("\"hostgroup_grid\": [\n"); 04550 }else{ 04551 printf("<P>\n"); 04552 04553 printf("<table border=0 width=100%%>\n"); 04554 printf("<tr>\n"); 04555 04556 printf("<td valign=top align=left width=33%%>\n"); 04557 04558 show_filters(); 04559 04560 printf("</td>"); 04561 04562 printf("<td valign=top align=center width=33%%>\n"); 04563 04564 printf("<DIV ALIGN=CENTER CLASS='statusTitle'>Status Grid For "); 04565 if(show_all_hostgroups==TRUE) 04566 printf("All Host Groups"); 04567 else 04568 printf("Host Group '%s'",hostgroup_name); 04569 printf("</DIV>\n"); 04570 04571 printf("<br>"); 04572 04573 printf("</td>\n"); 04574 04575 printf("<td valign=top align=right width=33%%></td>\n"); 04576 04577 printf("</tr>\n"); 04578 printf("</table>\n"); 04579 04580 printf("</P>\n"); 04581 } 04582 04583 /* display status grids for all hostgroups */ 04584 if(show_all_hostgroups==TRUE){ 04585 04586 /* loop through all hostgroups... */ 04587 for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ 04588 04589 /* make sure the user is authorized to view this hostgroup */ 04590 if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==FALSE) 04591 continue; 04592 04593 if(odd==0) 04594 odd=1; 04595 else 04596 odd=0; 04597 04598 if(content_type==JSON_CONTENT){ 04599 // always add a comma, except for the first line 04600 if (json_start==FALSE) 04601 printf(",\n"); 04602 json_start=FALSE; 04603 } 04604 04605 /* show grid for this hostgroup */ 04606 show_hostgroup_grid(temp_hostgroup); 04607 04608 user_has_seen_something=TRUE; 04609 } 04610 04611 } 04612 04613 /* else just show grid for a specific hostgroup */ 04614 else{ 04615 temp_hostgroup=find_hostgroup(hostgroup_name); 04616 if(temp_hostgroup==NULL) 04617 hostgroup_error=TRUE; 04618 else{ 04619 show_hostgroup_grid(temp_hostgroup); 04620 user_has_seen_something=TRUE; 04621 } 04622 } 04623 04624 if(content_type==JSON_CONTENT) 04625 printf(" ]\n"); 04626 04627 /* if user couldn't see anything, print out some helpful info... */ 04628 if(user_has_seen_something==FALSE && hostgroup_error==FALSE){ 04629 04630 if(content_type==JSON_CONTENT) 04631 printf(",\n"); 04632 04633 if(hoststatus_list!=NULL) 04634 print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...","If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.",0); 04635 else 04636 print_generic_error_message("There are no host groups defined.",NULL,0); 04637 } 04638 04639 /* we couldn't find the hostgroup */ 04640 else if(hostgroup_error==TRUE){ 04641 if(content_type==JSON_CONTENT) 04642 printf(",\n"); 04643 04644 snprintf(error_text,sizeof(error_text),"Sorry, but host group '%s' doesn't seem to exist...",hostgroup_name); 04645 error_text[sizeof(error_text)-1]='\x0'; 04646 print_generic_error_message(error_text,NULL,0); 04647 } 04648 04649 return; 04650 } 04651 04652 04653 /* displays status grid for a specific hostgroup */ 04654 void show_hostgroup_grid(hostgroup *temp_hostgroup){ 04655 hostsmember *temp_member; 04656 char *status_bg_class=""; 04657 char *status=""; 04658 char *host_status_class=""; 04659 char *service_status_class=""; 04660 host *temp_host; 04661 service *temp_service; 04662 hoststatus *temp_hoststatus; 04663 servicestatus *temp_servicestatus; 04664 char *processed_string=NULL; 04665 int odd=0; 04666 int current_item; 04667 int json_start=TRUE; 04668 int json_start2=TRUE; 04669 04670 if(content_type==JSON_CONTENT){ 04671 printf("{ \"hostgroup_name\": \"%s\",\n",json_encode(temp_hostgroup->group_name)); 04672 printf("\"members\": [ \n"); 04673 }else{ 04674 printf("<P>\n"); 04675 printf("<DIV ALIGN=CENTER>\n"); 04676 04677 printf("<DIV CLASS='status'><A HREF='%s?hostgroup=%s&style=detail'>%s</A>",STATUS_CGI,url_encode(temp_hostgroup->group_name),temp_hostgroup->alias); 04678 printf(" (<A HREF='%s?type=%d&hostgroup=%s'>%s</A>)</DIV>",EXTINFO_CGI,DISPLAY_HOSTGROUP_INFO,url_encode(temp_hostgroup->group_name),temp_hostgroup->group_name); 04679 04680 printf("<TABLE BORDER=1 CLASS='status' ALIGN=CENTER>\n"); 04681 printf("<TR><TH CLASS='status'>Host</TH><TH CLASS='status'>Services</a></TH><TH CLASS='status'>Actions</TH></TR>\n"); 04682 } 04683 04684 /* find all the hosts that belong to the hostgroup */ 04685 for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){ 04686 04687 /* find the host... */ 04688 temp_host=find_host(temp_member->host_name); 04689 if(temp_host==NULL) 04690 continue; 04691 04692 /* grab macros */ 04693 grab_host_macros_r(mac, temp_host); 04694 04695 /* find the host status */ 04696 temp_hoststatus=find_hoststatus(temp_host->name); 04697 if(temp_hoststatus==NULL) 04698 continue; 04699 04700 if(odd==1){ 04701 status_bg_class="Even"; 04702 odd=0; 04703 }else{ 04704 status_bg_class="Odd"; 04705 odd=1; 04706 } 04707 04708 if(content_type!=JSON_CONTENT) 04709 printf("<TR CLASS='status%s'>\n",status_bg_class); 04710 04711 /* get the status of the host */ 04712 if(temp_hoststatus->status==HOST_DOWN) { 04713 status="DOWN"; 04714 host_status_class="HOSTDOWN"; 04715 }else if(temp_hoststatus->status==HOST_UNREACHABLE){ 04716 status="UNREACHABLE"; 04717 host_status_class="HOSTUNREACHABLE"; 04718 }else{ 04719 status="OK"; 04720 host_status_class=status_bg_class; 04721 } 04722 04723 if(content_type==JSON_CONTENT) { 04724 if (json_start==FALSE) 04725 printf(",\n"); 04726 json_start=FALSE; 04727 04728 printf("{ \"host_name\": \"%s\",\n",json_encode(temp_host->name)); 04729 printf("\"host_status\": \"%s\",\n",status); 04730 printf("\"services\": [ \n"); 04731 }else{ 04732 printf("<TD CLASS='status%s'>",host_status_class); 04733 04734 printf("<TABLE BORDER=0 WIDTH='100%%' cellpadding=0 cellspacing=0>\n"); 04735 printf("<TR>\n"); 04736 printf("<TD ALIGN=LEFT>\n"); 04737 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 04738 printf("<TR>\n"); 04739 printf("<TD align=left valign=center CLASS='status%s'>",host_status_class); 04740 printf("<A HREF='%s?type=%d&host=%s'>%s</A>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_host->name),(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 04741 printf("</TD>\n"); 04742 printf("</TR>\n"); 04743 printf("</TABLE>\n"); 04744 printf("</TD>\n"); 04745 printf("<TD align=right valign=center nowrap>\n"); 04746 printf("<TABLE BORDER=0 cellpadding=0 cellspacing=0>\n"); 04747 printf("<TR>\n"); 04748 04749 if(temp_host->icon_image!=NULL){ 04750 printf("<TD align=center valign=center>"); 04751 printf("<A HREF='%s?type=%d&host=%s'>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_host->name)); 04752 printf("<IMG SRC='%s",url_logo_images_path); 04753 process_macros_r(mac, temp_host->icon_image,&processed_string,0); 04754 printf("%s",processed_string); 04755 free(processed_string); 04756 printf("' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt,(temp_host->icon_image_alt==NULL)?"":temp_host->icon_image_alt); 04757 printf("</A>"); 04758 printf("<TD>\n"); 04759 } 04760 printf("<TD>\n"); 04761 04762 printf("</TR>\n"); 04763 printf("</TABLE>\n"); 04764 printf("</TD>\n"); 04765 printf("</TR>\n"); 04766 printf("</TABLE>\n"); 04767 04768 printf("</TD>\n"); 04769 04770 printf("<TD CLASS='status%s'>",host_status_class); 04771 } 04772 04773 /* display all services on the host */ 04774 current_item=1; 04775 json_start2=TRUE; 04776 for(temp_service=service_list;temp_service;temp_service=temp_service->next){ 04777 04778 /* skip this service if it's not associate with the host */ 04779 if(strcmp(temp_service->host_name,temp_host->name)) 04780 continue; 04781 04782 /* grab macros */ 04783 grab_service_macros_r(mac, temp_service); 04784 04785 /* get the status of the service */ 04786 temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description); 04787 if(temp_servicestatus==NULL) 04788 service_status_class="NULL"; 04789 else if(temp_servicestatus->status==SERVICE_OK) 04790 service_status_class="OK"; 04791 else if(temp_servicestatus->status==SERVICE_WARNING) 04792 service_status_class="WARNING"; 04793 else if(temp_servicestatus->status==SERVICE_UNKNOWN) 04794 service_status_class="UNKNOWN"; 04795 else if(temp_servicestatus->status==SERVICE_CRITICAL) 04796 service_status_class="CRITICAL"; 04797 else 04798 service_status_class="PENDING"; 04799 04800 if(content_type==JSON_CONTENT) { 04801 if (json_start2==FALSE) 04802 printf(",\n"); 04803 json_start2=FALSE; 04804 04805 printf("{ \"service_description\": \"%s\",\n",json_encode(temp_servicestatus->description)); 04806 if(temp_servicestatus==NULL) 04807 printf("\"service_status\": null } "); 04808 else 04809 printf("\"service_status\": \"%s\" } ",service_status_class); 04810 }else{ 04811 if(current_item>max_grid_width && max_grid_width>0){ 04812 printf("<BR>\n"); 04813 current_item=1; 04814 } 04815 04816 printf("<A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_servicestatus->host_name)); 04817 printf("&service=%s' CLASS='status%s'>%s</A> ",url_encode(temp_servicestatus->description),service_status_class,temp_servicestatus->description); 04818 04819 current_item++; 04820 } 04821 } 04822 04823 if(content_type==JSON_CONTENT) { 04824 printf(" ] } \n"); 04825 }else{ 04826 printf("</TD>\n"); 04827 04828 /* actions */ 04829 printf("<TD CLASS='status%s'>",host_status_class); 04830 04831 printf("<A HREF='%s?type=%d&host=%s'>\n",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_host->name)); 04832 printf("<IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,DETAIL_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extended Information For This Host","View Extended Information For This Host"); 04833 printf("</A>"); 04834 04835 if(temp_host->notes_url!=NULL){ 04836 process_macros_r(mac, temp_host->notes_url,&processed_string,0); 04837 BEGIN_MULTIURL_LOOP 04838 printf("<A HREF='"); 04839 printf("%s",processed_string); 04840 printf("' TARGET='%s'>",(notes_url_target==NULL)?"_blank":notes_url_target); 04841 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,NOTES_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"View Extra Host Notes","View Extra Host Notes"); 04842 printf("</A>"); 04843 END_MULTIURL_LOOP 04844 free(processed_string); 04845 } 04846 if(temp_host->action_url!=NULL){ 04847 process_macros_r(mac, temp_host->action_url,&processed_string,0); 04848 BEGIN_MULTIURL_LOOP 04849 printf("<A HREF='"); 04850 printf("%s",processed_string); 04851 printf("' TARGET='%s'>",(action_url_target==NULL)?"_blank":action_url_target); 04852 printf("<IMG SRC='%s%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'>",url_images_path,MU_iconstr,ACTION_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Perform Extra Host Actions","Perform Extra Host Actions"); 04853 printf("</A>"); 04854 END_MULTIURL_LOOP 04855 free(processed_string); 04856 } 04857 04858 printf("<a href='%s?host=%s'><img src='%s%s' border=0 alt='View Service Details For This Host' title='View Service Details For This Host'></a>\n",STATUS_CGI,url_encode(temp_host->name),url_images_path,STATUS_DETAIL_ICON); 04859 #ifdef USE_STATUSMAP 04860 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d ALT='%s' TITLE='%s'></A>",STATUSMAP_CGI,url_encode(temp_host->name),url_images_path,STATUSMAP_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT,"Locate Host On Map","Locate Host On Map"); 04861 #endif 04862 printf("</TD>\n"); 04863 04864 printf("</TR>\n"); 04865 } 04866 } 04867 04868 if(content_type==JSON_CONTENT) 04869 printf(" ] } \n"); 04870 else { 04871 printf("</TABLE>\n"); 04872 printf("</DIV>\n"); 04873 printf("</P>\n"); 04874 } 04875 04876 return; 04877 } 04878 04879 04880 /******************************************************************/ 04881 /********** SERVICE SORTING & FILTERING FUNCTIONS ***************/ 04882 /******************************************************************/ 04883 04884 void grab_statusdata(void) { 04885 hoststatus *temp_hoststatus=NULL; 04886 servicestatus *temp_servicestatus=NULL; 04887 host *temp_host=NULL; 04888 service *temp_service=NULL; 04889 hostgroup *temp_hostgroup=NULL; 04890 servicegroup *temp_servicegroup=NULL; 04891 int grab_service=FALSE; 04892 regex_t preg, preg_hostname; 04893 04894 /* get requested groups */ 04895 temp_hostgroup=find_hostgroup(hostgroup_name); 04896 temp_servicegroup=find_servicegroup(servicegroup_name); 04897 04898 if (group_style_type==STYLE_HOST_DETAIL) { 04899 04900 for(temp_hoststatus=hoststatus_list;temp_hoststatus!=NULL;temp_hoststatus=temp_hoststatus->next){ 04901 04902 /* find the host */ 04903 temp_host=find_host(temp_hoststatus->host_name); 04904 04905 /* if we couldn't find the host, go to the next status entry */ 04906 if(temp_host==NULL) 04907 continue; 04908 04909 /* If user searched for a single host without any services then show only this one */ 04910 if(show_all_hosts==FALSE && strcmp(host_name,temp_hoststatus->host_name)) 04911 continue; 04912 04913 /* make sure user has rights to see this... */ 04914 if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 04915 continue; 04916 04917 user_is_authorized_for_statusdata=TRUE; 04918 04919 /* see if we should display services for hosts with this type of status */ 04920 if(!(host_status_types & temp_hoststatus->status)) 04921 continue; 04922 04923 /* check host properties filter */ 04924 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 04925 continue; 04926 04927 /* see if this host is a member of the hostgroup */ 04928 if(show_all_hostgroups==FALSE){ 04929 if(temp_hostgroup==NULL) 04930 continue; 04931 if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE) 04932 continue; 04933 } 04934 04935 add_status_data(HOST_STATUS,temp_hoststatus,NULL); 04936 04937 } 04938 } else { 04939 if(service_filter!=NULL) 04940 regcomp(&preg,service_filter,0); 04941 if(host_filter!=NULL) 04942 regcomp(&preg_hostname,host_filter,REG_ICASE); 04943 04944 for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){ 04945 04946 /* find the service */ 04947 temp_service=find_service(temp_servicestatus->host_name,temp_servicestatus->description); 04948 04949 /* if we couldn't find the service, go to the next service */ 04950 if(temp_service==NULL) 04951 continue; 04952 04953 /* find the host */ 04954 temp_host=find_host(temp_service->host_name); 04955 04956 /* make sure user has rights to see this... */ 04957 if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) 04958 continue; 04959 04960 user_is_authorized_for_statusdata=TRUE; 04961 04962 /* get the host status information */ 04963 temp_hoststatus=find_hoststatus(temp_service->host_name); 04964 04965 /* see if we should display services for hosts with tis type of status */ 04966 if(!(host_status_types & temp_hoststatus->status)) 04967 continue; 04968 04969 /* see if we should display this type of service status */ 04970 if(!(service_status_types & temp_servicestatus->status)) 04971 continue; 04972 04973 /* check host properties filter */ 04974 if(passes_host_properties_filter(temp_hoststatus)==FALSE) 04975 continue; 04976 04977 /* check service properties filter */ 04978 if(passes_service_properties_filter(temp_servicestatus)==FALSE) 04979 continue; 04980 04981 /* servicefilter cgi var */ 04982 if(service_filter!=NULL) 04983 if(regexec(&preg,temp_servicestatus->description,0,NULL,0)) 04984 continue; 04985 04986 grab_service=FALSE; 04987 04988 if(display_type==DISPLAY_HOSTS){ 04989 if(show_all_hosts==TRUE) 04990 grab_service=TRUE; 04991 /* for the host_name ... */ 04992 else if(host_filter!=NULL && 0==regexec(&preg_hostname,temp_servicestatus->host_name,0,NULL,0)) 04993 grab_service=TRUE; 04994 else if(!strcmp(host_name,temp_servicestatus->host_name)) 04995 grab_service=TRUE; 04996 /* and for the display_name */ 04997 else if(host_filter!=NULL && 0==regexec(&preg_hostname,temp_host->display_name,0,NULL,0)) 04998 grab_service=TRUE; 04999 else if(!strcmp(host_name,temp_host->display_name)) 05000 grab_service=TRUE; 05001 } 05002 05003 else if(display_type==DISPLAY_HOSTGROUPS){ 05004 if(show_all_hostgroups==TRUE) 05005 grab_service=TRUE; 05006 else if(temp_hostgroup!=NULL && is_host_member_of_hostgroup(temp_hostgroup,temp_host)==TRUE) 05007 grab_service=TRUE; 05008 } 05009 05010 else if(display_type==DISPLAY_SERVICEGROUPS){ 05011 if(show_all_servicegroups==TRUE) 05012 grab_service=TRUE; 05013 else if(temp_servicegroup!=NULL && is_service_member_of_servicegroup(temp_servicegroup,temp_service)==TRUE) 05014 grab_service=TRUE; 05015 } 05016 05017 if(grab_service==TRUE) 05018 add_status_data(SERVICE_STATUS,NULL,temp_servicestatus); 05019 } 05020 } 05021 05022 return; 05023 } 05024 05025 int add_status_data(int status_type, hoststatus *host_status, servicestatus *service_status){ 05026 statusdata *new_statusdata=NULL; 05027 char *status_string=NULL; 05028 char *host_name=NULL; 05029 char *svc_description=NULL; 05030 char *plugin_output_short=NULL; 05031 char *plugin_output_long=NULL; 05032 char *plugin_output=NULL; 05033 char last_check[MAX_DATETIME_LENGTH]; 05034 char state_duration[48]; 05035 char attempts[MAX_INPUT_BUFFER]; 05036 time_t ts_state_duration=0L; 05037 time_t ts_last_check=0L; 05038 time_t ts_last_state_change=0L; 05039 int days; 05040 int hours; 05041 int minutes; 05042 int seconds; 05043 int duration_error=FALSE; 05044 int status=OK; 05045 int dummy=0; 05046 int current_attempt=0; 05047 int is_flapping=FALSE; 05048 int problem_has_been_acknowledged=FALSE; 05049 int scheduled_downtime_depth=0; 05050 int notifications_enabled=FALSE; 05051 int checks_enabled=FALSE; 05052 05053 if (status_type==HOST_STATUS) { 05054 if (host_status==NULL) 05055 return ERROR; 05056 05057 status=host_status->status; 05058 if(host_status->status==HOST_PENDING) 05059 status_string="PENDING"; 05060 else if(host_status->status==HOST_UP) 05061 status_string="UP"; 05062 else if(host_status->status==HOST_DOWN) 05063 status_string="DOWN"; 05064 else if(host_status->status==HOST_UNREACHABLE) 05065 status_string="UNREACHABLE"; 05066 05067 ts_last_check=host_status->last_check; 05068 ts_last_state_change=host_status->last_state_change; 05069 05070 host_name=host_status->host_name; 05071 current_attempt=host_status->current_attempt; 05072 05073 problem_has_been_acknowledged=host_status->problem_has_been_acknowledged; 05074 scheduled_downtime_depth=host_status->scheduled_downtime_depth; 05075 notifications_enabled=host_status->notifications_enabled; 05076 checks_enabled=host_status->checks_enabled; 05077 is_flapping=host_status->is_flapping; 05078 05079 plugin_output_short=host_status->plugin_output; 05080 plugin_output_long=host_status->long_plugin_output; 05081 05082 snprintf(attempts,sizeof(attempts)-1,"%d/%d",host_status->current_attempt,host_status->max_attempts); 05083 attempts[sizeof(attempts)-1]='\x0'; 05084 05085 } 05086 else if (status_type==SERVICE_STATUS) { 05087 if (service_status==NULL) 05088 return ERROR; 05089 05090 status=service_status->status; 05091 if(service_status->status==SERVICE_PENDING) 05092 status_string="PENDING"; 05093 else if(service_status->status==SERVICE_OK) 05094 status_string="OK"; 05095 else if(service_status->status==SERVICE_WARNING) 05096 status_string="WARNING"; 05097 else if(service_status->status==SERVICE_UNKNOWN) 05098 status_string="UNKNOWN"; 05099 else if(service_status->status==SERVICE_CRITICAL) 05100 status_string="CRITICAL"; 05101 05102 ts_last_check=service_status->last_check; 05103 ts_last_state_change=service_status->last_state_change; 05104 05105 host_name=service_status->host_name; 05106 svc_description=service_status->description; 05107 current_attempt=service_status->current_attempt; 05108 05109 problem_has_been_acknowledged=service_status->problem_has_been_acknowledged; 05110 scheduled_downtime_depth=service_status->scheduled_downtime_depth; 05111 notifications_enabled=service_status->notifications_enabled; 05112 checks_enabled=service_status->checks_enabled; 05113 is_flapping=service_status->is_flapping; 05114 05115 plugin_output_short=service_status->plugin_output; 05116 plugin_output_long=service_status->long_plugin_output; 05117 05118 if(content_type==CSV_CONTENT || content_type==JSON_CONTENT) 05119 snprintf(attempts,sizeof(attempts)-1,"%d/%d",service_status->current_attempt,service_status->max_attempts); 05120 else 05121 snprintf(attempts,sizeof(attempts)-1,"%d/%d %s#%d%s",service_status->current_attempt,service_status->max_attempts,(service_status->status&(service_status->state_type==HARD_STATE?add_notif_num_hard:add_notif_num_soft)?"(":"<!-- "),service_status->current_notification_number,(service_status->status&(service_status->state_type==HARD_STATE?add_notif_num_hard:add_notif_num_soft)?")":" -->")); 05122 attempts[sizeof(attempts)-1]='\x0'; 05123 05124 } else { 05125 return ERROR; 05126 } 05127 05128 /* last check timestamp to string */ 05129 get_time_string(&ts_last_check,last_check,(int)sizeof(last_check),SHORT_DATE_TIME); 05130 if((unsigned long)ts_last_check==0L) 05131 strcpy(last_check,"N/A"); 05132 05133 /* state duration calculation... */ 05134 ts_state_duration=0; 05135 duration_error=FALSE; 05136 if(ts_last_state_change==(time_t)0){ 05137 if(program_start>current_time) 05138 duration_error=TRUE; 05139 else 05140 ts_state_duration=current_time-program_start; 05141 }else{ 05142 if(ts_last_state_change>current_time) 05143 duration_error=TRUE; 05144 else 05145 ts_state_duration=current_time-ts_last_state_change; 05146 } 05147 get_time_breakdown((unsigned long)ts_state_duration,&days,&hours,&minutes,&seconds); 05148 if(duration_error==TRUE) 05149 snprintf(state_duration,sizeof(state_duration)-1,"???"); 05150 else 05151 snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(ts_last_state_change==(time_t)0)?"+":""); 05152 state_duration[sizeof(state_duration)-1]='\x0'; 05153 strip(state_duration); 05154 05155 /* plugin ouput */ 05156 if (status_show_long_plugin_output!=FALSE && plugin_output_long!=NULL) { 05157 if(content_type==CSV_CONTENT || content_type==JSON_CONTENT) 05158 dummy=asprintf(&plugin_output,"%s %s",plugin_output_short,escape_newlines(plugin_output_long)); 05159 else 05160 dummy=asprintf(&plugin_output,"%s<BR>%s",html_encode(plugin_output_short,TRUE),html_encode(plugin_output_long,TRUE)); 05161 } else if (plugin_output_short!=NULL) { 05162 if(content_type==CSV_CONTENT || content_type==JSON_CONTENT) 05163 dummy=asprintf(&plugin_output,"%s",plugin_output_short); 05164 else 05165 dummy=asprintf(&plugin_output,"%s ",html_encode(plugin_output_short,TRUE)); 05166 } else { 05167 if(content_type==CSV_CONTENT || content_type==JSON_CONTENT) 05168 plugin_output=NULL; 05169 else 05170 dummy=asprintf(&plugin_output," "); 05171 } 05172 05173 /* allocating new memory */ 05174 new_statusdata=(statusdata *)malloc(sizeof(statusdata)); 05175 if(new_statusdata==NULL) 05176 return ERROR; // maybe not good. better to return with ERROR ???? 05177 05178 new_statusdata->type=status_type; 05179 new_statusdata->status=status; 05180 new_statusdata->status_string=status_string; 05181 new_statusdata->host_name=host_name; 05182 new_statusdata->svc_description=svc_description; 05183 new_statusdata->state_duration=strdup(state_duration); 05184 new_statusdata->ts_state_duration=ts_state_duration; 05185 new_statusdata->last_check=strdup(last_check); 05186 new_statusdata->ts_last_check=ts_last_check; 05187 new_statusdata->attempts=strdup(attempts); 05188 05189 new_statusdata->current_attempt=current_attempt; 05190 05191 new_statusdata->problem_has_been_acknowledged=problem_has_been_acknowledged; 05192 new_statusdata->scheduled_downtime_depth=scheduled_downtime_depth; 05193 new_statusdata->notifications_enabled=notifications_enabled; 05194 new_statusdata->checks_enabled=checks_enabled; 05195 new_statusdata->is_flapping=is_flapping; 05196 05197 new_statusdata->plugin_output=(plugin_output==NULL)?NULL:strdup(plugin_output); 05198 05199 if (statusdata_list==NULL){ 05200 statusdata_list=new_statusdata; 05201 statusdata_list->next=NULL; 05202 last_statusdata=statusdata_list; 05203 } else { 05204 last_statusdata->next=new_statusdata; 05205 last_statusdata=new_statusdata; 05206 last_statusdata->next=NULL; 05207 } 05208 05209 return OK; 05210 } 05211 05212 /* sorts the service list */ 05213 int sort_status_data(int status_type,int sort_type, int sort_option){ 05214 sort *new_sort; 05215 sort *last_sort; 05216 sort *temp_sort; 05217 statusdata *temp_status=NULL; 05218 05219 if(sort_type==SORT_NONE) 05220 return ERROR; 05221 05222 if(statusdata_list==NULL) 05223 return ERROR; 05224 05225 for(temp_status=statusdata_list;temp_status!=NULL;temp_status=temp_status->next){ 05226 05227 /* allocate memory for a new sort structure */ 05228 new_sort=(sort *)malloc(sizeof(sort)); 05229 if(new_sort==NULL) 05230 return ERROR; 05231 05232 new_sort->status=temp_status; 05233 05234 last_sort=statussort_list; 05235 for(temp_sort=statussort_list;temp_sort!=NULL;temp_sort=temp_sort->next){ 05236 05237 if(compare_sort_entries(status_type,sort_type,sort_option,new_sort,temp_sort)==TRUE){ 05238 new_sort->next=temp_sort; 05239 if(temp_sort==statussort_list) 05240 statussort_list=new_sort; 05241 else 05242 last_sort->next=new_sort; 05243 break; 05244 }else 05245 last_sort=temp_sort; 05246 } 05247 05248 if(statussort_list==NULL){ 05249 new_sort->next=NULL; 05250 statussort_list=new_sort; 05251 } 05252 else if(temp_sort==NULL){ 05253 new_sort->next=NULL; 05254 last_sort->next=new_sort; 05255 } 05256 } 05257 05258 return OK; 05259 } 05260 05261 int compare_sort_entries(int status_type, int sort_type, int sort_option, sort *new_sort, sort *temp_sort){ 05262 statusdata *new_status; 05263 statusdata *temp_status; 05264 05265 new_status=new_sort->status; 05266 temp_status=temp_sort->status; 05267 05268 if(sort_type==SORT_ASCENDING){ 05269 05270 if(sort_option==SORT_LASTCHECKTIME){ 05271 if(new_status->ts_last_check < temp_status->ts_last_check) 05272 return TRUE; 05273 else 05274 return FALSE; 05275 } 05276 else if(sort_option==SORT_CURRENTATTEMPT){ 05277 if(new_status->current_attempt < temp_status->current_attempt) 05278 return TRUE; 05279 else 05280 return FALSE; 05281 } 05282 else if(sort_option==SORT_SERVICESTATUS && status_type == SERVICE_STATUS){ 05283 if(new_status->status <= temp_status->status) 05284 return TRUE; 05285 else 05286 return FALSE; 05287 } 05288 else if(sort_option==SORT_HOSTNAME){ 05289 if(strcasecmp(new_status->host_name,temp_status->host_name)<0) 05290 return TRUE; 05291 else 05292 return FALSE; 05293 } 05294 else if(sort_option==SORT_SERVICENAME && status_type == SERVICE_STATUS){ 05295 if(strcasecmp(new_status->svc_description,temp_status->svc_description)<0) 05296 return TRUE; 05297 else 05298 return FALSE; 05299 } 05300 else if(sort_option==SORT_STATEDURATION){ 05301 if(new_status->ts_state_duration < temp_status->ts_state_duration) 05302 return TRUE; 05303 else 05304 return FALSE; 05305 } 05306 }else{ 05307 if(sort_option==SORT_LASTCHECKTIME){ 05308 if(new_status->ts_last_check > temp_status->ts_last_check) 05309 return TRUE; 05310 else 05311 return FALSE; 05312 } 05313 else if(sort_option==SORT_CURRENTATTEMPT){ 05314 if(new_status->current_attempt > temp_status->current_attempt) 05315 return TRUE; 05316 else 05317 return FALSE; 05318 } 05319 else if(sort_option==SORT_SERVICESTATUS && status_type == SERVICE_STATUS){ 05320 if(new_status->status > temp_status->status) 05321 return TRUE; 05322 else 05323 return FALSE; 05324 } 05325 else if(sort_option==SORT_HOSTNAME){ 05326 if(strcasecmp(new_status->host_name,temp_status->host_name)>0) 05327 return TRUE; 05328 else 05329 return FALSE; 05330 } 05331 else if(sort_option==SORT_SERVICENAME && status_type == SERVICE_STATUS){ 05332 if(strcasecmp(new_status->svc_description,temp_status->svc_description)>0) 05333 return TRUE; 05334 else 05335 return FALSE; 05336 } 05337 else if(sort_option==SORT_STATEDURATION){ 05338 if(new_status->ts_state_duration > temp_status->ts_state_duration) 05339 return TRUE; 05340 else 05341 return FALSE; 05342 } 05343 } 05344 05345 return TRUE; 05346 } 05347 05348 void free_sort_list(void){ 05349 sort *this_sort; 05350 sort *next_sort; 05351 05352 /* free memory for the servicesort list */ 05353 for(this_sort=statussort_list;this_sort!=NULL;this_sort=next_sort){ 05354 next_sort=this_sort->next; 05355 free(this_sort); 05356 } 05357 05358 return; 05359 } 05360 05361 05362 /* check host properties filter */ 05363 int passes_host_properties_filter(hoststatus *temp_hoststatus){ 05364 05365 if((host_properties & HOST_SCHEDULED_DOWNTIME) && temp_hoststatus->scheduled_downtime_depth<=0) 05366 return FALSE; 05367 05368 if((host_properties & HOST_NO_SCHEDULED_DOWNTIME) && temp_hoststatus->scheduled_downtime_depth>0) 05369 return FALSE; 05370 05371 if((host_properties & HOST_STATE_ACKNOWLEDGED) && temp_hoststatus->problem_has_been_acknowledged==FALSE) 05372 return FALSE; 05373 05374 if((host_properties & HOST_STATE_UNACKNOWLEDGED) && temp_hoststatus->problem_has_been_acknowledged==TRUE) 05375 return FALSE; 05376 05377 if((host_properties & HOST_CHECKS_DISABLED) && temp_hoststatus->checks_enabled==TRUE) 05378 return FALSE; 05379 05380 if((host_properties & HOST_CHECKS_ENABLED) && temp_hoststatus->checks_enabled==FALSE) 05381 return FALSE; 05382 05383 if((host_properties & HOST_EVENT_HANDLER_DISABLED) && temp_hoststatus->event_handler_enabled==TRUE) 05384 return FALSE; 05385 05386 if((host_properties & HOST_EVENT_HANDLER_ENABLED) && temp_hoststatus->event_handler_enabled==FALSE) 05387 return FALSE; 05388 05389 if((host_properties & HOST_FLAP_DETECTION_DISABLED) && temp_hoststatus->flap_detection_enabled==TRUE) 05390 return FALSE; 05391 05392 if((host_properties & HOST_FLAP_DETECTION_ENABLED) && temp_hoststatus->flap_detection_enabled==FALSE) 05393 return FALSE; 05394 05395 if((host_properties & HOST_IS_FLAPPING) && temp_hoststatus->is_flapping==FALSE) 05396 return FALSE; 05397 05398 if((host_properties & HOST_IS_NOT_FLAPPING) && temp_hoststatus->is_flapping==TRUE) 05399 return FALSE; 05400 05401 if((host_properties & HOST_NOTIFICATIONS_DISABLED) && temp_hoststatus->notifications_enabled==TRUE) 05402 return FALSE; 05403 05404 if((host_properties & HOST_NOTIFICATIONS_ENABLED) && temp_hoststatus->notifications_enabled==FALSE) 05405 return FALSE; 05406 05407 if((host_properties & HOST_PASSIVE_CHECKS_DISABLED) && temp_hoststatus->accept_passive_host_checks==TRUE) 05408 return FALSE; 05409 05410 if((host_properties & HOST_PASSIVE_CHECKS_ENABLED) && temp_hoststatus->accept_passive_host_checks==FALSE) 05411 return FALSE; 05412 05413 if((host_properties & HOST_PASSIVE_CHECK) && temp_hoststatus->check_type==HOST_CHECK_ACTIVE) 05414 return FALSE; 05415 05416 if((host_properties & HOST_ACTIVE_CHECK) && temp_hoststatus->check_type==HOST_CHECK_PASSIVE) 05417 return FALSE; 05418 05419 if((host_properties & HOST_HARD_STATE) && temp_hoststatus->state_type==SOFT_STATE) 05420 return FALSE; 05421 05422 if((host_properties & HOST_SOFT_STATE) && temp_hoststatus->state_type==HARD_STATE) 05423 return FALSE; 05424 05425 return TRUE; 05426 } 05427 05428 05429 /* check service properties filter */ 05430 int passes_service_properties_filter(servicestatus *temp_servicestatus){ 05431 05432 if((service_properties & SERVICE_SCHEDULED_DOWNTIME) && temp_servicestatus->scheduled_downtime_depth<=0) 05433 return FALSE; 05434 05435 if((service_properties & SERVICE_NO_SCHEDULED_DOWNTIME) && temp_servicestatus->scheduled_downtime_depth>0) 05436 return FALSE; 05437 05438 if((service_properties & SERVICE_STATE_ACKNOWLEDGED) && temp_servicestatus->problem_has_been_acknowledged==FALSE) 05439 return FALSE; 05440 05441 if((service_properties & SERVICE_STATE_UNACKNOWLEDGED) && temp_servicestatus->problem_has_been_acknowledged==TRUE) 05442 return FALSE; 05443 05444 if((service_properties & SERVICE_CHECKS_DISABLED) && temp_servicestatus->checks_enabled==TRUE) 05445 return FALSE; 05446 05447 if((service_properties & SERVICE_CHECKS_ENABLED) && temp_servicestatus->checks_enabled==FALSE) 05448 return FALSE; 05449 05450 if((service_properties & SERVICE_EVENT_HANDLER_DISABLED) && temp_servicestatus->event_handler_enabled==TRUE) 05451 return FALSE; 05452 05453 if((service_properties & SERVICE_EVENT_HANDLER_ENABLED) && temp_servicestatus->event_handler_enabled==FALSE) 05454 return FALSE; 05455 05456 if((service_properties & SERVICE_FLAP_DETECTION_DISABLED) && temp_servicestatus->flap_detection_enabled==TRUE) 05457 return FALSE; 05458 05459 if((service_properties & SERVICE_FLAP_DETECTION_ENABLED) && temp_servicestatus->flap_detection_enabled==FALSE) 05460 return FALSE; 05461 05462 if((service_properties & SERVICE_IS_FLAPPING) && temp_servicestatus->is_flapping==FALSE) 05463 return FALSE; 05464 05465 if((service_properties & SERVICE_IS_NOT_FLAPPING) && temp_servicestatus->is_flapping==TRUE) 05466 return FALSE; 05467 05468 if((service_properties & SERVICE_NOTIFICATIONS_DISABLED) && temp_servicestatus->notifications_enabled==TRUE) 05469 return FALSE; 05470 05471 if((service_properties & SERVICE_NOTIFICATIONS_ENABLED) && temp_servicestatus->notifications_enabled==FALSE) 05472 return FALSE; 05473 05474 if((service_properties & SERVICE_PASSIVE_CHECKS_DISABLED) && temp_servicestatus->accept_passive_service_checks==TRUE) 05475 return FALSE; 05476 05477 if((service_properties & SERVICE_PASSIVE_CHECKS_ENABLED) && temp_servicestatus->accept_passive_service_checks==FALSE) 05478 return FALSE; 05479 05480 if((service_properties & SERVICE_PASSIVE_CHECK) && temp_servicestatus->check_type==SERVICE_CHECK_ACTIVE) 05481 return FALSE; 05482 05483 if((service_properties & SERVICE_ACTIVE_CHECK) && temp_servicestatus->check_type==SERVICE_CHECK_PASSIVE) 05484 return FALSE; 05485 05486 if((service_properties & SERVICE_HARD_STATE) && temp_servicestatus->state_type==SOFT_STATE) 05487 return FALSE; 05488 05489 if((service_properties & SERVICE_SOFT_STATE) && temp_servicestatus->state_type==HARD_STATE) 05490 return FALSE; 05491 05492 return TRUE; 05493 } 05494 05495 05496 /* shows service and host filters in use */ 05497 void show_filters(void){ 05498 int found=0; 05499 05500 /* show filters box if necessary */ 05501 if(host_properties!=0L || service_properties!=0L || host_status_types!=all_host_status_types || service_status_types!=all_service_status_types){ 05502 05503 printf("<table border=1 class='filter' cellspacing=0 cellpadding=0>\n"); 05504 printf("<tr><td valign=top align=left CLASS='filterTitle'>Display Filters: "); 05505 printf("<img id='expand_image' src='%s%s' border=0 onClick=\"if (document.getElementById('filters').style.display == 'none') { document.getElementById('filters').style.display = ''; document.getElementById('expand_image').src = '%s%s'; } else { document.getElementById('filters').style.display = 'none'; document.getElementById('expand_image').src = '%s%s'; }\">",url_images_path,EXPAND_ICON,url_images_path,COLLAPSE_ICON,url_images_path,EXPAND_ICON); 05506 printf("</td></tr>"); 05507 printf("<tr><td><table id='filters' border=0 cellspacing=2 cellpadding=0 style='display:none;'>\n"); 05508 printf("<tr><td valign=top align=left CLASS='filterName'>Host Status Types:</td>"); 05509 printf("<td valign=top align=left CLASS='filterValue'>"); 05510 if(host_status_types==all_host_status_types) 05511 printf("All"); 05512 else if(host_status_types==all_host_problems) 05513 printf("All problems"); 05514 else{ 05515 found=0; 05516 if(host_status_types & HOST_PENDING){ 05517 printf(" Pending"); 05518 found=1; 05519 } 05520 if(host_status_types & HOST_UP){ 05521 printf("%s Up",(found==1)?" |":""); 05522 found=1; 05523 } 05524 if(host_status_types & HOST_DOWN){ 05525 printf("%s Down",(found==1)?" |":""); 05526 found=1; 05527 } 05528 if(host_status_types & HOST_UNREACHABLE) 05529 printf("%s Unreachable",(found==1)?" |":""); 05530 } 05531 printf("</td></tr>"); 05532 printf("<tr><td valign=top align=left CLASS='filterName'>Host Properties:</td>"); 05533 printf("<td valign=top align=left CLASS='filterValue'>"); 05534 if(host_properties==0) 05535 printf("Any"); 05536 else{ 05537 found=0; 05538 if(host_properties & HOST_SCHEDULED_DOWNTIME){ 05539 printf(" In Scheduled Downtime"); 05540 found=1; 05541 } 05542 if(host_properties & HOST_NO_SCHEDULED_DOWNTIME){ 05543 printf("%s Not In Scheduled Downtime",(found==1)?" &":""); 05544 found=1; 05545 } 05546 if(host_properties & HOST_STATE_ACKNOWLEDGED){ 05547 printf("%s Has Been Acknowledged",(found==1)?" &":""); 05548 found=1; 05549 } 05550 if(host_properties & HOST_STATE_UNACKNOWLEDGED){ 05551 printf("%s Has Not Been Acknowledged",(found==1)?" &":""); 05552 found=1; 05553 } 05554 if(host_properties & HOST_CHECKS_DISABLED){ 05555 printf("%s Checks Disabled",(found==1)?" &":""); 05556 found=1; 05557 } 05558 if(host_properties & HOST_CHECKS_ENABLED){ 05559 printf("%s Checks Enabled",(found==1)?" &":""); 05560 found=1; 05561 } 05562 if(host_properties & HOST_EVENT_HANDLER_DISABLED){ 05563 printf("%s Event Handler Disabled",(found==1)?" &":""); 05564 found=1; 05565 } 05566 if(host_properties & HOST_EVENT_HANDLER_ENABLED){ 05567 printf("%s Event Handler Enabled",(found==1)?" &":""); 05568 found=1; 05569 } 05570 if(host_properties & HOST_FLAP_DETECTION_DISABLED){ 05571 printf("%s Flap Detection Disabled",(found==1)?" &":""); 05572 found=1; 05573 } 05574 if(host_properties & HOST_FLAP_DETECTION_ENABLED){ 05575 printf("%s Flap Detection Enabled",(found==1)?" &":""); 05576 found=1; 05577 } 05578 if(host_properties & HOST_IS_FLAPPING){ 05579 printf("%s Is Flapping",(found==1)?" &":""); 05580 found=1; 05581 } 05582 if(host_properties & HOST_IS_NOT_FLAPPING){ 05583 printf("%s Is Not Flapping",(found==1)?" &":""); 05584 found=1; 05585 } 05586 if(host_properties & HOST_NOTIFICATIONS_DISABLED){ 05587 printf("%s Notifications Disabled",(found==1)?" &":""); 05588 found=1; 05589 } 05590 if(host_properties & HOST_NOTIFICATIONS_ENABLED){ 05591 printf("%s Notifications Enabled",(found==1)?" &":""); 05592 found=1; 05593 } 05594 if(host_properties & HOST_PASSIVE_CHECKS_DISABLED){ 05595 printf("%s Passive Checks Disabled",(found==1)?" &":""); 05596 found=1; 05597 } 05598 if(host_properties & HOST_PASSIVE_CHECKS_ENABLED){ 05599 printf("%s Passive Checks Enabled",(found==1)?" &":""); 05600 found=1; 05601 } 05602 if(host_properties & HOST_PASSIVE_CHECK){ 05603 printf("%s Passive Checks",(found==1)?" &":""); 05604 found=1; 05605 } 05606 if(host_properties & HOST_ACTIVE_CHECK){ 05607 printf("%s Active Checks",(found==1)?" &":""); 05608 found=1; 05609 } 05610 if(host_properties & HOST_HARD_STATE){ 05611 printf("%s In Hard State",(found==1)?" &":""); 05612 found=1; 05613 } 05614 if(host_properties & HOST_SOFT_STATE){ 05615 printf("%s In Soft State",(found==1)?" &":""); 05616 found=1; 05617 } 05618 } 05619 printf("</td>"); 05620 printf("</tr>\n"); 05621 05622 05623 printf("<tr><td valign=top align=left CLASS='filterName'>Service Status Types:</td>"); 05624 printf("<td valign=top align=left CLASS='filterValue'>"); 05625 if(service_status_types==all_service_status_types) 05626 printf("All"); 05627 else if(service_status_types==all_service_problems) 05628 printf("All Problems"); 05629 else{ 05630 found=0; 05631 if(service_status_types & SERVICE_PENDING){ 05632 printf(" Pending"); 05633 found=1; 05634 } 05635 if(service_status_types & SERVICE_OK){ 05636 printf("%s Ok",(found==1)?" |":""); 05637 found=1; 05638 } 05639 if(service_status_types & SERVICE_UNKNOWN){ 05640 printf("%s Unknown",(found==1)?" |":""); 05641 found=1; 05642 } 05643 if(service_status_types & SERVICE_WARNING){ 05644 printf("%s Warning",(found==1)?" |":""); 05645 found=1; 05646 } 05647 if(service_status_types & SERVICE_CRITICAL){ 05648 printf("%s Critical",(found==1)?" |":""); 05649 found=1; 05650 } 05651 } 05652 printf("</td></tr>"); 05653 printf("<tr><td valign=top align=left CLASS='filterName'>Service Properties:</td>"); 05654 printf("<td valign=top align=left CLASS='filterValue'>"); 05655 if(service_properties==0) 05656 printf("Any"); 05657 else{ 05658 found=0; 05659 if(service_properties & SERVICE_SCHEDULED_DOWNTIME){ 05660 printf(" In Scheduled Downtime"); 05661 found=1; 05662 } 05663 if(service_properties & SERVICE_NO_SCHEDULED_DOWNTIME){ 05664 printf("%s Not In Scheduled Downtime",(found==1)?" &":""); 05665 found=1; 05666 } 05667 if(service_properties & SERVICE_STATE_ACKNOWLEDGED){ 05668 printf("%s Has Been Acknowledged",(found==1)?" &":""); 05669 found=1; 05670 } 05671 if(service_properties & SERVICE_STATE_UNACKNOWLEDGED){ 05672 printf("%s Has Not Been Acknowledged",(found==1)?" &":""); 05673 found=1; 05674 } 05675 if(service_properties & SERVICE_CHECKS_DISABLED){ 05676 printf("%s Active Checks Disabled",(found==1)?" &":""); 05677 found=1; 05678 } 05679 if(service_properties & SERVICE_CHECKS_ENABLED){ 05680 printf("%s Active Checks Enabled",(found==1)?" &":""); 05681 found=1; 05682 } 05683 if(service_properties & SERVICE_EVENT_HANDLER_DISABLED){ 05684 printf("%s Event Handler Disabled",(found==1)?" &":""); 05685 found=1; 05686 } 05687 if(service_properties & SERVICE_EVENT_HANDLER_ENABLED){ 05688 printf("%s Event Handler Enabled",(found==1)?" &":""); 05689 found=1; 05690 } 05691 if(service_properties & SERVICE_FLAP_DETECTION_DISABLED){ 05692 printf("%s Flap Detection Disabled",(found==1)?" &":""); 05693 found=1; 05694 } 05695 if(service_properties & SERVICE_FLAP_DETECTION_ENABLED){ 05696 printf("%s Flap Detection Enabled",(found==1)?" &":""); 05697 found=1; 05698 } 05699 if(service_properties & SERVICE_IS_FLAPPING){ 05700 printf("%s Is Flapping",(found==1)?" &":""); 05701 found=1; 05702 } 05703 if(service_properties & SERVICE_IS_NOT_FLAPPING){ 05704 printf("%s Is Not Flapping",(found==1)?" &":""); 05705 found=1; 05706 } 05707 if(service_properties & SERVICE_NOTIFICATIONS_DISABLED){ 05708 printf("%s Notifications Disabled",(found==1)?" &":""); 05709 found=1; 05710 } 05711 if(service_properties & SERVICE_NOTIFICATIONS_ENABLED){ 05712 printf("%s Notifications Enabled",(found==1)?" &":""); 05713 found=1; 05714 } 05715 if(service_properties & SERVICE_PASSIVE_CHECKS_DISABLED){ 05716 printf("%s Passive Checks Disabled",(found==1)?" &":""); 05717 found=1; 05718 } 05719 if(service_properties & SERVICE_PASSIVE_CHECKS_ENABLED){ 05720 printf("%s Passive Checks Enabled",(found==1)?" &":""); 05721 found=1; 05722 } 05723 if(service_properties & SERVICE_PASSIVE_CHECK){ 05724 printf("%s Passive Checks",(found==1)?" &":""); 05725 found=1; 05726 } 05727 if(service_properties & SERVICE_ACTIVE_CHECK){ 05728 printf("%s Active Checks",(found==1)?" &":""); 05729 found=1; 05730 } 05731 if(service_properties & SERVICE_HARD_STATE){ 05732 printf("%s In Hard State",(found==1)?" &":""); 05733 found=1; 05734 } 05735 if(service_properties & SERVICE_SOFT_STATE){ 05736 printf("%s In Soft State",(found==1)?" &":""); 05737 found=1; 05738 } 05739 } 05740 printf("</td></tr>"); 05741 printf("</table>\n"); 05742 05743 printf("</td></tr>"); 05744 printf("</table>\n"); 05745 } 05746 05747 return; 05748 } 05749 05750 /******************************************************************/ 05751 /********* DROPDOWN MENU's FOR DETAILED VIEWS ;-) ***************/ 05752 /******************************************************************/ 05753 05754 /* Display a table with the commands for checked checkboxes, for services */ 05755 void show_servicecommand_table(void){ 05756 if (is_authorized_for_read_only(¤t_authdata)==FALSE){ 05757 /* A new div for the command table */ 05758 printf("<DIV CLASS='serviceTotalsCommands'>Commands for checked services</DIV>\n"); 05759 /* DropDown menu */ 05760 printf("<select name='webmenu' id='webmenu' onchange='showValue(this.value,%d,%d)'CLASS='serviceTotalsCommands'>",CMD_SCHEDULE_HOST_CHECK,CMD_SCHEDULE_SVC_CHECK); 05761 printf("<option value='nothing'>Select command</option>"); 05762 printf("<option value='%d' title='%s%s' >Add a Comment to Checked Service(s)</option>",CMD_ADD_SVC_COMMENT,url_images_path,COMMENT_ICON); 05763 printf("<option value='%d' title='%s%s'>Disable Active Checks Of Checked Service(s)</option>",CMD_DISABLE_SVC_CHECK,url_images_path,DISABLED_ICON); 05764 printf("<option value='%d' title='%s%s'>Enable Active Checks Of Checked Service(s)</option>",CMD_ENABLE_SVC_CHECK,url_images_path,ENABLED_ICON); 05765 printf("<option value='%d' title='%s%s'>Re-schedule Next Service Check</option>",CMD_SCHEDULE_SVC_CHECK,url_images_path,DELAY_ICON); 05766 printf("<option value='%d' title='%s%s'>Submit Passive Check Result For Checked Service(s)</option>",CMD_PROCESS_SERVICE_CHECK_RESULT,url_images_path,PASSIVE_ICON); 05767 printf("<option value='%d' title='%s%s'>Stop Accepting Passive Checks For Checked Service(s)</option>",CMD_DISABLE_PASSIVE_SVC_CHECKS,url_images_path,DISABLED_ICON); 05768 printf("<option value='%d' title='%s%s'>Start Accepting Passive Checks For Checked Service(s)</option>",CMD_ENABLE_PASSIVE_SVC_CHECKS,url_images_path,ENABLED_ICON); 05769 printf("<option value='%d' title='%s%s'>Stop Obsessing Over Checked Service(s)</option>",CMD_STOP_OBSESSING_OVER_SVC,url_images_path,DISABLED_ICON); 05770 printf("<option value='%d' title='%s%s'>Start Obsessing Over Checked Service(s)</option>",CMD_START_OBSESSING_OVER_SVC,url_images_path,ENABLED_ICON); 05771 printf("<option value='%d' title='%s%s'>Acknowledge Checked Service(s) Problem</option>",CMD_ACKNOWLEDGE_SVC_PROBLEM,url_images_path,ACKNOWLEDGEMENT_ICON); 05772 printf("<option value='%d' title='%s%s'>Remove Problem Acknowledgement for Checked Service(s)</option>",CMD_REMOVE_SVC_ACKNOWLEDGEMENT,url_images_path,REMOVE_ACKNOWLEDGEMENT_ICON); 05773 printf("<option value='%d' title='%s%s'>Disable Notifications For Checked Service(s)</option>",CMD_DISABLE_SVC_NOTIFICATIONS,url_images_path,DISABLED_ICON); 05774 printf("<option value='%d' title='%s%s'>Enable Notifications For Checked Service(s)</option>",CMD_ENABLE_SVC_NOTIFICATIONS,url_images_path,ENABLED_ICON); 05775 printf("<option value='%d' title='%s%s'>Send Custom Notification For Checked Service(s)</option>",CMD_SEND_CUSTOM_SVC_NOTIFICATION,url_images_path,NOTIFICATION_ICON); 05776 printf("<option value='%d' title='%s%s'>Delay Next Notification For Checked Service(s)</option>",CMD_DELAY_SVC_NOTIFICATION,url_images_path,DELAY_ICON); 05777 printf("<option value='%d' title='%s%s'>Schedule Downtime For Checked Service(s)</option>",CMD_SCHEDULE_SVC_DOWNTIME,url_images_path,DOWNTIME_ICON); 05778 printf("<option value='%d' title='%s%s'>Disable Event Handler For Checked Service(s)</option>",CMD_DISABLE_SVC_EVENT_HANDLER,url_images_path,DISABLED_ICON); 05779 printf("<option value='%d' title='%s%s'>Enable Event Handler For Checked Service(s)</option>",CMD_ENABLE_SVC_EVENT_HANDLER,url_images_path,ENABLED_ICON); 05780 printf("<option value='%d' title='%s%s'>Disable Flap Detection For Checked Service(s)</option>",CMD_DISABLE_SVC_FLAP_DETECTION,url_images_path,DISABLED_ICON); 05781 printf("<option value='%d' title='%s%s'>Enable Flap Detection For Checked Service(s)</option>",CMD_ENABLE_SVC_FLAP_DETECTION,url_images_path,ENABLED_ICON); 05782 printf("</select>"); 05783 printf("<br><br><b><input type='button' name='CommandButton' value='Submit' class='serviceTotalsCommands' onClick=\"cmd_submit('tableform')\" disabled='disabled'></b>\n"); 05784 } 05785 } 05786 05787 /* Display a table with the commands for checked checkboxes, for hosts */ 05788 void show_hostcommand_table(void){ 05789 if (is_authorized_for_read_only(¤t_authdata)==FALSE){ 05790 /* A new div for the command table */ 05791 printf("<DIV CLASS='hostTotalsCommands'>Commands for checked host(s)</DIV>\n"); 05792 /* DropDown menu */ 05793 printf("<select name='webmenu' id='webmenu' onchange='showValue(this.value,%d,%d)' CLASS='hostTotalsCommands'>",CMD_SCHEDULE_HOST_CHECK,CMD_SCHEDULE_SVC_CHECK); 05794 printf("<option value='nothing'>Select command</option>"); 05795 printf("<option value='%d' title='%s%s' >Add a Comment to Checked Host(s)</option>",CMD_ADD_HOST_COMMENT,url_images_path,COMMENT_ICON); 05796 printf("<option value='%d' title='%s%s' >Disable Active Checks Of Checked Host(s)</option>",CMD_DISABLE_HOST_CHECK,url_images_path,DISABLED_ICON); 05797 printf("<option value='%d' title='%s%s' >Enable Active Checks Of Checked Host(s)'</option>",CMD_ENABLE_HOST_CHECK,url_images_path,ENABLED_ICON); 05798 printf("<option value='%d' title='%s%s' >Re-schedule Next Host Check</option>",CMD_SCHEDULE_HOST_CHECK,url_images_path,DELAY_ICON); 05799 printf("<option value='%d' title='%s%s' >Submit Passive Check Result For Checked Host(s)</option>",CMD_PROCESS_HOST_CHECK_RESULT,url_images_path,PASSIVE_ICON); 05800 printf("<option value='%d' title='%s%s' >Stop Accepting Passive Checks For Checked Host(s)</option>",CMD_DISABLE_PASSIVE_HOST_CHECKS,url_images_path,DISABLED_ICON); 05801 printf("<option value='%d' title='%s%s' >Start Accepting Passive Checks For Checked Host(s)</option>",CMD_ENABLE_PASSIVE_HOST_CHECKS,url_images_path,ENABLED_ICON); 05802 printf("<option value='%d' title='%s%s' >Stop Obsessing Over Checked Host(s)</option>",CMD_STOP_OBSESSING_OVER_HOST,url_images_path,DISABLED_ICON); 05803 printf("<option value='%d' title='%s%s' >Start Obsessing Over Checked Host(s)</option>",CMD_START_OBSESSING_OVER_HOST,url_images_path,ENABLED_ICON); 05804 printf("<option value='%d' title='%s%s' >Acknowledge Checked Host(s) Problem</option>",CMD_ACKNOWLEDGE_HOST_PROBLEM,url_images_path,ACKNOWLEDGEMENT_ICON); 05805 printf("<option value='%d' title='%s%s' >Remove Problem Acknowledgement</option>",CMD_REMOVE_HOST_ACKNOWLEDGEMENT,url_images_path,REMOVE_ACKNOWLEDGEMENT_ICON); 05806 printf("<option value='%d' title='%s%s' >Disable Notifications For Checked Host(s)</option>",CMD_DISABLE_HOST_NOTIFICATIONS,url_images_path,DISABLED_ICON); 05807 printf("<option value='%d' title='%s%s' >Enable Notifications For Checked Host(s)</option>",CMD_ENABLE_HOST_NOTIFICATIONS,url_images_path,ENABLED_ICON); 05808 printf("<option value='%d' title='%s%s' >Send Custom Notification</option>",CMD_SEND_CUSTOM_HOST_NOTIFICATION,url_images_path,NOTIFICATION_ICON); 05809 printf("<option value='%d' title='%s%s' >Delay Next Host Notification</option>",CMD_DELAY_HOST_NOTIFICATION,url_images_path,DELAY_ICON); 05810 printf("<option value='%d' title='%s%s' >Schedule Downtime For Checked Host(s)</option>",CMD_SCHEDULE_HOST_DOWNTIME,url_images_path,DOWNTIME_ICON); 05811 printf("<option value='%d' title='%s%s' >Schedule Downtime For Checked Host(s) and All Services</option>",CMD_SCHEDULE_HOST_SVC_DOWNTIME,url_images_path,DOWNTIME_ICON); 05812 printf("<option value='%d' title='%s%s' >Disable Notifications For All Services On Checked Host(s)</option>",CMD_DISABLE_HOST_SVC_NOTIFICATIONS,url_images_path,DISABLED_ICON); 05813 printf("<option value='%d' title='%s%s' >Enable Notifications For All Services On Checked Host(s)</option>",CMD_ENABLE_HOST_SVC_NOTIFICATIONS,url_images_path,ENABLED_ICON); 05814 printf("<option value='%d' title='%s%s' >Schedule A Check Of All Services On Checked Host(s)</option>",CMD_SCHEDULE_HOST_SVC_CHECKS,url_images_path,DELAY_ICON); 05815 printf("<option value='%d' title='%s%s' >Disable Checks Of All Services On Checked Host(s)</option>",CMD_DISABLE_HOST_SVC_CHECKS,url_images_path,DISABLED_ICON); 05816 printf("<option value='%d' title='%s%s' >Enable Checks Of All Services On Checked Host(s)</option>",CMD_ENABLE_HOST_SVC_CHECKS,url_images_path,ENABLED_ICON); 05817 printf("<option value='%d' title='%s%s' >Disable Event Handler For Checked Host(s)</option>",CMD_DISABLE_HOST_EVENT_HANDLER,url_images_path,DISABLED_ICON); 05818 printf("<option value='%d' title='%s%s' >Enable Event Handler For Checked Host(s)</option>",CMD_ENABLE_HOST_EVENT_HANDLER,url_images_path,ENABLED_ICON); 05819 printf("<option value='%d' title='%s%s' >Disable Flap Detection For Checked Host(s)</option>",CMD_DISABLE_HOST_FLAP_DETECTION,url_images_path,DISABLED_ICON); 05820 printf("<option value='%d' title='%s%s' >Enable Flap Detection For Checked Host(s)</option>",CMD_ENABLE_HOST_FLAP_DETECTION,url_images_path,ENABLED_ICON); 05821 printf("</select>"); 05822 printf("<br><br><b><input type='button' name='CommandButton' value='Submit' class='hostsTotalsCommands' onClick=\"cmd_submit('tableform')\" disabled='disabled'></b>\n"); 05823 } 05824 } 05825 /* The cake is a lie! */ 05826 05827 /******************************************************************/ 05828 /********* print a tooltip to show comments *********************/ 05829 /******************************************************************/ 05830 void print_comment_icon(char *host_name, char *svc_description) { 05831 comment *temp_comment=NULL; 05832 char *comment_entry_type=""; 05833 char comment_data[MAX_INPUT_BUFFER]=""; 05834 char entry_time[MAX_DATETIME_LENGTH]; 05835 int len,output_len; 05836 int x,y; 05837 char *escaped_output_string=NULL; 05838 int saved_escape_html_tags_var=FALSE; 05839 05840 if(svc_description==NULL) 05841 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s'",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(host_name)); 05842 else{ 05843 printf("<TD ALIGN=center valign=center><A HREF='%s?type=%d&host=%s",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(host_name)); 05844 printf("&service=%s#comments'",url_encode(svc_description)); 05845 } 05846 /* possible to implement a config option to show and hide comments tooltip in status.cgi */ 05847 /* but who wouldn't like to have these fancy tooltips ;-) */ 05848 if(TRUE){ 05849 printf(" onMouseOver=\"return tooltip('<table border=0 width=100%% height=100%% cellpadding=3>"); 05850 printf("<tr style=font-weight:bold;><td width=10%% nowrap>Type </td><td width=12%%>Time</td><td>Comment</td></tr>"); 05851 for(temp_comment=get_first_comment_by_host(host_name);temp_comment!=NULL;temp_comment=get_next_comment_by_host(host_name,temp_comment)){ 05852 if((svc_description==NULL && temp_comment->comment_type==HOST_COMMENT) || \ 05853 (svc_description!=NULL && temp_comment->comment_type==SERVICE_COMMENT && !strcmp(temp_comment->service_description,svc_description))) { 05854 switch(temp_comment->entry_type) { 05855 case USER_COMMENT: 05856 comment_entry_type="User"; 05857 break; 05858 case DOWNTIME_COMMENT: 05859 comment_entry_type="Downtime"; 05860 break; 05861 case FLAPPING_COMMENT: 05862 comment_entry_type="Flapping"; 05863 break; 05864 case ACKNOWLEDGEMENT_COMMENT: 05865 comment_entry_type="Ack"; 05866 break; 05867 } 05868 snprintf(comment_data,sizeof(comment_data)-1,"%s",temp_comment->comment_data); 05869 comment_data[sizeof(comment_data)-1]='\x0'; 05870 05871 /* we need up to twice the space to do the conversion of single, double quotes and back slash's */ 05872 len=(int)strlen(comment_data); 05873 output_len=len*2; 05874 if((escaped_output_string=(char *)malloc(output_len+1))!=NULL) { 05875 05876 strcpy(escaped_output_string,""); 05877 05878 for(x=0,y=0;x<=len;x++){ 05879 /* end of string */ 05880 if((char)comment_data[x]==(char)'\x0'){ 05881 escaped_output_string[y]='\x0'; 05882 break; 05883 } else if((char)comment_data[x]==(char)'\n' || (char)comment_data[x]==(char)'\r') { 05884 escaped_output_string[y]=' '; 05885 } else if((char)comment_data[x]==(char)'\'') { 05886 escaped_output_string[y]='\x0'; 05887 if((int)strlen(escaped_output_string)<(output_len-2)){ 05888 strcat(escaped_output_string,"\\'"); 05889 y+=2; 05890 } 05891 } else if((char)comment_data[x]==(char)'"') { 05892 escaped_output_string[y]='\x0'; 05893 if((int)strlen(escaped_output_string)<(output_len-2)){ 05894 strcat(escaped_output_string,"\\\""); 05895 y+=2; 05896 } 05897 } else if((char)comment_data[x]==(char)'\\') { 05898 escaped_output_string[y]='\x0'; 05899 if((int)strlen(escaped_output_string)<(output_len-2)){ 05900 strcat(escaped_output_string,"\\\\"); 05901 y+=2; 05902 } 05903 } else 05904 escaped_output_string[y++]=comment_data[x]; 05905 05906 } 05907 escaped_output_string[++y]='\x0'; 05908 } else 05909 strcpy(escaped_output_string,comment_data); 05910 05911 /* get entry time */ 05912 get_time_string(&temp_comment->entry_time,entry_time,(int)sizeof(entry_time),SHORT_DATE_TIME); 05913 05914 /* in the tooltips we have to escape all characters */ 05915 saved_escape_html_tags_var=escape_html_tags; 05916 escape_html_tags=TRUE; 05917 05918 printf("<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td></tr>",comment_entry_type,entry_time,html_encode(escaped_output_string,TRUE)); 05919 05920 escape_html_tags=saved_escape_html_tags_var; 05921 05922 free(escaped_output_string); 05923 } 05924 } 05925 /* under http://www.ebrueggeman.com/skinnytip/documentation.php#reference you can find the config options of skinnytip */ 05926 printf("</table>', ' Comments', 'border:1, width:600, bordercolor:#333399, title_padding:2px, titletextcolor:#FFFFFF, backcolor:#CCCCFF');\" onMouseOut=\"return hideTip()\""); 05927 } 05928 printf("><IMG SRC='%s%s' BORDER=0 WIDTH=%d HEIGHT=%d></A></TD>",url_images_path,COMMENT_ICON,STATUS_ICON_WIDTH,STATUS_ICON_HEIGHT); 05929 05930 return; 05931 } 05932