X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=action_list_graphs.c;h=08d0eb49acac11af0bfb543bd037fb5ba593a9c4;hb=de9239ac3e16e12503eae5ddbfcdaae27f262081;hp=c239222051679003587bbcf769d407d9b2abd4df;hpb=8f210aa3a93bafab43eba645c9bc2babab999b93;p=collection4.git diff --git a/action_list_graphs.c b/action_list_graphs.c index c239222..08d0eb4 100644 --- a/action_list_graphs.c +++ b/action_list_graphs.c @@ -3,94 +3,119 @@ #include #include -#include -#include - #include "action_list_graphs.h" +#include "graph.h" +#include "graph_ident.h" #include "graph_list.h" #include "utils_params.h" -static int print_graph_json (const graph_list_t *gl, void *user_data) /* {{{ */ +#include +#include + +static int print_graph_inst_json (__attribute__((unused)) graph_config_t *cfg, /* {{{ */ + graph_instance_t *inst, + void *user_data) { _Bool *first; + graph_ident_t *ident; + char *json; - if ((gl == NULL) || (user_data == NULL)) - return (EINVAL); + first = user_data; - first = (_Bool *) user_data; - if (!*first) - printf (",\n"); - *first = 0; + ident = inst_get_selector (inst); + if (ident == NULL) + return (-1); - printf (" {"); - - printf ("\"host\":\"%s\"", gl->host); - - printf (",\"plugin\":\"%s\"", gl->plugin); - if (gl->plugin_instance != NULL) - printf (",\"plugin_instance\":\"%s\"", gl->plugin_instance); - else - printf (",\"plugin_instance\":null"); + json = ident_to_json (ident); + if (json == NULL) + { + ident_destroy (ident); + return (ENOMEM); + } - printf (",\"type\":\"%s\"", gl->type); - if (gl->type_instance != NULL) - printf (",\"type_instance\":\"%s\"", gl->type_instance); + if (*first) + printf ("%s", json); else - printf (",\"type_instance\":null"); + printf (",\n%s", json); - printf ("}"); + *first = 0; + ident_destroy (ident); return (0); +} /* }}} int print_graph_inst_json */ + +static int print_graph_json (graph_config_t *cfg, /* {{{ */ + void *user_data) +{ + return (gl_graph_instance_get_all (cfg, print_graph_inst_json, user_data)); } /* }}} int print_graph_json */ -static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */ - graph_instance_t *inst, - __attribute__((unused)) void *user_data) +static int list_graphs_json (void) /* {{{ */ { - char buffer[1024]; + _Bool first = 1; - memset (buffer, 0, sizeof (buffer)); - gl_instance_get_params (cfg, inst, buffer, sizeof (buffer)); + printf ("Content-Type: application/json\n\n"); - printf ("
  • %s
  • \n", buffer, buffer); + printf ("[\n"); + gl_graph_get_all (print_graph_json, /* user_data = */ &first); + printf ("\n]"); return (0); -} /* }}} int print_graph_inst_html */ +} /* }}} int list_graphs_json */ -static int print_graph_html (graph_config_t *cfg, /* {{{ */ - __attribute__((unused)) void *user_data) +struct callback_data_s { - char buffer[1024]; + graph_config_t *cfg; +}; +typedef struct callback_data_s callback_data_t; - memset (buffer, 0, sizeof (buffer)); - gl_graph_get_title (cfg, buffer, sizeof (buffer)); +static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */ + graph_instance_t *inst, + void *user_data) +{ + callback_data_t *data = user_data; + char params[1024]; + char desc[1024]; - printf ("
  • %s\n
      \n", buffer); - gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL); - printf ("
    \n"); + if (data->cfg != cfg) + { + if (data->cfg != NULL) + printf ("
  • \n"); - return (0); -} /* }}} int print_graph_html */ + memset (desc, 0, sizeof (desc)); + graph_get_title (cfg, desc, sizeof (desc)); -static int list_graphs_json (void) /* {{{ */ -{ - _Bool first = 1; + printf ("
  • %s\n
      \n", desc); - printf ("Content-Type: application/json\n\n"); + data->cfg = cfg; + } - printf ("[\n"); - gl_foreach (print_graph_json, /* user_data = */ &first); - printf ("\n]"); + memset (params, 0, sizeof (params)); + inst_get_params (cfg, inst, params, sizeof (params)); + + memset (desc, 0, sizeof (desc)); + inst_describe (cfg, inst, desc, sizeof (desc)); + + printf ("
    • %s
    • \n", + params, desc); return (0); -} /* }}} int list_graphs_json */ +} /* }}} int print_graph_inst_html */ -static int list_graphs_html (void) /* {{{ */ +static int list_graphs_html (const char *term) /* {{{ */ { + callback_data_t data = { NULL }; printf ("Content-Type: text/html\n\n"); printf ("
        \n"); - gl_graph_get_all (print_graph_html, /* user_data = */ NULL); + if (term == NULL) + gl_instance_get_all (print_graph_inst_html, /* user_data = */ &data); + else + gl_search (term, print_graph_inst_html, /* user_data = */ &data); + + if (data.cfg != NULL) + printf ("
      \n"); + printf ("
    \n"); return (0); @@ -109,7 +134,7 @@ int action_list_graphs (void) /* {{{ */ if (strcmp ("json", format) == 0) return (list_graphs_json ()); else - return (list_graphs_html ()); + return (list_graphs_html (param ("search"))); } /* }}} int action_list_graphs */ /* vim: set sw=2 sts=2 et fdm=marker : */