summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4bd1536)
raw | patch | inline | side by side (parent: 4bd1536)
author | Florian Forster <ff@octo.it> | |
Wed, 9 Jun 2010 17:03:08 +0000 (19:03 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 9 Jun 2010 17:03:08 +0000 (19:03 +0200) |
graph_list.c | patch | blob | history | |
graph_list.h | patch | blob | history |
diff --git a/graph_list.c b/graph_list.c
index 240f2e1b8a62f64d4f3cc1ce56bb1257634f7b0e..389a03b2a3e86530f2c1e97eb0b75797e4d5698f 100644 (file)
--- a/graph_list.c
+++ b/graph_list.c
#include "graph_list.h"
#include "common.h"
+#include "utils_params.h"
/*
* Defines
return (status);
} /* }}} int callback_host */
+static const char *get_part_from_param (const char *prim_key, /* {{{ */
+ const char *sec_key)
+{
+ const char *val;
+
+ val = param (prim_key);
+ if (val != NULL)
+ return (val);
+
+ return (param (sec_key));
+} /* }}} const char *get_part_from_param */
+
/*
* Global functions
*/
-int gl_instance_get_ident (graph_instance_t *inst, /* {{{ */
+int gl_instance_get_params (graph_config_t *cfg, 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;
+ buffer[0] = 0;
+
+#define COPY_FIELD(field) do { \
+ if (strcmp (cfg->select.field, inst->select.field) == 0) \
+ { \
+ strlcat (buffer, #field, buffer_size); \
+ strlcat (buffer, "=", buffer_size); \
+ strlcat (buffer, cfg->select.field, buffer_size); \
+ } \
+ else \
+ { \
+ strlcat (buffer, "graph_", buffer_size); \
+ strlcat (buffer, #field, buffer_size); \
+ strlcat (buffer, "=", buffer_size); \
+ strlcat (buffer, cfg->select.field, buffer_size); \
+ strlcat (buffer, ";", buffer_size); \
+ strlcat (buffer, "inst_", buffer_size); \
+ strlcat (buffer, #field, buffer_size); \
+ strlcat (buffer, "=", buffer_size); \
+ strlcat (buffer, inst->select.field, buffer_size); \
+ } \
+} while (0)
+
+ COPY_FIELD(host);
+ strlcat (buffer, ";", buffer_size);
+ COPY_FIELD(plugin);
+ strlcat (buffer, ";", buffer_size);
+ COPY_FIELD(plugin_instance);
+ strlcat (buffer, ";", buffer_size);
+ COPY_FIELD(type);
+ strlcat (buffer, ";", buffer_size);
+ COPY_FIELD(type_instance);
+
+#undef COPY_FIELD
return (0);
-} /* }}} int gl_instance_get_ident */
+} /* }}} int gl_instance_get_params */
+
+graph_instance_t *inst_get_selected (graph_config_t *cfg) /* {{{ */
+{
+ const char *host = get_part_from_param ("inst_host", "host");
+ const char *plugin = get_part_from_param ("inst_plugin", "plugin");
+ const char *plugin_instance = get_part_from_param ("inst_plugin_instance", "plugin_instance");
+ const char *type = get_part_from_param ("inst_type", "type");
+ const char *type_instance = get_part_from_param ("inst_type_instance", "type_instance");
+ graph_instance_t *inst;
+
+ if (cfg == NULL)
+ cfg = graph_get_selected ();
+
+ if (cfg == NULL)
+ return (NULL);
+
+ if ((host == NULL)
+ || (plugin == NULL) || (plugin_instance == NULL)
+ || (type == NULL) || (type_instance == NULL))
+ return (NULL);
+
+ for (inst = cfg->instances; inst != NULL; inst = inst->next)
+ {
+ if ((strcmp (inst->select.host, host) != 0)
+ || (strcmp (inst->select.plugin, plugin) != 0)
+ || (strcmp (inst->select.plugin_instance, plugin_instance) != 0)
+ || (strcmp (inst->select.type, type) != 0)
+ || (strcmp (inst->select.type_instance, type_instance) != 0))
+ continue;
+
+ return (inst);
+ }
+
+ return (NULL);
+} /* }}} graph_instance_t *inst_get_selected */
int gl_graph_get_all (gl_cfg_callback callback, /* {{{ */
void *user_data)
return (0);
} /* }}} int gl_graph_get_all */
+graph_config_t *graph_get_selected (void) /* {{{ */
+{
+ const char *host = get_part_from_param ("graph_host", "host");
+ const char *plugin = get_part_from_param ("graph_plugin", "plugin");
+ const char *plugin_instance = get_part_from_param ("graph_plugin_instance", "plugin_instance");
+ const char *type = get_part_from_param ("graph_type", "type");
+ const char *type_instance = get_part_from_param ("graph_type_instance", "type_instance");
+ graph_config_t *cfg;
+
+ if ((host == NULL)
+ || (plugin == NULL) || (plugin_instance == NULL)
+ || (type == NULL) || (type_instance == NULL))
+ return (NULL);
+
+ for (cfg = graph_config_head; cfg != NULL; cfg = cfg->next)
+ {
+ if ((strcmp (cfg->select.host, host) != 0)
+ || (strcmp (cfg->select.plugin, plugin) != 0)
+ || (strcmp (cfg->select.plugin_instance, plugin_instance) != 0)
+ || (strcmp (cfg->select.type, type) != 0)
+ || (strcmp (cfg->select.type_instance, type_instance) != 0))
+ continue;
+
+ return (cfg);
+ }
+
+ return (NULL);
+} /* }}} graph_config_t *graph_get_selected */
+
int gl_graph_instance_get_all (graph_config_t *cfg, /* {{{ */
gl_inst_callback callback, void *user_data)
{
return (0);
} /* }}} int gl_graph_instance_get_all */
+int gl_graph_get_title (graph_config_t *cfg, /* {{{ */
+ char *buffer, size_t buffer_size)
+{
+ if ((cfg == NULL) || (buffer == NULL) || (buffer_size < 1))
+ return (EINVAL);
+
+ buffer[0] = 0;
+ strlcat (buffer, cfg->select.host, buffer_size);
+ strlcat (buffer, "/", buffer_size);
+ strlcat (buffer, cfg->select.plugin, buffer_size);
+ if (cfg->select.plugin_instance[0] != 0)
+ {
+ strlcat (buffer, "-", buffer_size);
+ strlcat (buffer, cfg->select.plugin_instance, buffer_size);
+ }
+ strlcat (buffer, "/", buffer_size);
+ strlcat (buffer, cfg->select.type, buffer_size);
+ if (cfg->select.type_instance[0] != 0)
+ {
+ strlcat (buffer, "-", buffer_size);
+ strlcat (buffer, cfg->select.type_instance, buffer_size);
+ }
+
+ return (0);
+} /* }}} int gl_graph_get_title */
+
int gl_instance_get_all (gl_inst_callback callback, /* {{{ */
void *user_data)
{
diff --git a/graph_list.h b/graph_list.h
index 605571e1b8762b8e6ebdd7933e8c8ed7e7d4e408..59104846b24b91742be6dfacd01a2fcea0ef0302 100644 (file)
--- a/graph_list.h
+++ b/graph_list.h
int gl_graph_get_all (gl_cfg_callback callback,
void *user_data);
+graph_config_t *graph_get_selected (void);
+
int gl_graph_instance_get_all (graph_config_t *cfg,
gl_inst_callback callback, void *user_data);
+graph_instance_t *inst_get_selected (graph_config_t *cfg);
+
int gl_instance_get_all (gl_inst_callback callback,
void *user_data);
-int gl_instance_get_ident (graph_instance_t *inst,
+int gl_instance_get_params (graph_config_t *cfg, graph_instance_t *inst,
char *buffer, size_t buffer_size);
-
+int gl_graph_get_title (graph_config_t *cfg,
+ char *buffer, size_t buffer_size);
struct graph_list_s