--- nagios-3.2.0/cgi/statusmap.c 2009-10-22 14:54:22.000000000 +0300 +++ nagios-3.2.0/cgi/statusmap.c 2009-10-22 16:11:22.450924994 +0300 @@ -27,6 +27,10 @@ * *****************************************************************************/ +#include +#include +#include + #include "../include/config.h" #include "../include/common.h" #include "../include/objects.h" @@ -88,13 +92,29 @@ #define LAYOUT_CIRCULAR 4 #define LAYOUT_CIRCULAR_MARKUP 5 #define LAYOUT_CIRCULAR_BALLOON 6 +#define LAYOUT_GOOGLEMAP 7 +/*#define DEBUG 1*/ typedef struct layer_struct{ char *layer_name; struct layer_struct *next; }layer; +typedef struct location_t { + char* name; + char* note; + char* latitude; + char* longitude; + struct location_t* next; +} location_t; + +typedef struct general_location_t { + char* key; + char* zoom; + char* latitude; + char* longitude; +} general_location_t; void document_header(int); void document_footer(void); @@ -112,6 +132,10 @@ void draw_background_image(void); void draw_background_extras(void); void draw_host_links(void); + +void google_map(void); +void write_google_head_code(void); + void draw_hosts(void); void draw_host_text(char *,int,int); void draw_text(char *,int,int,int); @@ -333,9 +357,14 @@ /* write JavaScript code for popup window */ write_popup_code(); + if ( layout_method == LAYOUT_GOOGLEMAP ) + write_google_head_code(); printf("\n"); - printf("\n"); + if ( layout_method == LAYOUT_GOOGLEMAP ) { + printf("\n"); + } else + printf("\n"); /* include user SSI header */ include_ssi_files(STATUSMAP_CGI,SSI_HEADER); @@ -703,7 +732,7 @@ /* right hand column of top row */ printf("\n"); - printf("
\n",STATUSMAP_CGI); + printf("\n",STATUSMAP_CGI); printf("\n"); printf("\n"); printf("
\n"); printf("\n",escape_string(host_name)); @@ -717,6 +746,7 @@ printf("\n"); @@ -794,6 +824,11 @@ /* display page header */ display_page_header(); + if (layout_method==LAYOUT_GOOGLEMAP){ + google_map(); + return; + } + initialize_graphics(); draw_background_image(); draw_background_extras(); @@ -848,6 +883,13 @@ /******************************/ + /***** GOOGLEMAP LAYOUT MODE *****/ + /******************************/ + if(layout_method==LAYOUT_GOOGLEMAP){ + + } + + /******************************/ /***** MANUAL LAYOUT MODE *****/ /******************************/ @@ -1535,10 +1577,19 @@ return; } +/* create the googlemap */ +void google_map(void){ + printf("\n"); + printf("

"); + printf("
"); + printf("

"); + printf("\n"); +} /* draws hosts */ void draw_hosts(void){ + host *temp_host; int x1, x2; int y1, y2; @@ -1558,6 +1609,8 @@ int translated_x; int translated_y; + if (layout_method==LAYOUT_GOOGLEMAP) + return; /* user didn't supply any coordinates for hosts, so display a warning */ if(coordinates_were_specified==FALSE){ @@ -2213,6 +2266,301 @@ /************************* MISC FUNCTIONS *************************/ /******************************************************************/ +int check_auth_location_host(char* name) +{ + int retVal=FALSE; + host *this_host; + + //printf("false=%d,true=%d\n",FALSE,TRUE); + this_host=find_host(name); + // printf("this_host=%s\n",this_host->name); + // printf("current_auth=%s\n",¤t_authdata); + retVal=is_authorized_for_host(this_host,¤t_authdata); + // printf("is_auth=%d\n",retVal); + return retVal; +} + +char* get_status_code(char* name) +{ + char* retVal; + hoststatus *temp_status; + temp_status=find_hoststatus(name); + + /* strip nasty stuff from plugin output */ + sanitize_plugin_output(temp_status->plugin_output); + + retVal=malloc(1000); + retVal[0]=0; + if(temp_status->status==HOST_DOWN){ + strcat(retVal,"Down"); + if(temp_status->problem_has_been_acknowledged==TRUE) + strcat(retVal," (Acknowledged)"); + strcat(retVal, ""); + } + + else if(temp_status->status==HOST_UNREACHABLE){ + strcat(retVal, "Unreachable"); + if(temp_status->problem_has_been_acknowledged==TRUE) + strcat(retVal, " (Acknowledged)"); + strcat(retVal, ""); + } + + else if(temp_status->status==HOST_UP) + strcat(retVal, "Up"); + + else if(temp_status->status==HOST_PENDING) + strcat(retVal, "Pending"); + return retVal; +} + +void write_google_head_code(void) +{ + char ch; + char* ptr; + int rc; + FILE *fp; + char stateinfo[1024]; + char line[1024]; + char key[1024]; + char value[1024]; + char buf[256]; + char* filename; + int state = 0; + int counter = 0; + general_location_t gen_loc; + location_t* loc; + location_t* loc_list=NULL; + + +/*************************************** + * parse location.cfg + **************************************/ + + filename = "/etc/webapps/nagios/location.cfg"; + if((fp=fopen(filename, "r"))==NULL) { + char* err_mess = "The file: location.cfg does not exist or could not be read"; + printf("

"); + printf("%s\r\n",err_mess); + printf("

"); + return; + } + + while(fgets(buf, sizeof(buf), fp)!=NULL) { + if ( (state == 1) && (buf[0] == '}')) { + // we have reached a definition end + state = 0; + counter++; + if (loc_list) { + loc->next = loc_list; + loc_list = loc; + } else { + loc_list = loc; + } + loc = NULL; + continue; + } + if ( (state==2) && (buf[0] == '}')) { + state=0; + } + key[0] = value[0] = 0; + if (isspace(buf[0])) + rc = sscanf(buf, "%*[ \t]%[^ \t]%*[ \t]%[^\n]", key, value); + else + rc = sscanf(buf, "%[^ \t]%*[ \t]%[^\n]", key, value); + + if ( (rc == 2)) { + if ( (state == 0) && (strcmp(key,"define")==0) ) { + // we have a start of a new definition + + // check if it is the default definition + if ( (strncmp(value,"default ",8)==0) || + (strncmp(value,"default{",8)==0)) { + state=2; + continue; + } + state = 1; + // declare a new location + loc = calloc(1,sizeof(*loc)); + continue; + } + // state 2 == default definition + if ( state == 2 ) { + if ( strcmp(key,"key") == 0) { + gen_loc.key=strdup(value); + } + if ( strcmp(key,"zoom") == 0) { + gen_loc.zoom=strdup(value); + } + if ( strcmp(key,"lat") == 0) { + gen_loc.latitude=strdup(value); + } + if ( strcmp(key,"long") == 0) { + gen_loc.longitude=strdup(value); + } + } + // state 1 == location definition + if ( state == 1 ) { + if ( strcmp(key,"host_name") == 0) { + loc->name=strdup(value); + } + if ( strcmp(key,"notes") == 0) { + loc->note = strdup(value); + } + if ( strcmp(key,"lat") == 0) { + loc->latitude = strdup(value); + } + if ( strcmp(key,"long") == 0) { + loc->longitude = strdup(value); + } + } + } + } + fclose(fp); + + printf("\n",gen_loc.key); + + printf("\n"); +} /* write JavaScript code an layer for popup window */ void write_popup_code(void){