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 (__attribute__((unused)) 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_ident (inst, buffer, sizeof (buffer));
55 printf ("<li>%s</li>\n", buffer);
58 } /* }}} int print_graph_inst_html */
60 static int print_graph_html (graph_config_t *cfg, /* {{{ */
61 __attribute__((unused)) void *user_data)
63 printf ("<li>%p\n<ul>\n", (void *) cfg);
64 gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL);
68 } /* }}} int print_graph_html */
70 static int list_graphs_json (void) /* {{{ */
74 printf ("Content-Type: application/json\n\n");
77 gl_foreach (print_graph_json, /* user_data = */ &first);
81 } /* }}} int list_graphs_json */
83 static int list_graphs_html (void) /* {{{ */
85 printf ("Content-Type: text/html\n\n");
88 gl_graph_get_all (print_graph_html, /* user_data = */ NULL);
92 } /* }}} int list_graphs_html */
94 int action_list_graphs (void) /* {{{ */
100 format = param ("format");
104 if (strcmp ("json", format) == 0)
105 return (list_graphs_json ());
107 return (list_graphs_html ());
108 } /* }}} int action_list_graphs */
110 /* vim: set sw=2 sts=2 et fdm=marker : */