Exemplo n.º 1
0
int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex,
                                const char *excluderegex, int ds_type,
                                const char *plugin, const char *plugin_instance,
                                const char *type, const char *type_instance,
                                const latency_config_t latency_cfg,
                                const cdtime_t interval) {
  cu_match_t *match;
  cu_tail_match_simple_t *user_data;
  int status;

  match = match_create_simple(regex, excluderegex, ds_type);
  if (match == NULL)
    return (-1);

  user_data = calloc(1, sizeof(*user_data));
  if (user_data == NULL) {
    match_destroy(match);
    return (-1);
  }

  sstrncpy(user_data->plugin, plugin, sizeof(user_data->plugin));
  if (plugin_instance != NULL)
    sstrncpy(user_data->plugin_instance, plugin_instance,
             sizeof(user_data->plugin_instance));

  sstrncpy(user_data->type, type, sizeof(user_data->type));
  if (type_instance != NULL)
    sstrncpy(user_data->type_instance, type_instance,
             sizeof(user_data->type_instance));

  user_data->interval = interval;

  if ((ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
      (ds_type & UTILS_MATCH_CF_GAUGE_DIST)) {
    status = latency_config_copy(&user_data->latency_config, latency_cfg);
    if (status != 0) {
      ERROR("tail_match_add_match_simple: latency_config_copy() failed.");
      status = -1;
      goto out;
    }

    status = tail_match_add_match(obj, match, latency_submit_match, user_data,
                                  tail_match_simple_free);
  } else {
    status =
        tail_match_add_match(obj, match, simple_submit_match, user_data, free);
  }

out:
  if (status != 0) {
    tail_match_simple_free(user_data);
    match_destroy(match);
  }

  return (status);
} /* int tail_match_add_match_simple */
Exemplo n.º 2
0
static int cc_config_add_match (web_page_t *page, /* {{{ */
    oconfig_item_t *ci)
{
  web_match_t *match;
  int status;
  int i;

  if (ci->values_num != 0)
  {
    WARNING ("curl plugin: Ignoring arguments for the `Match' block.");
  }

  match = calloc (1, sizeof (*match));
  if (match == NULL)
  {
    ERROR ("curl plugin: calloc failed.");
    return (-1);
  }

  status = 0;
  for (i = 0; i < ci->children_num; i++)
  {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp ("Regex", child->key) == 0)
      status = cf_util_get_string (child, &match->regex);
    else if (strcasecmp ("ExcludeRegex", child->key) == 0)
      status = cf_util_get_string (child, &match->exclude_regex);
    else if (strcasecmp ("DSType", child->key) == 0)
      status = cc_config_add_match_dstype (&match->dstype, child);
    else if (strcasecmp ("Type", child->key) == 0)
      status = cf_util_get_string (child, &match->type);
    else if (strcasecmp ("Instance", child->key) == 0)
      status = cf_util_get_string (child, &match->instance);
    else
    {
      WARNING ("curl plugin: Option `%s' not allowed here.", child->key);
      status = -1;
    }

    if (status != 0)
      break;
  } /* for (i = 0; i < ci->children_num; i++) */

  while (status == 0)
  {
    if (match->regex == NULL)
    {
      WARNING ("curl plugin: `Regex' missing in `Match' block.");
      status = -1;
    }

    if (match->type == NULL)
    {
      WARNING ("curl plugin: `Type' missing in `Match' block.");
      status = -1;
    }

    if (match->dstype == 0)
    {
      WARNING ("curl plugin: `DSType' missing in `Match' block.");
      status = -1;
    }

    break;
  } /* while (status == 0) */

  if (status != 0)
  {
    cc_web_match_free (match);
    return (status);
  }

  match->match = match_create_simple (match->regex, match->exclude_regex,
      match->dstype);
  if (match->match == NULL)
  {
    ERROR ("curl plugin: tail_match_add_match_simple failed.");
    cc_web_match_free (match);
    return (-1);
  }
  else
  {
    web_match_t *prev;

    prev = page->matches;
    while ((prev != NULL) && (prev->next != NULL))
      prev = prev->next;

    if (prev == NULL)
      page->matches = match;
    else
      prev->next = match;
  }

  return (0);
} /* }}} int cc_config_add_match */