+static int gmond_config_set_string (oconfig_item_t *ci, char **str) /* {{{ */
+{
+ char *tmp;
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ WARNING ("gmond plugin: The `%s' option needs "
+ "exactly one string argument.", ci->key);
+ return (-1);
+ }
+
+ tmp = strdup (ci->values[0].value.string);
+ if (tmp == NULL)
+ {
+ ERROR ("gmond plugin: strdup failed.");
+ return (-1);
+ }
+
+ sfree (*str);
+ *str = tmp;
+ return (0);
+} /* }}} int gmond_config_set_string */
+
+static int gmond_config_add_metric (oconfig_item_t *ci) /* {{{ */
+{
+ metric_map_t *map;
+ int i;
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ WARNING ("gmond plugin: `Metric' blocks need "
+ "exactly one string argument.");
+ return (-1);
+ }
+
+ map = realloc (metric_map, (metric_map_len + 1) * sizeof (*metric_map));
+ if (map == NULL)
+ {
+ ERROR ("gmond plugin: realloc failed.");
+ return (-1);
+ }
+ metric_map = map;
+ map = metric_map + metric_map_len;
+
+ memset (map, 0, sizeof (*map));
+ map->type = NULL;
+ map->type_instance = NULL;
+ map->ds_name = NULL;
+ map->ds_type = -1;
+ map->ds_index = -1;
+
+ map->ganglia_name = strdup (ci->values[0].value.string);
+ if (map->ganglia_name == NULL)
+ {
+ ERROR ("gmond plugin: strdup failed.");
+ return (-1);
+ }
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+ if (strcasecmp ("Type", child->key) == 0)
+ gmond_config_set_string (child, &map->type);
+ else if (strcasecmp ("TypeInstance", child->key) == 0)
+ gmond_config_set_string (child, &map->type_instance);
+ else if (strcasecmp ("DataSource", child->key) == 0)
+ gmond_config_set_string (child, &map->ds_name);
+ else
+ {
+ WARNING ("gmond plugin: Unknown configuration option `%s' ignored.",
+ child->key);
+ }
+ }
+
+ if (map->type == NULL)
+ {
+ ERROR ("gmond plugin: No type is set for metric %s.",
+ map->ganglia_name);
+ sfree (map->ganglia_name);
+ sfree (map->type_instance);
+ return (-1);
+ }
+
+ metric_map_len++;
+ return (0);
+} /* }}} int gmond_config_add_metric */
+
+static int gmond_config_set_address (oconfig_item_t *ci, /* {{{ */
+ char **ret_addr, char **ret_port)
+{
+ char *addr;
+ char *port;
+
+ if ((ci->values_num != 1) && (ci->values_num != 2))
+ {
+ WARNING ("gmond plugin: The `%s' config option needs "
+ "one or two string arguments.",
+ ci->key);
+ return (-1);
+ }
+ if ((ci->values[0].type != OCONFIG_TYPE_STRING)
+ || ((ci->values_num == 2)
+ && (ci->values[1].type != OCONFIG_TYPE_STRING)))
+ {
+ WARNING ("gmond plugin: The `%s' config option needs "
+ "one or two string arguments.",
+ ci->key);
+ return (-1);
+ }
+
+ addr = strdup (ci->values[0].value.string);
+ if (ci->values_num == 2)
+ port = strdup (ci->values[1].value.string);
+ else
+ port = NULL;
+
+ if ((addr == NULL) || ((ci->values_num == 2) && (port == NULL)))
+ {
+ ERROR ("gmond plugin: strdup failed.");
+ sfree (addr);
+ sfree (port);
+ return (-1);
+ }
+
+ sfree (*ret_addr);
+ sfree (*ret_port);
+
+ *ret_addr = addr;
+ *ret_port = port;
+
+ return (0);
+} /* }}} int gmond_config_set_address */
+
+static int gmond_config (oconfig_item_t *ci) /* {{{ */
+{
+ int i;
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+ if (strcasecmp ("MCReceiveFrom", child->key) == 0)
+ gmond_config_set_address (child, &mc_receive_group, &mc_receive_port);
+ else if (strcasecmp ("Metric", child->key) == 0)
+ gmond_config_add_metric (child);
+ else
+ {
+ WARNING ("gmond plugin: Unknown configuration option `%s' ignored.",
+ child->key);
+ }
+ }
+
+ return (0);
+} /* }}} int gmond_config */