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 struct show_graph_data_s
29 graph_instance_t *inst;
31 typedef struct show_graph_data_s show_graph_data_t;
33 static void show_breadcrump_field (const char *str, /* {{{ */
34 const char *field_name)
36 if ((str == NULL) || (str[0] == 0))
37 printf ("<em>none</em>");
38 else if (IS_ANY (str))
39 printf ("<em>any</em>");
40 else if (IS_ALL (str))
41 printf ("<em>all</em>");
44 char *str_html = html_escape (str);
46 if (field_name != NULL)
47 printf ("<a href=\"%s?action=list_graphs;q=%s:%s\">%s</a>",
48 script_name (), field_name, str_html, str_html);
50 printf ("<a href=\"%s?action=list_graphs;q=%s\">%s</a>",
51 script_name (), str_html, str_html);
55 } /* }}} void show_breadcrump_field */
57 static int show_breadcrump (show_graph_data_t *data) /* {{{ */
62 if (data->inst != NULL)
65 ident = inst_get_selector (data->inst);
70 ident = graph_get_selector (data->cfg);
73 printf ("<div class=\"breadcrump\">%s: "", prefix);
74 show_breadcrump_field (ident_get_host (ident), "host");
76 show_breadcrump_field (ident_get_plugin (ident), "plugin");
77 printf (" – ");
78 show_breadcrump_field (ident_get_plugin_instance (ident), "plugin_instance");
80 show_breadcrump_field (ident_get_type (ident), "type");
81 printf (" – ");
82 show_breadcrump_field (ident_get_type_instance (ident), "type_instance");
83 printf (""</div>\n");
86 } /* }}} int show_breadcrump */
88 static int show_time_selector (__attribute__((unused)) void *user_data) /* {{{ */
92 pl = param_create (/* query string = */ NULL);
93 param_set (pl, "begin", NULL);
94 param_set (pl, "end", NULL);
95 param_set (pl, "button", NULL);
97 printf ("<form action=\"%s\" method=\"get\">\n", script_name ());
99 param_print_hidden (pl);
101 printf (" <select name=\"begin\">\n"
102 " <option value=\"-3600\">Hour</option>\n"
103 " <option value=\"-86400\">Day</option>\n"
104 " <option value=\"-604800\">Week</option>\n"
105 " <option value=\"-2678400\">Month</option>\n"
106 " <option value=\"-31622400\">Year</option>\n"
108 " <input type=\"submit\" name=\"button\" value=\"Go\" />\n");
110 printf ("</form>\n");
115 } /* }}} int show_time_selector */
117 static int show_instance_list_cb (graph_instance_t *inst, /* {{{ */
120 show_graph_data_t *data = user_data;
124 memset (descr, 0, sizeof (descr));
125 inst_describe (data->cfg, inst, descr, sizeof (descr));
126 html_escape_buffer (descr, sizeof (descr));
128 if (inst == data->inst)
130 printf (" <li class=\"instance\"><strong>%s</strong></li>\n", descr);
134 memset (params, 0, sizeof (params));
135 inst_get_params (data->cfg, inst, params, sizeof (params));
136 html_escape_buffer (params, sizeof (params));
138 printf (" <li class=\"instance\">"
139 "<a href=\"%s?action=show_instance;%s\">%s</a></li>\n",
140 script_name (), params, descr);
143 } /* }}} int show_instance_list_cb */
145 static int show_instance_list (void *user_data) /* {{{ */
147 show_graph_data_t *data = user_data;
151 memset (title, 0, sizeof (title));
152 graph_get_title (data->cfg, title, sizeof (title));
153 html_escape_buffer (title, sizeof (title));
155 memset (params, 0, sizeof (params));
156 graph_get_params (data->cfg, params, sizeof (params));
157 html_escape_buffer (params, sizeof (params));
159 printf ("<ul class=\"graph_list\">\n"
160 " <li class=\"graph\"><a href=\"%s?action=show_instance;%s\">%s</a>\n"
161 " <ul class=\"instance_list\">\n",
162 script_name (), params, title);
164 graph_inst_foreach (data->cfg, show_instance_list_cb, user_data);
170 } /* }}} int show_instance_list */
172 static int show_instance_cb (graph_config_t *cfg, /* {{{ */
173 graph_instance_t *inst,
174 __attribute__((unused)) void *user_data)
180 memset (title, 0, sizeof (title));
181 graph_get_title (cfg, title, sizeof (title));
182 html_escape_buffer (title, sizeof (title));
184 memset (descr, 0, sizeof (descr));
185 inst_describe (cfg, inst, descr, sizeof (descr));
186 html_escape_buffer (descr, sizeof (descr));
188 memset (params, 0, sizeof (params));
189 inst_get_params (cfg, inst, params, sizeof (params));
190 html_escape_buffer (params, sizeof (params));
192 printf ("<h3>Instance "%s"</h3>\n", descr);
193 printf ("<div class=\"graph-img\"><img src=\"%s?action=graph;%s\" "
194 "title=\"%s / %s\" /></div>\n",
195 script_name (), params, title, descr);
198 } /* }}} int show_instance_cb */
200 static int show_instance (void *user_data) /* {{{ */
202 show_graph_data_t *data = user_data;
205 fprintf (stderr, "show_instance: Calling inst_get_all_selected()\n");
206 status = inst_get_all_selected (data->cfg,
207 /* callback = */ show_instance_cb, /* user data = */ NULL);
209 fprintf (stderr, "show_instance: inst_get_all_selected failed "
210 "with status %i\n", status);
213 } /* }}} int show_instance */
215 int action_show_instance (void) /* {{{ */
217 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
218 show_graph_data_t pg_data;
223 pg_data.cfg = gl_graph_get_selected ();
224 if (pg_data.cfg == NULL)
225 OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
227 memset (tmp, 0, sizeof (tmp));
228 graph_get_title (pg_data.cfg, tmp, sizeof (tmp));
229 snprintf (title, sizeof (title), "Graph \"%s\"", tmp);
230 title[sizeof (title) - 1] = 0;
232 pg_callbacks.top_right = html_print_search_box;
233 pg_callbacks.middle_center = show_instance;
234 pg_callbacks.middle_left = show_instance_list;
235 pg_callbacks.middle_right = show_time_selector;
237 html_print_page (title, &pg_callbacks, &pg_data);
240 } /* }}} int action_show_instance */
242 /* vim: set sw=2 sts=2 et fdm=marker : */