return (0);
} /* }}} int print_graph_json */
-static int print_graph_html (const graph_list_t *gl,
- void __attribute__((unused)) *user_data)
+static int print_graph_inst_html (__attribute__((unused)) graph_config_t *cfg, /* {{{ */
+ graph_instance_t *inst,
+ __attribute__((unused)) void *user_data)
{
- if (gl == NULL)
- return (EINVAL);
+ char buffer[1024];
- printf ("<li>");
+ memset (buffer, 0, sizeof (buffer));
+ gl_instance_get_ident (inst, buffer, sizeof (buffer));
- printf ("<a href=\"%s?action=graph;", getenv ("SCRIPT_NAME"));
- printf ("host=%s;plugin=%s;", gl->host, gl->plugin);
- if (gl->plugin_instance != NULL)
- printf ("plugin_instance=%s;", gl->plugin_instance);
- printf ("type=%s;", gl->type);
- if (gl->type_instance != NULL)
- printf ("type_instance=%s;", gl->type_instance);
- printf ("\">");
+ printf ("<li>%s</li>\n", buffer);
- printf ("%s/%s", gl->host, gl->plugin);
- if (gl->plugin_instance != NULL)
- printf ("-%s", gl->plugin_instance);
- printf ("/%s", gl->type);
- if (gl->type_instance != NULL)
- printf ("-%s", gl->type_instance);
- printf ("</a></li>\n");
+ return (0);
+} /* }}} int print_graph_inst_html */
+
+static int print_graph_html (graph_config_t *cfg, /* {{{ */
+ __attribute__((unused)) void *user_data)
+{
+ printf ("<li>%p\n<ul>\n", (void *) cfg);
+ gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL);
+ printf ("</ul>\n");
return (0);
-}
+} /* }}} int print_graph_html */
static int list_graphs_json (void) /* {{{ */
{
printf ("Content-Type: text/html\n\n");
printf ("<ul>\n");
- gl_foreach (print_graph_html, /* user_data = */ NULL);
+ gl_graph_get_all (print_graph_html, /* user_data = */ NULL);
printf ("</ul>\n");
return (0);
char *type_instance;
}; /* }}} struct graph_ident_s */
-struct graph_instance_s;
-typedef struct graph_instance_s graph_instance_t;
struct graph_instance_s /* {{{ */
{
graph_ident_t select;
graph_instance_t *next;
}; /* }}} struct graph_instance_s */
-struct graph_config_s;
-typedef struct graph_config_s graph_config_t;
struct graph_config_s /* {{{ */
{
graph_ident_t select;
/*
* Private functions
*/
+/* FIXME: These "print_*" functions are used for debugging. They should be
+ * removed at some point. */
static int print_files (const graph_instance_t *inst) /* {{{ */
{
size_t i;
return (0);
} /* }}} int print_graphs */
-
/* "Safe" version of strcmp(3): Either or both pointers may be NULL. */
static int strcmp_s (const char *s1, const char *s2) /* {{{ */
{
return (0);
} /* }}} int FIXME_graph_create_from_file */
+/* FIXME: Actually read the config file here. */
static int read_graph_config (void) /* {{{ */
{
if (graph_config_head != NULL)
/*
* Global functions
*/
+int gl_instance_get_ident (graph_instance_t *inst, /* {{{ */
+ char *buffer, size_t buffer_size)
+{
+ if ((inst == NULL) || (buffer == NULL) || (buffer_size < 1))
+ return (EINVAL);
+
+ snprintf (buffer, buffer_size, "%s/%s-%s/%s-%s",
+ inst->select.host,
+ inst->select.plugin, inst->select.plugin_instance,
+ inst->select.type, inst->select.type_instance);
+ buffer[buffer_size - 1] = 0;
+
+ return (0);
+} /* }}} int gl_instance_get_ident */
+
+int gl_graph_get_all (gl_cfg_callback callback, /* {{{ */
+ void *user_data)
+{
+ graph_config_t *cfg;
+
+ if (callback == NULL)
+ return (EINVAL);
+
+ for (cfg = graph_config_head; cfg != NULL; cfg = cfg->next)
+ {
+ int status;
+
+ status = (*callback) (cfg, user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int gl_graph_get_all */
+
+int gl_graph_instance_get_all (graph_config_t *cfg,
+ gl_inst_callback callback, void *user_data)
+{
+ graph_instance_t *inst;
+
+ if ((cfg == NULL) || (callback == NULL))
+ return (EINVAL);
+
+ for (inst = cfg->instances; inst != NULL; inst = inst->next)
+ {
+ int status;
+
+ status = (*callback) (cfg, inst, user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int gl_graph_instance_get_all */
+
+int gl_instance_get_all (gl_inst_callback callback, /* {{{ */
+ void *user_data)
+{
+ graph_config_t *cfg;
+
+ for (cfg = graph_config_head; cfg != NULL; cfg = cfg->next)
+ {
+ graph_instance_t *inst;
+
+ for (inst = cfg->instances; inst != NULL; inst = inst->next)
+ {
+ int status;
+
+ status = (*callback) (cfg, inst, user_data);
+ if (status != 0)
+ return (status);
+ }
+ }
+
+ return (0);
+} /* }}} int gl_instance_get_all */
+
int gl_update (void) /* {{{ */
{
time_t now;
graph_ident_t gl;
int status;
+ /*
printf ("Content-Type: text/plain\n\n");
+ */
read_graph_config ();
status = foreach_host (callback_host, &gl);
- print_graphs ();
+ /* print_graphs (); */
if (graph_list_length > 1)
qsort (graph_list, graph_list_length, sizeof (*graph_list), gl_compare);
struct graph_ident_s;
typedef struct graph_ident_s graph_ident_t;
+struct graph_instance_s;
+typedef struct graph_instance_s graph_instance_t;
+
+struct graph_config_s;
+typedef struct graph_config_s graph_config_t;
+
+/*
+ * Callback types
+ */
+typedef int (*gl_cfg_callback) (graph_config_t *cfg,
+ void *user_data);
+
+typedef int (*gl_inst_callback) (graph_config_t *cfg,
+ graph_instance_t *inst, void *user_data);
+
+/*
+ * Functions
+ */
+int gl_graph_get_all (gl_cfg_callback callback,
+ void *user_data);
+
+int gl_graph_instance_get_all (graph_config_t *cfg,
+ gl_inst_callback callback, void *user_data);
+
+int gl_instance_get_all (gl_inst_callback callback,
+ void *user_data);
+
+int gl_instance_get_ident (graph_instance_t *inst,
+ char *buffer, size_t buffer_size);
+
+
+
+
struct graph_list_s
{
char *host;
};
typedef struct graph_list_s graph_list_t;
-typedef int (*gl_callback) (const graph_list_t *, void *);
+typedef int (*gl_callback) (
+ const graph_list_t *, void *user_data);
int gl_update (void);
int gl_foreach (gl_callback callback, void *user_data);