diff --git a/src/graph_instance.c b/src/graph_instance.c
index e560527026c989b39a52d6b0e9f0c8b95d1dac85..317c381f77f7c48aad0dd664d4279161290ed032 100644 (file)
--- a/src/graph_instance.c
+++ b/src/graph_instance.c
#include <string.h>
#include <errno.h>
#include <time.h>
+#include <assert.h>
#include "graph_instance.h"
+#include "graph.h"
#include "graph_def.h"
#include "graph_ident.h"
#include "graph_list.h"
struct def_callback_data_s
{
graph_instance_t *inst;
- str_array_t *args;
+ rrd_args_t *args;
};
typedef struct def_callback_data_s def_callback_data_t;
@@ -122,7 +124,7 @@ static int gl_instance_get_rrdargs_cb (graph_def_t *def, void *user_data) /* {{{
{
def_callback_data_t *data = user_data;
graph_instance_t *inst = data->inst;
- str_array_t *args = data->args;
+ rrd_args_t *args = data->args;
size_t i;
return (param (sec_key));
} /* }}} const char *get_part_from_param */
+static graph_ident_t *inst_get_selector_from_params (void) /* {{{ */
+{
+ 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_ident_t *ident;
+
+ if ((host == NULL)
+ || (plugin == NULL) || (plugin_instance == NULL)
+ || (type == NULL) || (type_instance == NULL))
+ {
+ fprintf (stderr, "inst_get_selected: A parameter is NULL\n");
+ return (NULL);
+ }
+
+ ident = ident_create (host, plugin, plugin_instance, type, type_instance);
+ if (ident == NULL)
+ {
+ fprintf (stderr, "inst_get_selected: ident_create failed\n");
+ return (NULL);
+ }
+
+ return (ident);
+} /* }}} graph_ident_t *inst_get_selector_from_params */
+
/*
* Public functions
*/
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_ident_t *ident;
graph_instance_t *inst;
return (NULL);
}
- if ((host == NULL)
- || (plugin == NULL) || (plugin_instance == NULL)
- || (type == NULL) || (type_instance == NULL))
- {
- DEBUG ("inst_get_selected: A parameter is NULL.\n");
- return (NULL);
- }
-
- ident = ident_create (host, plugin, plugin_instance, type, type_instance);
+ ident = inst_get_selector_from_params ();
if (ident == NULL)
{
fprintf (stderr, "inst_get_selected: ident_create failed\n");
}
inst = graph_inst_find_exact (cfg, ident);
- ident_destroy (ident);
+ ident_destroy (ident);
return (inst);
} /* }}} graph_instance_t *inst_get_selected */
+int inst_get_all_selected (graph_config_t *cfg, /* {{{ */
+ graph_inst_callback_t callback, void *user_data)
+{
+ graph_ident_t *ident;
+ int status;
+
+ if ((cfg == NULL) || (callback == NULL))
+ return (EINVAL);
+
+ ident = inst_get_selector_from_params ();
+ if (ident == NULL)
+ {
+ fprintf (stderr, "inst_get_all_selected: "
+ "inst_get_selector_from_params failed\n");
+ return (EINVAL);
+ }
+
+ status = graph_inst_find_all_matching (cfg, ident, callback, user_data);
+
+ ident_destroy (ident);
+ return (status);
+} /* }}} int inst_get_all_selected */
+
int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */
graph_instance_t *inst,
- str_array_t *args)
+ rrd_args_t *args)
{
def_callback_data_t data = { inst, args };
graph_def_t *defs;
return (ident_compare (inst->select, ident));
} /* }}} int inst_compare_ident */
-_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */
+_Bool inst_ident_matches (graph_instance_t *inst, /* {{{ */
const graph_ident_t *ident)
{
if ((inst == NULL) || (ident == NULL))
return (0);
return (ident_matches (inst->select, ident));
+} /* }}} _Bool inst_ident_matches */
+
+_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */
+ const graph_ident_t *ident)
+{
+ if ((inst == NULL) || (ident == NULL))
+ return (0);
+
+ return (ident_matches (ident, inst->select));
} /* }}} _Bool inst_matches_ident */
_Bool inst_matches_string (graph_config_t *cfg, /* {{{ */
return (1);
} /* }}} _Bool inst_matches_string */
+_Bool inst_matches_field (graph_instance_t *inst, /* {{{ */
+ graph_ident_field_t field, const char *field_value)
+{
+ const char *selector_field;
+ size_t i;
+
+ if ((inst == NULL) || (field_value == NULL))
+ return (0);
+
+ selector_field = ident_get_field (inst->select, field);
+ if (selector_field == NULL)
+ return (0);
+
+ assert (!IS_ANY (selector_field));
+ if (!IS_ALL (selector_field))
+ {
+ if (strcasecmp (selector_field, field_value) == 0)
+ return (1);
+ else
+ return (0);
+ }
+
+ /* The selector field is an ALL selector
+ * => we need to check the files to see if the instance matches. */
+ for (i = 0; i < inst->files_num; i++)
+ {
+ selector_field = ident_get_field (inst->files[i], field);
+ if (selector_field == NULL)
+ continue;
+
+ assert (!IS_ANY (selector_field));
+ assert (!IS_ALL (selector_field));
+
+ if (strcasecmp (selector_field, field_value) == 0)
+ return (1);
+ } /* for files */
+
+ return (0);
+} /* }}} _Bool inst_matches_field */
+
int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
char *buffer, size_t buffer_size)
{