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_html (const graph_list_t *gl,
47 void __attribute__((unused)) *user_data)
54 printf ("<a href=\"%s?action=graph;", getenv ("SCRIPT_NAME"));
55 printf ("host=%s;plugin=%s;", gl->host, gl->plugin);
56 if (gl->plugin_instance != NULL)
57 printf ("plugin_instance=%s;", gl->plugin_instance);
58 printf ("type=%s;", gl->type);
59 if (gl->type_instance != NULL)
60 printf ("type_instance=%s;", gl->type_instance);
63 printf ("%s/%s", gl->host, gl->plugin);
64 if (gl->plugin_instance != NULL)
65 printf ("-%s", gl->plugin_instance);
66 printf ("/%s", gl->type);
67 if (gl->type_instance != NULL)
68 printf ("-%s", gl->type_instance);
69 printf ("</a></li>\n");
74 static int list_graphs_json (void) /* {{{ */
78 printf ("Content-Type: application/json\n\n");
81 gl_foreach (print_graph_json, /* user_data = */ &first);
85 } /* }}} int list_graphs_json */
87 static int list_graphs_html (void) /* {{{ */
89 printf ("Content-Type: text/html\n\n");
92 gl_foreach (print_graph_html, /* user_data = */ NULL);
96 } /* }}} int list_graphs_html */
98 int action_list_graphs (void) /* {{{ */
104 format = param ("format");
108 if (strcmp ("json", format) == 0)
109 return (list_graphs_json ());
111 return (list_graphs_html ());
112 } /* }}} int action_list_graphs */
114 /* vim: set sw=2 sts=2 et fdm=marker : */