summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3a5182f)
raw | patch | inline | side by side (parent: 3a5182f)
author | Florian Forster <octo@verplant.org> | |
Sat, 11 Sep 2010 07:33:41 +0000 (09:33 +0200) | ||
committer | Florian Forster <octo@verplant.org> | |
Sat, 11 Sep 2010 07:33:41 +0000 (09:33 +0200) |
share/collection.js | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/action_graph_data_json.c | [deleted file] | patch | blob | history |
src/action_graph_data_json.h | [deleted file] | patch | blob | history |
src/action_instance_data_json.c | [new file with mode: 0644] | patch | blob |
src/action_instance_data_json.h | [new file with mode: 0644] | patch | blob |
src/action_show_instance.c | patch | blob | history | |
src/main.c | patch | blob | history |
diff --git a/share/collection.js b/share/collection.js
index e352d51ec0457ae8e87286154f39775a0b345104..63bfd0857993bd098ce42ed82554f71161785e69 100644 (file)
--- a/share/collection.js
+++ b/share/collection.js
inst.raphael = Raphael ("c4-graph" + index);
params = instance_get_params (inst);
- params.action = "graph_data_json";
+ params.action = "instance_data_json";
params.begin = inst.begin;
params.end = inst.end;
diff --git a/src/Makefile.am b/src/Makefile.am
index 96bbae789529d0a10855ef06c7010a216f17b083..bd986999cb47e8a939dbcb719b7c0649799742b2 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collection_fcgi_SOURCES = main.c \
oconfig.c oconfig.h aux_types.h scanner.l parser.y \
action_graph.c action_graph.h \
- action_graph_data_json.c action_graph_data_json.h \
+ action_instance_data_json.c action_instance_data_json.h \
action_graph_def_json.c action_graph_def_json.h \
action_list_graphs.c action_list_graphs.h \
action_list_hosts.c action_list_hosts.h \
diff --git a/src/action_graph_data_json.c b/src/action_graph_data_json.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * collection4 - action_graph_data_json.c
- * Copyright (C) 2010 Florian octo Forster
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- *
- * Authors:
- * Florian octo Forster <ff at octo.it>
- **/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <assert.h>
-
-#include "action_graph_data_json.h"
-#include "common.h"
-#include "graph.h"
-#include "graph_instance.h"
-#include "graph_list.h"
-#include "utils_cgi.h"
-
-#include <fcgiapp.h>
-#include <fcgi_stdio.h>
-
-/* Expire data after one day. */
-#define EXPIRES_SECS 86400
-
-static void write_callback (__attribute__((unused)) void *ctx, /* {{{ */
- const char *str, unsigned int len)
-{
- fwrite ((void *) str, /* size = */ len, /* nmemb = */ 1, stdout);
-} /* }}} void write_callback */
-
-int action_graph_data_json (void) /* {{{ */
-{
- graph_config_t *cfg;
- graph_instance_t *inst;
-
- time_t tt_begin = 0;
- time_t tt_end = 0;
- time_t tt_now = 0;
-
- dp_time_t dp_begin = { 0, 0 };
- dp_time_t dp_end = { 0, 0 };
-
- yajl_gen_config handler_config;
- yajl_gen handler;
-
- time_t expires;
- char time_buffer[128];
- int status;
-
- cfg = gl_graph_get_selected ();
- if (cfg == NULL)
- return (ENOMEM);
-
- inst = inst_get_selected (cfg);
- if (inst == NULL)
- return (EINVAL);
-
- /* Get selected time(s) */
- tt_begin = tt_end = tt_now = 0;
- status = get_time_args (&tt_begin, &tt_end, &tt_now);
- if (status != 0)
- return (status);
-
- dp_begin.tv_sec = tt_begin;
- dp_begin.tv_nsec = 0;
- dp_end.tv_sec = tt_end;
- dp_end.tv_nsec = 0;
-
- memset (&handler_config, 0, sizeof (handler_config));
- handler_config.beautify = 0;
- handler_config.indentString = " ";
-
- handler = yajl_gen_alloc2 (write_callback,
- &handler_config,
- /* alloc functions = */ NULL,
- /* context = */ NULL);
- if (handler == NULL)
- return (-1);
-
- printf ("Content-Type: application/json\n");
-
- /* By default, permit caching until 1/1000th after the last data. If that
- * data is in the past, assume the entire data is in the past and allow
- * caching for one day. */
- expires = tt_end + ((tt_end - tt_begin) / 1000);
- if (expires < tt_now)
- expires = tt_now + 86400;
-
- status = time_to_rfc1123 (expires, time_buffer, sizeof (time_buffer));
- if (status == 0)
- printf ("Expires: %s\n"
- "Cache-Control: public\n",
- time_buffer);
- printf ("\n");
-
- status = inst_data_to_json (inst,
- dp_begin, dp_end, handler);
-
- yajl_gen_free (handler);
-
- return (status);
-} /* }}} int action_graph_data_json */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/action_graph_data_json.h b/src/action_graph_data_json.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * collection4 - action_graph_data_json.h
- * Copyright (C) 2010 Florian octo Forster
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- *
- * Authors:
- * Florian octo Forster <ff at octo.it>
- **/
-
-#ifndef ACTION_GRAPH_DATA_JSON_H
-#define ACTION_GRAPH_DATA_JSON_H 1
-
-int action_graph_data_json (void);
-
-#endif /* ACTION_GRAPH_DATA_JSON_H */
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/action_instance_data_json.c b/src/action_instance_data_json.c
--- /dev/null
@@ -0,0 +1,124 @@
+/**
+ * collection4 - action_instance_data_json.c
+ * Copyright (C) 2010 Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <ff at octo.it>
+ **/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "action_instance_data_json.h"
+#include "common.h"
+#include "graph.h"
+#include "graph_instance.h"
+#include "graph_list.h"
+#include "utils_cgi.h"
+
+#include <fcgiapp.h>
+#include <fcgi_stdio.h>
+
+/* Expire data after one day. */
+#define EXPIRES_SECS 86400
+
+static void write_callback (__attribute__((unused)) void *ctx, /* {{{ */
+ const char *str, unsigned int len)
+{
+ fwrite ((void *) str, /* size = */ len, /* nmemb = */ 1, stdout);
+} /* }}} void write_callback */
+
+int action_instance_data_json (void) /* {{{ */
+{
+ graph_config_t *cfg;
+ graph_instance_t *inst;
+
+ time_t tt_begin = 0;
+ time_t tt_end = 0;
+ time_t tt_now = 0;
+
+ dp_time_t dp_begin = { 0, 0 };
+ dp_time_t dp_end = { 0, 0 };
+
+ yajl_gen_config handler_config;
+ yajl_gen handler;
+
+ time_t expires;
+ char time_buffer[128];
+ int status;
+
+ cfg = gl_graph_get_selected ();
+ if (cfg == NULL)
+ return (ENOMEM);
+
+ inst = inst_get_selected (cfg);
+ if (inst == NULL)
+ return (EINVAL);
+
+ /* Get selected time(s) */
+ tt_begin = tt_end = tt_now = 0;
+ status = get_time_args (&tt_begin, &tt_end, &tt_now);
+ if (status != 0)
+ return (status);
+
+ dp_begin.tv_sec = tt_begin;
+ dp_begin.tv_nsec = 0;
+ dp_end.tv_sec = tt_end;
+ dp_end.tv_nsec = 0;
+
+ memset (&handler_config, 0, sizeof (handler_config));
+ handler_config.beautify = 0;
+ handler_config.indentString = " ";
+
+ handler = yajl_gen_alloc2 (write_callback,
+ &handler_config,
+ /* alloc functions = */ NULL,
+ /* context = */ NULL);
+ if (handler == NULL)
+ return (-1);
+
+ printf ("Content-Type: application/json\n");
+
+ /* By default, permit caching until 1/1000th after the last data. If that
+ * data is in the past, assume the entire data is in the past and allow
+ * caching for one day. */
+ expires = tt_end + ((tt_end - tt_begin) / 1000);
+ if (expires < tt_now)
+ expires = tt_now + 86400;
+
+ status = time_to_rfc1123 (expires, time_buffer, sizeof (time_buffer));
+ if (status == 0)
+ printf ("Expires: %s\n"
+ "Cache-Control: public\n",
+ time_buffer);
+ printf ("\n");
+
+ status = inst_data_to_json (inst,
+ dp_begin, dp_end, handler);
+
+ yajl_gen_free (handler);
+
+ return (status);
+} /* }}} int action_instance_data_json */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/action_instance_data_json.h b/src/action_instance_data_json.h
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * collection4 - action_instance_data_json.h
+ * Copyright (C) 2010 Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <ff at octo.it>
+ **/
+
+#ifndef ACTION_GRAPH_DATA_JSON_H
+#define ACTION_GRAPH_DATA_JSON_H 1
+
+int action_instance_data_json (void);
+
+#endif /* ACTION_GRAPH_DATA_JSON_H */
+/* vim: set sw=2 sts=2 et fdm=marker : */
index 15130adde95151b07a1ec6f76a1ef9b8a3fc2b0c..b67e8b0840900a72afae381df866366a209169ae 100644 (file)
script_name (), params, title, descr);
#if 0
- printf ("<div><a href=\"%s?action=graph_data_json;%s%s\">"
+ printf ("<div><a href=\"%s?action=instance_data_json;%s%s\">"
"Get graph data as JSON</a></div>\n",
script_name (), params, time_params);
#endif
diff --git a/src/main.c b/src/main.c
index a97a6152f0dee0f6d960ae461002fc4b7356f2e2..0722403fac4f885883d6a9c1765ab081a408037f 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include "utils_cgi.h"
#include "action_graph.h"
-#include "action_graph_data_json.h"
+#include "action_instance_data_json.h"
#include "action_graph_def_json.h"
#include "action_list_graphs.h"
#include "action_list_hosts.h"
static const action_t actions[] =
{
{ "graph", action_graph },
- { "graph_data_json", action_graph_data_json },
+ { "instance_data_json", action_instance_data_json },
{ "graph_def_json", action_graph_def_json },
{ "list_graphs", action_list_graphs },
{ "list_hosts", action_list_hosts },