#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"
graph_ident_t **files;
size_t files_num;
-
- graph_instance_t *next;
}; /* }}} struct graph_instance_s */
struct def_callback_data_s
i->files = NULL;
i->files_num = 0;
- i->next = NULL;
-
return (i);
} /* }}} graph_instance_t *inst_create */
void inst_destroy (graph_instance_t *inst) /* {{{ */
{
- graph_instance_t *next;
size_t i;
if (inst == NULL)
return;
- next = inst->next;
-
ident_destroy (inst->select);
for (i = 0; i < inst->files_num; i++)
free (inst->files);
free (inst);
-
- inst_destroy (next);
} /* }}} void inst_destroy */
int inst_add_file (graph_instance_t *inst, /* {{{ */
{
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 *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");
+ const char *type_instance = get_part_from_param ("inst_type_instance",
+ "type_instance");
+
graph_ident_t *ident;
graph_instance_t *inst;
}
ident = ident_create (host, plugin, plugin_instance, type, type_instance);
-
- for (inst = graph_get_instances (cfg); inst != NULL; inst = inst->next)
+ if (ident == NULL)
{
- if (ident_compare (ident, inst->select) != 0)
- continue;
-
- ident_destroy (ident);
- return (inst);
+ fprintf (stderr, "inst_get_selected: ident_create failed\n");
+ return (NULL);
}
- DEBUG ("inst_get_selected: No match found.\n");
+ inst = graph_inst_find_exact (cfg, ident);
ident_destroy (ident);
- return (NULL);
+
+ return (inst);
} /* }}} graph_instance_t *inst_get_selected */
int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */
return (0);
} /* }}} int inst_get_params */
-int inst_append (graph_instance_t *head, graph_instance_t *inst) /* {{{ */
+int inst_compare_ident (graph_instance_t *inst, /* {{{ */
+ const graph_ident_t *ident)
{
- graph_instance_t *ptr;
-
- if ((head == NULL) || (inst == NULL))
- return (EINVAL);
+ if ((inst == NULL) || (ident == NULL))
+ return (0);
- ptr = head;
- while (ptr->next != NULL)
- ptr = ptr->next;
+ return (ident_compare (inst->select, ident));
+} /* }}} int inst_compare_ident */
- ptr->next = inst;
+_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */
+ const graph_ident_t *ident)
+{
+ if ((inst == NULL) || (ident == NULL))
+ return (0);
- return (0);
-} /* }}} int inst_append */
+ return (ident_matches (inst->select, ident));
+} /* }}} _Bool inst_matches_ident */
-int inst_foreach (graph_instance_t *inst, /* {{{ */
- inst_callback_t cb, void *user_data)
+_Bool inst_matches_string (graph_config_t *cfg, /* {{{ */
+ graph_instance_t *inst,
+ const char *term)
{
- graph_instance_t *ptr;
+ char buffer[1024];
+ int status;
- if ((inst == NULL) || (cb == NULL))
- return (EINVAL);
+ if ((cfg == NULL) || (inst == NULL) || (term == NULL))
+ return (0);
- for (ptr = inst; ptr != NULL; ptr = ptr->next)
+ status = inst_describe (cfg, inst, buffer, sizeof (buffer));
+ if (status != 0)
{
- int status;
-
- status = (*cb) (ptr, user_data);
- if (status != 0)
- return (status);
+ fprintf (stderr, "inst_matches_string: inst_describe failed\n");
+ return (status);
}
- return (0);
-} /* }}} int inst_foreach */
+ strtolower (buffer);
-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;
+ /* no match */
+ if (strstr (buffer, term) == NULL)
+ return (0);
- if ((inst == NULL) || (cb == NULL))
- return (EINVAL);
+ return (1);
+} /* }}} _Bool inst_matches_string */
- 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);
- }
+_Bool inst_matches_field (graph_instance_t *inst, /* {{{ */
+ graph_ident_field_t field, const char *field_value)
+{
+ const char *selector_field;
+ size_t i;
- strtolower (buffer);
+ if ((inst == NULL) || (field_value == NULL))
+ return (0);
- /* no match */
- if (strstr (buffer, term) == NULL)
- continue;
+ selector_field = ident_get_field (inst->select, field);
+ if (selector_field == NULL)
+ return (0);
- /* match */
- status = (*cb) (ptr, user_data);
- if (status != 0)
- return (status);
+ assert (!IS_ANY (selector_field));
+ if (!IS_ALL (selector_field))
+ {
+ if (strcasecmp (selector_field, field_value) == 0)
+ return (1);
+ else
+ return (0);
}
- return (0);
-} /* }}} int inst_search */
-
-graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */
- const graph_ident_t *ident)
-{
- graph_instance_t *ptr;
+ /* 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;
- if ((inst == NULL) || (ident == NULL))
- return (NULL);
+ assert (!IS_ANY (selector_field));
+ assert (!IS_ALL (selector_field));
- for (ptr = inst; ptr != NULL; ptr = ptr->next)
- if (ident_matches (ptr->select, ident))
- return (ptr);
+ if (strcasecmp (selector_field, field_value) == 0)
+ return (1);
+ } /* for files */
- return (NULL);
-} /* }}} graph_instance_t *inst_find_matching */
+ return (0);
+} /* }}} _Bool inst_matches_field */
int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
char *buffer, size_t buffer_size)