7 #include <fcgi_stdio.h>
9 #include "action_list_graphs.h"
10 #include "graph_list.h"
11 #include "utils_params.h"
13 static int print_graph_json (const graph_list_t *gl, void *user_data) /* {{{ */
17 if ((gl == NULL) || (user_data == NULL))
20 first = (_Bool *) user_data;
27 printf ("\"host\":\"%s\"", gl->host);
29 printf (",\"plugin\":\"%s\"", gl->plugin);
30 if (gl->plugin_instance != NULL)
31 printf (",\"plugin_instance\":\"%s\"", gl->plugin_instance);
33 printf (",\"plugin_instance\":null");
35 printf (",\"type\":\"%s\"", gl->type);
36 if (gl->type_instance != NULL)
37 printf (",\"type_instance\":\"%s\"", gl->type_instance);
39 printf (",\"type_instance\":null");
44 } /* }}} int print_graph_json */
46 static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */
47 graph_instance_t *inst,
48 __attribute__((unused)) void *user_data)
52 memset (buffer, 0, sizeof (buffer));
53 gl_instance_get_params (cfg, inst, buffer, sizeof (buffer));
55 printf ("<li><a href=\"test.fcgi?action=graph;%s\">%s</a></li>\n", buffer, buffer);
58 } /* }}} int print_graph_inst_html */
60 static int print_graph_html (graph_config_t *cfg, /* {{{ */
61 __attribute__((unused)) void *user_data)
65 memset (buffer, 0, sizeof (buffer));
66 gl_graph_get_title (cfg, buffer, sizeof (buffer));
68 printf ("<li>%s\n<ul>\n", buffer);
69 gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL);
73 } /* }}} int print_graph_html */
75 static int list_graphs_json (void) /* {{{ */
79 printf ("Content-Type: application/json\n\n");
82 gl_foreach (print_graph_json, /* user_data = */ &first);
86 } /* }}} int list_graphs_json */
88 static int list_graphs_html (void) /* {{{ */
90 printf ("Content-Type: text/html\n\n");
93 gl_graph_get_all (print_graph_html, /* user_data = */ NULL);
97 } /* }}} int list_graphs_html */
99 int action_list_graphs (void) /* {{{ */
105 format = param ("format");
109 if (strcmp ("json", format) == 0)
110 return (list_graphs_json ());
112 return (list_graphs_html ());
113 } /* }}} int action_list_graphs */
115 /* vim: set sw=2 sts=2 et fdm=marker : */