X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faction_show_instance.c;h=b67e8b0840900a72afae381df866366a209169ae;hb=e0b8e6b3289ee56fba4dbee099f8fd25d5028639;hp=0e1e43c9c79875bfe1699cab4c0dc07242dba7f0;hpb=ec060bd3831805d241bcd00d4d09b59ec8b10c26;p=collection4.git
diff --git a/src/action_show_instance.c b/src/action_show_instance.c
index 0e1e43c..b67e8b0 100644
--- a/src/action_show_instance.c
+++ b/src/action_show_instance.c
@@ -48,11 +48,15 @@
#define MAX_SHOW_GRAPHS 10
+#define SGD_FORMAT_JSON 0
+#define SGD_FORMAT_RRD 1
+
struct show_graph_data_s
{
graph_config_t *cfg;
graph_instance_t *inst;
int graph_count;
+ int format;
};
typedef struct show_graph_data_s show_graph_data_t;
@@ -132,8 +136,12 @@ static int show_time_selector (__attribute__((unused)) void *user_data) /* {{{ *
" \n"
" \n"
" \n"
- " \n"
- " \n");
+ "
\n");
+ printf (" "
+ "
\n"
+ " "
+ "\n
");
+ printf (" \n");
printf ("\n");
@@ -146,6 +154,7 @@ static int left_menu (void *user_data) /* {{{ */
{
show_graph_data_t *data = user_data;
char params[1024];
+ graph_instance_t *inst;
graph_ident_t *ident;
const char *host;
@@ -153,7 +162,8 @@ static int left_menu (void *user_data) /* {{{ */
graph_get_params (data->cfg, params, sizeof (params));
html_escape_buffer (params, sizeof (params));
- ident = inst_get_selector (data->inst);
+ inst = inst_get_selected (data->cfg);
+ ident = inst_get_selector (inst);
host = ident_get_host (ident);
if (IS_ANY (host))
host = NULL;
@@ -176,22 +186,102 @@ static int left_menu (void *user_data) /* {{{ */
}
printf ("\n");
+ host = NULL;
+ ident_destroy (ident);
+
return (0);
} /* }}} int left_menu */
-static int show_instance_cb (graph_config_t *cfg, /* {{{ */
+static int show_instance_json (graph_config_t *cfg, /* {{{ */
graph_instance_t *inst,
- void *user_data)
+ long begin, long end, int index)
+{
+ yajl_gen_config handler_config;
+ yajl_gen handler;
+ const unsigned char *json_buffer;
+ unsigned int json_buffer_length;
+
+ graph_ident_t *graph_selector;
+ graph_ident_t *inst_selector;
+
+ graph_selector = graph_get_selector (cfg);
+ if (graph_selector == NULL)
+ return (ENOMEM);
+
+ inst_selector = inst_get_selector (inst);
+ if (inst_selector == NULL)
+ {
+ ident_destroy (inst_selector);
+ return (ENOMEM);
+ }
+
+ memset (&handler_config, 0, sizeof (handler_config));
+ handler_config.beautify = 1;
+ handler_config.indentString = " ";
+
+ handler = yajl_gen_alloc2 (/* callback = */ NULL,
+ &handler_config,
+ /* alloc functions = */ NULL,
+ /* context = */ NULL);
+ if (handler == NULL)
+ {
+ ident_destroy (inst_selector);
+ ident_destroy (graph_selector);
+ return (-1);
+ }
+
+ yajl_gen_map_open (handler);
+
+ yajl_gen_string (handler,
+ (unsigned char *) "graph_selector",
+ (unsigned int) strlen ("graph_selector"));
+ ident_to_json (graph_selector, handler);
+ ident_destroy (graph_selector);
+
+ yajl_gen_string (handler,
+ (unsigned char *) "instance_selector",
+ (unsigned int) strlen ("instance_selector"));
+ ident_to_json (inst_selector, handler);
+ ident_destroy (inst_selector);
+
+ yajl_gen_string (handler,
+ (unsigned char *) "begin",
+ (unsigned int) strlen ("begin"));
+ yajl_gen_integer (handler, begin);
+
+ yajl_gen_string (handler,
+ (unsigned char *) "end",
+ (unsigned int) strlen ("end"));
+ yajl_gen_integer (handler, end);
+
+ yajl_gen_map_close (handler);
+
+ json_buffer = NULL;
+ json_buffer_length = 0;
+ yajl_gen_get_buf (handler, &json_buffer, &json_buffer_length);
+
+ if (json_buffer == NULL)
+ {
+ yajl_gen_free (handler);
+ return (EINVAL);
+ }
+
+ printf ("