9 #include "action_show_instance.h"
12 #include "graph_ident.h"
13 #include "graph_instance.h"
14 #include "graph_list.h"
15 #include "utils_cgi.h"
18 #include <fcgi_stdio.h>
20 #define OUTPUT_ERROR(...) do { \
21 printf ("Content-Type: text/plain\n\n"); \
22 printf (__VA_ARGS__); \
26 #define MAX_SHOW_GRAPHS 10
28 struct show_graph_data_s
31 graph_instance_t *inst;
34 typedef struct show_graph_data_s show_graph_data_t;
36 static void show_breadcrump_field (const char *str, /* {{{ */
37 const char *field_name)
39 if ((str == NULL) || (str[0] == 0))
40 printf ("<em>none</em>");
41 else if (IS_ANY (str))
42 printf ("<em>any</em>");
43 else if (IS_ALL (str))
44 printf ("<em>all</em>");
47 char *str_html = html_escape (str);
49 if (field_name != NULL)
50 printf ("<a href=\"%s?action=list_graphs;q=%s:%s\">%s</a>",
51 script_name (), field_name, str_html, str_html);
53 printf ("<a href=\"%s?action=list_graphs;q=%s\">%s</a>",
54 script_name (), str_html, str_html);
58 } /* }}} void show_breadcrump_field */
60 static int show_breadcrump (graph_config_t *cfg, /* {{{ */
61 graph_instance_t *inst)
69 ident = inst_get_selector (inst);
74 ident = graph_get_selector (cfg);
77 printf ("<div class=\"breadcrump\">%s: "", prefix);
78 show_breadcrump_field (ident_get_host (ident), "host");
80 show_breadcrump_field (ident_get_plugin (ident), "plugin");
81 printf (" – ");
82 show_breadcrump_field (ident_get_plugin_instance (ident), "plugin_instance");
84 show_breadcrump_field (ident_get_type (ident), "type");
85 printf (" – ");
86 show_breadcrump_field (ident_get_type_instance (ident), "type_instance");
87 printf (""</div>\n");
89 ident_destroy (ident);
91 } /* }}} int show_breadcrump */
93 static int show_time_selector (__attribute__((unused)) void *user_data) /* {{{ */
97 pl = param_create (/* query string = */ NULL);
98 param_set (pl, "begin", NULL);
99 param_set (pl, "end", NULL);
100 param_set (pl, "button", NULL);
102 printf ("<form action=\"%s\" method=\"get\">\n", script_name ());
104 param_print_hidden (pl);
106 printf (" <select name=\"begin\">\n"
107 " <option value=\"-3600\">Hour</option>\n"
108 " <option value=\"-86400\">Day</option>\n"
109 " <option value=\"-604800\">Week</option>\n"
110 " <option value=\"-2678400\">Month</option>\n"
111 " <option value=\"-31622400\">Year</option>\n"
113 " <input type=\"submit\" name=\"button\" value=\"Go\" />\n");
115 printf ("</form>\n");
120 } /* }}} int show_time_selector */
122 static int show_instance_list_cb (graph_instance_t *inst, /* {{{ */
125 show_graph_data_t *data = user_data;
129 memset (descr, 0, sizeof (descr));
130 inst_describe (data->cfg, inst, descr, sizeof (descr));
131 html_escape_buffer (descr, sizeof (descr));
133 if (inst == data->inst)
135 printf (" <li class=\"instance\"><strong>%s</strong></li>\n", descr);
139 memset (params, 0, sizeof (params));
140 inst_get_params (data->cfg, inst, params, sizeof (params));
141 html_escape_buffer (params, sizeof (params));
143 printf (" <li class=\"instance\">"
144 "<a href=\"%s?action=show_instance;%s\">%s</a></li>\n",
145 script_name (), params, descr);
148 } /* }}} int show_instance_list_cb */
150 static int show_instance_list (void *user_data) /* {{{ */
152 show_graph_data_t *data = user_data;
156 memset (title, 0, sizeof (title));
157 graph_get_title (data->cfg, title, sizeof (title));
158 html_escape_buffer (title, sizeof (title));
160 memset (params, 0, sizeof (params));
161 graph_get_params (data->cfg, params, sizeof (params));
162 html_escape_buffer (params, sizeof (params));
164 printf ("<ul class=\"graph_list\">\n"
165 " <li class=\"graph\"><a href=\"%s?action=show_instance;%s\">%s</a>\n"
166 " <ul class=\"instance_list\">\n",
167 script_name (), params, title);
169 graph_inst_foreach (data->cfg, show_instance_list_cb, user_data);
175 } /* }}} int show_instance_list */
177 static int show_instance_cb (graph_config_t *cfg, /* {{{ */
178 graph_instance_t *inst,
181 show_graph_data_t *data = user_data;
186 memset (title, 0, sizeof (title));
187 graph_get_title (cfg, title, sizeof (title));
188 html_escape_buffer (title, sizeof (title));
190 memset (descr, 0, sizeof (descr));
191 inst_describe (cfg, inst, descr, sizeof (descr));
192 html_escape_buffer (descr, sizeof (descr));
194 memset (params, 0, sizeof (params));
195 inst_get_params (cfg, inst, params, sizeof (params));
196 html_escape_buffer (params, sizeof (params));
198 printf ("<h3>Instance "%s"</h3>\n", descr);
200 show_breadcrump (cfg, inst);
202 if (data->graph_count < MAX_SHOW_GRAPHS)
203 printf ("<div class=\"graph-img\"><img src=\"%s?action=graph;%s\" "
204 "title=\"%s / %s\" /></div>\n",
205 script_name (), params, title, descr);
207 printf ("<a href=\"%s?action=show_instance;%s\">Show graph "
208 ""%s / %s"</a>\n",
209 script_name (), params, title, descr);
214 } /* }}} int show_instance_cb */
216 static int show_instance (void *user_data) /* {{{ */
218 show_graph_data_t *data = user_data;
221 fprintf (stderr, "show_instance: Calling inst_get_all_selected()\n");
222 status = inst_get_all_selected (data->cfg,
223 /* callback = */ show_instance_cb, /* user data = */ data);
225 fprintf (stderr, "show_instance: inst_get_all_selected failed "
226 "with status %i\n", status);
229 } /* }}} int show_instance */
231 int action_show_instance (void) /* {{{ */
233 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
234 show_graph_data_t pg_data;
239 memset (&pg_data, 0, sizeof (pg_data));
240 pg_data.cfg = gl_graph_get_selected ();
241 if (pg_data.cfg == NULL)
242 OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
244 memset (tmp, 0, sizeof (tmp));
245 graph_get_title (pg_data.cfg, tmp, sizeof (tmp));
246 snprintf (title, sizeof (title), "Graph \"%s\"", tmp);
247 title[sizeof (title) - 1] = 0;
249 pg_callbacks.top_right = html_print_search_box;
250 pg_callbacks.middle_center = show_instance;
251 pg_callbacks.middle_left = show_instance_list;
252 pg_callbacks.middle_right = show_time_selector;
254 html_print_page (title, &pg_callbacks, &pg_data);
257 } /* }}} int action_show_instance */
259 /* vim: set sw=2 sts=2 et fdm=marker : */