--- nagios-3.2.0/cgi/statusmap.c 2009-10-22 18:19:21.913340828 +0300 +++ nagios-3.2.0.googlemap/cgi/statusmap.c 2009-10-22 18:19:06.830007817 +0300 @@ -27,6 +27,10 @@ * *****************************************************************************/ +#include +#include +#include + #include "../include/config.h" #include "../include/common.h" #include "../include/objects.h" @@ -93,13 +97,27 @@ #define LAYOUT_CIRCULAR 4 #define LAYOUT_CIRCULAR_MARKUP 5 #define LAYOUT_CIRCULAR_BALLOON 6 - +#define LAYOUT_GOOGLEMAP 7 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); @@ -117,6 +135,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); @@ -288,12 +310,11 @@ /* initialize macros */ init_macros(); - - document_header(TRUE); - /* get authentication information */ get_authentication_information(¤t_authdata); + document_header(TRUE); + /* display the network map... */ display_map(); @@ -345,9 +366,14 @@ /* write JavaScript code for popup window */ write_popup_code(); + if (layout_method == LAYOUT_GOOGLEMAP) + write_google_head_code(); printf("\n"); + if (layout_method == LAYOUT_GOOGLEMAP) { + printf("\n"); + } else printf("\n"); /* include user SSI header */ @@ -703,7 +729,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)); @@ -725,6 +751,7 @@ printf("\n"); @@ -821,6 +848,11 @@ /* display page header */ display_page_header(); + if (layout_method==LAYOUT_GOOGLEMAP){ + google_map(); + return; + } + initialize_graphics(); draw_background_image(); draw_background_extras(); @@ -1563,10 +1602,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; @@ -1586,6 +1634,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){ @@ -2241,6 +2291,197 @@ /************************* MISC FUNCTIONS *************************/ /******************************************************************/ +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"); + + printf("\n",gen_loc.key); + printf("\n", url_images_path); +} /* write JavaScript code an layer for popup window */ void write_popup_code(void){