9 #include "action_show_graph.h"
11 #include "graph_ident.h"
12 #include "graph_list.h"
13 #include "utils_cgi.h"
16 #include <fcgi_stdio.h>
18 #define OUTPUT_ERROR(...) do { \
19 printf ("Content-Type: text/plain\n\n"); \
20 printf (__VA_ARGS__); \
24 struct show_graph_data_s
27 graph_instance_t *inst;
29 typedef struct show_graph_data_s show_graph_data_t;
31 static void show_breadcrump_field (const char *str, /* {{{ */
32 const char *field_name)
34 if ((str == NULL) || (str[0] == 0))
35 printf ("<em>none</em>");
36 else if (IS_ANY (str))
37 printf ("<em>any</em>");
38 else if (IS_ALL (str))
39 printf ("<em>all</em>");
42 char *str_html = html_escape (str);
44 if (field_name != NULL)
45 printf ("<a href=\"%s?action=list_graphs;q=%s:%s\">%s</a>",
46 script_name (), field_name, str_html, str_html);
48 printf ("<a href=\"%s?action=list_graphs;q=%s\">%s</a>",
49 script_name (), str_html, str_html);
53 } /* }}} void show_breadcrump_field */
55 static int show_breadcrump (show_graph_data_t *data) /* {{{ */
60 if (data->inst != NULL)
63 ident = inst_get_selector (data->inst);
68 ident = graph_get_selector (data->cfg);
71 printf ("<div class=\"breadcrump\">%s: "", prefix);
72 show_breadcrump_field (ident_get_host (ident), "host");
74 show_breadcrump_field (ident_get_plugin (ident), "plugin");
75 printf (" – ");
76 show_breadcrump_field (ident_get_plugin_instance (ident), NULL);
78 show_breadcrump_field (ident_get_type (ident), "type");
79 printf (" – ");
80 show_breadcrump_field (ident_get_type_instance (ident), NULL);
81 printf (""</div>\n");
84 } /* }}} int show_breadcrump */
86 static int show_instance_list_cb (graph_instance_t *inst, /* {{{ */
89 show_graph_data_t *data = user_data;
93 memset (descr, 0, sizeof (descr));
94 inst_describe (data->cfg, inst, descr, sizeof (descr));
95 html_escape_buffer (descr, sizeof (descr));
97 if (inst == data->inst)
99 printf (" <li class=\"instance\"><strong>%s</strong></li>\n", descr);
103 memset (params, 0, sizeof (params));
104 inst_get_params (data->cfg, inst, params, sizeof (params));
105 html_escape_buffer (params, sizeof (params));
107 printf (" <li class=\"instance\">"
108 "<a href=\"%s?action=show_graph;%s\">%s</a></li>\n",
109 script_name (), params, descr);
112 } /* }}} int show_instance_list_cb */
114 static int show_instance_list (void *user_data) /* {{{ */
116 show_graph_data_t *data = user_data;
120 memset (title, 0, sizeof (title));
121 graph_get_title (data->cfg, title, sizeof (title));
122 html_escape_buffer (title, sizeof (title));
124 memset (params, 0, sizeof (params));
125 graph_get_params (data->cfg, params, sizeof (params));
126 html_escape_buffer (params, sizeof (params));
128 printf ("<ul class=\"graph_list\">\n"
129 " <li class=\"graph\"><a href=\"%s?action=show_graph;%s\">%s</a>\n"
130 " <ul class=\"instance_list\">\n",
131 script_name (), params, title);
133 graph_inst_foreach (data->cfg, show_instance_list_cb, user_data);
139 } /* }}} int show_instance_list */
141 static int show_instance (void *user_data) /* {{{ */
143 show_graph_data_t *data = user_data;
148 show_breadcrump (data);
150 memset (title, 0, sizeof (title));
151 graph_get_title (data->cfg, title, sizeof (title));
152 html_escape_buffer (title, sizeof (title));
154 memset (descr, 0, sizeof (descr));
155 inst_describe (data->cfg, data->inst, descr, sizeof (descr));
156 html_escape_buffer (descr, sizeof (descr));
158 memset (params, 0, sizeof (params));
159 inst_get_params (data->cfg, data->inst, params, sizeof (params));
160 html_escape_buffer (params, sizeof (params));
162 printf ("<div class=\"graph-img\"><img src=\"%s?action=graph;%s\" "
163 "title=\"%s / %s\" /></div>\n",
164 script_name (), params, title, descr);
167 } /* }}} int show_instance */
169 static int show_graph (void *user_data)
171 show_graph_data_t *data = user_data;
173 show_breadcrump (data);
174 return (show_instance_list (user_data));
175 } /* }}} int show_graph */
177 int action_show_graph (void) /* {{{ */
179 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
180 show_graph_data_t pg_data;
184 pg_data.cfg = gl_graph_get_selected ();
185 if (pg_data.cfg == NULL)
186 OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
188 memset (title, 0, sizeof (title));
189 graph_get_title (pg_data.cfg, title, sizeof (title));
191 pg_data.inst = inst_get_selected (pg_data.cfg);
192 if (pg_data.inst != NULL)
195 char html_title[128];
197 memset (descr, 0, sizeof (descr));
198 inst_describe (pg_data.cfg, pg_data.inst, descr, sizeof (descr));
200 snprintf (html_title, sizeof (html_title), "Graph \"%s / %s\"",
202 html_title[sizeof (html_title) - 1] = 0;
204 pg_callbacks.top_right = html_print_search_box;
205 pg_callbacks.middle_center = show_instance;
206 pg_callbacks.middle_left = show_instance_list;
208 html_print_page (html_title, &pg_callbacks, &pg_data);
210 else /* if (pg_data.inst == NULL) */
212 pg_callbacks.top_right = html_print_search_box;
213 pg_callbacks.middle_center = show_graph;
215 html_print_page (title, &pg_callbacks, &pg_data);
219 } /* }}} int action_graph */
221 /* vim: set sw=2 sts=2 et fdm=marker : */