]> git.pld-linux.org Git - packages/nagios.git/blame - nagios-googlemap.patch
This commit was manufactured by cvs2git to create branch 'AC-branch'.
[packages/nagios.git] / nagios-googlemap.patch
CommitLineData
455492e8
ER
1--- nagios-3.2.0/cgi/statusmap.c 2009-10-22 18:19:21.913340828 +0300
2+++ nagios-3.2.0.googlemap/cgi/statusmap.c 2009-10-22 18:19:06.830007817 +0300
6442e2ee
ER
3@@ -27,6 +27,10 @@
4 *
5 *****************************************************************************/
6
7+#include <stdio.h>
8+#include <stdlib.h>
9+#include <string.h>
10+
11 #include "../include/config.h"
12 #include "../include/common.h"
13 #include "../include/objects.h"
b7e814c5 14@@ -93,13 +97,27 @@
6442e2ee
ER
15 #define LAYOUT_CIRCULAR 4
16 #define LAYOUT_CIRCULAR_MARKUP 5
17 #define LAYOUT_CIRCULAR_BALLOON 6
b7e814c5 18-
6442e2ee
ER
19+#define LAYOUT_GOOGLEMAP 7
20
6442e2ee
ER
21 typedef struct layer_struct{
22 char *layer_name;
23 struct layer_struct *next;
24 }layer;
25
26+typedef struct location_t {
27+ char* name;
28+ char* note;
29+ char* latitude;
30+ char* longitude;
31+ struct location_t* next;
32+} location_t;
33+
34+typedef struct general_location_t {
35+ char* key;
36+ char* zoom;
37+ char* latitude;
38+ char* longitude;
39+} general_location_t;
40
41 void document_header(int);
42 void document_footer(void);
b7e814c5 43@@ -117,6 +135,10 @@
6442e2ee
ER
44 void draw_background_image(void);
45 void draw_background_extras(void);
46 void draw_host_links(void);
47+
48+void google_map(void);
49+void write_google_head_code(void);
50+
51 void draw_hosts(void);
52 void draw_host_text(char *,int,int);
53 void draw_text(char *,int,int,int);
26cc3b6f
ER
54@@ -288,12 +310,11 @@
55 /* initialize macros */
56 init_macros();
57
58-
59- document_header(TRUE);
60-
61 /* get authentication information */
62 get_authentication_information(&current_authdata);
63
64+ document_header(TRUE);
65+
66 /* display the network map... */
67 display_map();
68
69@@ -345,9 +366,14 @@
b7e814c5 70
6442e2ee
ER
71 /* write JavaScript code for popup window */
72 write_popup_code();
b7e814c5 73+ if (layout_method == LAYOUT_GOOGLEMAP)
6442e2ee
ER
74+ write_google_head_code();
75
76 printf("</head>\n");
77
b7e814c5 78+ if (layout_method == LAYOUT_GOOGLEMAP) {
6442e2ee
ER
79+ printf("<body onload='load()' onunload='GUnload()' CLASS='statusmap' name='mappage' id='mappage'>\n");
80+ } else
b7e814c5 81 printf("<body CLASS='statusmap' name='mappage' id='mappage'>\n");
6442e2ee
ER
82
83 /* include user SSI header */
26cc3b6f 84@@ -703,7 +729,7 @@
6442e2ee
ER
85 /* right hand column of top row */
86 printf("<td align=right valign=top>\n");
87
88- printf("<form method=\"POST\" action=\"%s\">\n",STATUSMAP_CGI);
89+ printf("<form name=\"layoutform\" method=\"POST\" action=\"%s\">\n",STATUSMAP_CGI);
90 printf("<table border=0 CLASS='optBox'>\n");
91 printf("<tr><td valign=top>\n");
92 printf("<input type='hidden' name='host' value='%s'>\n",escape_string(host_name));
26cc3b6f 93@@ -725,6 +751,7 @@
6442e2ee
ER
94 printf("<option value=%d %s>Circular\n",LAYOUT_CIRCULAR,(layout_method==LAYOUT_CIRCULAR)?"selected":"");
95 printf("<option value=%d %s>Circular (Marked Up)\n",LAYOUT_CIRCULAR_MARKUP,(layout_method==LAYOUT_CIRCULAR_MARKUP)?"selected":"");
96 printf("<option value=%d %s>Circular (Balloon)\n",LAYOUT_CIRCULAR_BALLOON,(layout_method==LAYOUT_CIRCULAR_BALLOON)?"selected":"");
97+ printf("<option value=%d %s>Googlemap\n",LAYOUT_GOOGLEMAP,(layout_method==LAYOUT_GOOGLEMAP)?"selected":"");
98 printf("</select>\n");
99 printf("</td>\n");
100 printf("<td CLASS='optBoxItem'>\n");
26cc3b6f 101@@ -821,6 +848,11 @@
6442e2ee
ER
102 /* display page header */
103 display_page_header();
104
105+ if (layout_method==LAYOUT_GOOGLEMAP){
106+ google_map();
107+ return;
108+ }
109+
110 initialize_graphics();
111 draw_background_image();
112 draw_background_extras();
26cc3b6f 113@@ -1563,10 +1602,19 @@
6442e2ee
ER
114 return;
115 }
116
117+/* create the googlemap */
118+void google_map(void){
119+ printf("<!-- Produced by Infoflex Connect AB (http://www.infoflexconnect.se), Fredrik Nilsson and Rujinschi Remus. -->\n");
120+ printf("<P><DIV ALIGN=center>");
121+ printf("<div id='map' style='width: 800px; height: 500px'></div>");
122+ printf("</DIV></P>");
123+ printf("<!-- Produced by Infoflex Connect AB (http://www.infoflexconnect.se), Fredrik Nilsson and Rujinschi Remus. -->\n");
124
125+}
126
127 /* draws hosts */
128 void draw_hosts(void){
129+
130 host *temp_host;
131 int x1, x2;
132 int y1, y2;
26cc3b6f 133@@ -1586,6 +1634,8 @@
6442e2ee
ER
134 int translated_x;
135 int translated_y;
136
455492e8 137+ if (layout_method == LAYOUT_GOOGLEMAP)
6442e2ee
ER
138+ return;
139
140 /* user didn't supply any coordinates for hosts, so display a warning */
141 if(coordinates_were_specified==FALSE){
455492e8 142@@ -2241,6 +2291,197 @@
6442e2ee
ER
143 /************************* MISC FUNCTIONS *************************/
144 /******************************************************************/
145
6442e2ee
ER
146+char* get_status_code(char* name)
147+{
148+ char* retVal;
149+ hoststatus *temp_status;
150+ temp_status=find_hoststatus(name);
151+
152+ /* strip nasty stuff from plugin output */
153+ sanitize_plugin_output(temp_status->plugin_output);
154+
155+ retVal=malloc(1000);
156+ retVal[0]=0;
157+ if(temp_status->status==HOST_DOWN){
158+ strcat(retVal,"Down");
159+ if(temp_status->problem_has_been_acknowledged==TRUE)
160+ strcat(retVal," (Acknowledged)");
161+ strcat(retVal, "");
162+ }
163+
164+ else if(temp_status->status==HOST_UNREACHABLE){
165+ strcat(retVal, "Unreachable");
166+ if(temp_status->problem_has_been_acknowledged==TRUE)
167+ strcat(retVal, " (Acknowledged)");
168+ strcat(retVal, "");
169+ }
170+
171+ else if(temp_status->status==HOST_UP)
172+ strcat(retVal, "Up");
173+
174+ else if(temp_status->status==HOST_PENDING)
175+ strcat(retVal, "Pending");
176+ return retVal;
177+}
178+
179+void write_google_head_code(void)
180+{
181+ char ch;
182+ char* ptr;
183+ int rc;
184+ FILE *fp;
185+ char stateinfo[1024];
186+ char line[1024];
187+ char key[1024];
188+ char value[1024];
b7e814c5 189+ char buf[256];
6442e2ee
ER
190+ char* filename;
191+ int state = 0;
192+ int counter = 0;
193+ general_location_t gen_loc;
194+ location_t* loc;
195+ location_t* loc_list=NULL;
196+
197+
198+/***************************************
199+ * parse location.cfg
200+ **************************************/
201+
202+ filename = "/etc/webapps/nagios/location.cfg";
203+ if((fp=fopen(filename, "r"))==NULL) {
204+ char* err_mess = "The file: location.cfg does not exist or could not be read";
205+ printf("<p>");
206+ printf("<font color=\"red\">%s</font>\r\n",err_mess);
207+ printf("</p>");
208+ return;
209+ }
210+
211+ while(fgets(buf, sizeof(buf), fp)!=NULL) {
212+ if ( (state == 1) && (buf[0] == '}')) {
213+ // we have reached a definition end
214+ state = 0;
215+ counter++;
216+ if (loc_list) {
217+ loc->next = loc_list;
218+ loc_list = loc;
219+ } else {
220+ loc_list = loc;
221+ }
222+ loc = NULL;
223+ continue;
224+ }
225+ if ( (state==2) && (buf[0] == '}')) {
226+ state=0;
227+ }
228+ key[0] = value[0] = 0;
229+ if (isspace(buf[0]))
230+ rc = sscanf(buf, "%*[ \t]%[^ \t]%*[ \t]%[^\n]", key, value);
231+ else
232+ rc = sscanf(buf, "%[^ \t]%*[ \t]%[^\n]", key, value);
233+
234+ if ( (rc == 2)) {
235+ if ( (state == 0) && (strcmp(key,"define")==0) ) {
236+ // we have a start of a new definition
237+
238+ // check if it is the default definition
239+ if ( (strncmp(value,"default ",8)==0) ||
240+ (strncmp(value,"default{",8)==0)) {
241+ state=2;
242+ continue;
243+ }
244+ state = 1;
245+ // declare a new location
246+ loc = calloc(1,sizeof(*loc));
247+ continue;
248+ }
249+ // state 2 == default definition
250+ if ( state == 2 ) {
251+ if ( strcmp(key,"key") == 0) {
252+ gen_loc.key=strdup(value);
253+ }
254+ if ( strcmp(key,"zoom") == 0) {
255+ gen_loc.zoom=strdup(value);
256+ }
257+ if ( strcmp(key,"lat") == 0) {
258+ gen_loc.latitude=strdup(value);
259+ }
260+ if ( strcmp(key,"long") == 0) {
261+ gen_loc.longitude=strdup(value);
262+ }
263+ }
264+ // state 1 == location definition
265+ if ( state == 1 ) {
266+ if ( strcmp(key,"host_name") == 0) {
267+ loc->name=strdup(value);
b7e814c5 268+ }
6442e2ee
ER
269+ if ( strcmp(key,"notes") == 0) {
270+ loc->note = strdup(value);
271+ }
272+ if ( strcmp(key,"lat") == 0) {
273+ loc->latitude = strdup(value);
274+ }
275+ if ( strcmp(key,"long") == 0) {
276+ loc->longitude = strdup(value);
277+ }
278+ }
279+ }
280+ }
281+ fclose(fp);
282+
6442e2ee 283+
455492e8
ER
284+ printf("<script type='text/javascript'>\n");
285+ printf("gstatusmap = {\n");
286+ printf("lat:%s,\n", gen_loc.latitude);
287+ printf("lng:%s,\n", gen_loc.longitude);
288+ if (user_supplied_scaling==TRUE) {
289+ printf("scale: '%2.1f',\n", user_scaling_factor);
6442e2ee 290+ } else {
455492e8 291+ printf("scale: '%2.1f',\n", gen_loc.zoom);
6442e2ee
ER
292+ user_scaling_factor = atof(gen_loc.zoom);
293+ }
455492e8
ER
294+ printf("markers: [\n");
295+
6442e2ee
ER
296+ loc = loc_list;
297+ while (loc) {
298+ // check if allowed to show hostname first
299+ host* temp_host=find_host(loc->name);
300+ int in_layer_list=FALSE;
301+ in_layer_list=is_host_in_layer_list(temp_host);
302+
303+ if ( !is_authorized_for_host(temp_host,&current_authdata) && !is_host_in_layer_list(temp_host)) {
304+ loc = loc->next;
305+ continue;
306+ } else {
307+ if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE))
308+ {
309+ loc = loc->next;
310+ continue;
311+ }
312+ ptr = get_status_code(loc->name);
313+ strcpy(stateinfo,ptr);
314+ free(ptr);
315+
316+
455492e8 317+ printf("['%s','",loc->name);
6442e2ee
ER
318+ ptr = loc->note;
319+ while ((ch = *ptr++)) {
320+ if (ch == '\'') printf("\\'");
321+ else printf("%c", ch);
322+ }
455492e8 323+ printf("',%s,%s,'%s'],\n",loc->latitude,loc->longitude,stateinfo);
6442e2ee
ER
324+
325+ loc = loc->next;
326+ }
327+ }
455492e8
ER
328+
329+ printf("0], \n");
330+ printf("images_url: '%s'\n", url_images_path);
331+ printf("};\n");
332+ printf("</script>\n");
333+
334+ printf("<script src='http://maps.google.com/maps?file=api&amp;v=2&key=%s&amp;sensor=false' type='text/javascript'></script>\n",gen_loc.key);
335+ printf("<script src='%sgooglemap.js' type='text/javascript'></script>\n", url_images_path);
6442e2ee
ER
336+}
337
338 /* write JavaScript code an layer for popup window */
339 void write_popup_code(void){
This page took 0.212431 seconds and 4 git commands to generate.