X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=graph_instance.c;h=e1e0a362c96d917bceef9ebb9093134bf124f199;hb=de9239ac3e16e12503eae5ddbfcdaae27f262081;hp=11629a5ade4d761d7827104bb58430a6c4d44299;hpb=0a4d88e7530531c01324af54e881ca770edd10d2;p=collection4.git diff --git a/graph_instance.c b/graph_instance.c index 11629a5..e1e0a36 100644 --- a/graph_instance.c +++ b/graph_instance.c @@ -3,6 +3,7 @@ #include #include "graph_instance.h" +#include "graph_def.h" #include "graph_ident.h" #include "graph_list.h" #include "common.h" @@ -288,20 +289,9 @@ int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */ if ((cfg == NULL) || (inst == NULL) || (args == NULL)) return (EINVAL); -/* FIXME: Re-enable title and vertical label stuff. */ -#if 0 - if (cfg->title != NULL) - { - array_append (args, "-t"); - array_append (args, cfg->title); - } - - if (cfg->vertical_label != NULL) - { - array_append (args, "-v"); - array_append (args, cfg->vertical_label); - } -#endif + status = graph_get_rrdargs (cfg, inst, args); + if (status != 0) + return (status); defs = graph_get_defs (cfg); if (defs == NULL) @@ -425,6 +415,38 @@ int inst_foreach (graph_instance_t *inst, /* {{{ */ return (0); } /* }}} int inst_foreach */ +int inst_search (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */ + const char *term, inst_callback_t cb, void *user_data) +{ + graph_instance_t *ptr; + char buffer[1024]; + int status; + + if ((inst == NULL) || (cb == NULL)) + return (EINVAL); + + for (ptr = inst; ptr != NULL; ptr = ptr->next) + { + status = inst_describe (cfg, ptr, buffer, sizeof (buffer)); + if (status != 0) + { + fprintf (stderr, "inst_search: inst_describe failed\n"); + return (status); + } + + /* no match */ + if (strstr (buffer, term) == NULL) + continue; + + /* match */ + status = (*cb) (ptr, user_data); + if (status != 0) + return (status); + } + + return (0); +} /* }}} int inst_search */ + graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */ const graph_ident_t *ident) { @@ -440,4 +462,47 @@ graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */ return (NULL); } /* }}} graph_instance_t *inst_find_matching */ +int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */ + char *buffer, size_t buffer_size) +{ + graph_ident_t *cfg_select; + + if ((cfg == NULL) || (inst == NULL) + || (buffer == NULL) || (buffer_size < 2)) + return (EINVAL); + + cfg_select = graph_get_selector (cfg); + if (cfg_select == NULL) + { + fprintf (stderr, "inst_describe: graph_get_selector failed\n"); + return (-1); + } + + buffer[0] = 0; + +#define CHECK_FIELD(field) do { \ + if (IS_ANY (ident_get_##field (cfg_select))) \ + { \ + if (buffer[0] != 0) \ + strlcat (buffer, "/", buffer_size); \ + strlcat (buffer, ident_get_##field (inst->select), buffer_size); \ + } \ +} while (0) + + CHECK_FIELD (host); + CHECK_FIELD (plugin); + CHECK_FIELD (plugin_instance); + CHECK_FIELD (type); + CHECK_FIELD (type_instance); + +#undef CHECK_FIELD + + if (buffer[0] == 0) + strlcat (buffer, "default", buffer_size); + + ident_destroy (cfg_select); + + return (0); +} /* }}} int inst_describe */ + /* vim: set sw=2 sts=2 et fdm=marker : */