예제 #1
0
파일: tail.c 프로젝트: collectd/collectd
static int ctail_config_add_file(oconfig_item_t *ci) {
  cu_tail_match_t *tm;
  cdtime_t interval = 0;
  char *plugin_name = NULL;
  char *plugin_instance = NULL;
  int num_matches = 0;

  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
    WARNING("tail plugin: `File' needs exactly one string argument.");
    return -1;
  }

  tm = tail_match_create(ci->values[0].value.string);
  if (tm == NULL) {
    ERROR("tail plugin: tail_match_create (%s) failed.",
          ci->values[0].value.string);
    return -1;
  }

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

    if (strcasecmp("Plugin", option->key) == 0)
      status = cf_util_get_string(option, &plugin_name);
    else if (strcasecmp("Instance", option->key) == 0)
      status = cf_util_get_string(option, &plugin_instance);
    else if (strcasecmp("Interval", option->key) == 0)
      cf_util_get_cdtime(option, &interval);
    else if (strcasecmp("Match", option->key) == 0) {
      status = ctail_config_add_match(tm, plugin_name, plugin_instance, option);
      if (status == 0)
        num_matches++;
      /* Be mild with failed matches.. */
      status = 0;
    } else {
      status = -1;
    }

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

  sfree(plugin_name);
  sfree(plugin_instance);

  if (num_matches == 0) {
    ERROR("tail plugin: No (valid) matches found for file `%s'.",
          ci->values[0].value.string);
    tail_match_destroy(tm);
    return -1;
  }

  char str[255];
  snprintf(str, sizeof(str), "tail-%zu", tail_file_num++);

  plugin_register_complex_read(
      NULL, str, ctail_read, interval,
      &(user_data_t){.data = tm, .free_func = ctail_match_free});
예제 #2
0
파일: tail.c 프로젝트: paul/collectd
static int ctail_shutdown (void)
{
    size_t i;

    for (i = 0; i < tail_match_list_num; i++)
    {
        tail_match_destroy (tail_match_list[i]);
        tail_match_list[i] = NULL;
    }
    sfree (tail_match_list);
    tail_match_list_num = 0;

    return (0);
} /* int ctail_shutdown */
예제 #3
0
파일: tail.c 프로젝트: collectd/collectd
static void ctail_match_free(void *arg) {
  tail_match_destroy((cu_tail_match_t *)arg);
} /* void ctail_match_free */
예제 #4
0
파일: tail.c 프로젝트: paul/collectd
static int ctail_config_add_file (oconfig_item_t *ci)
{
    cu_tail_match_t *tm;
    char *plugin_instance = NULL;
    int num_matches = 0;
    int status;
    int i;

    if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
    {
        WARNING ("tail plugin: `File' needs exactly one string argument.");
        return (-1);
    }

    tm = tail_match_create (ci->values[0].value.string);
    if (tm == NULL)
    {
        ERROR ("tail plugin: tail_match_create (%s) failed.",
               ci->values[0].value.string);
        return (-1);
    }

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

        if (strcasecmp ("Match", option->key) == 0)
        {
            status = ctail_config_add_match (tm, plugin_instance, option);
            if (status == 0)
                num_matches++;
            /* Be mild with failed matches.. */
            status = 0;
        }
        else if (strcasecmp ("Instance", option->key) == 0)
            status = ctail_config_add_string ("Instance", &plugin_instance, option);
        else
        {
            WARNING ("tail plugin: Option `%s' not allowed here.", option->key);
            status = -1;
        }

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

    if (num_matches == 0)
    {
        ERROR ("tail plugin: No (valid) matches found for file `%s'.",
               ci->values[0].value.string);
        tail_match_destroy (tm);
        return (-1);
    }
    else
    {
        cu_tail_match_t **temp;

        temp = (cu_tail_match_t **) realloc (tail_match_list,
                                             sizeof (cu_tail_match_t *) * (tail_match_list_num + 1));
        if (temp == NULL)
        {
            ERROR ("tail plugin: realloc failed.");
            tail_match_destroy (tm);
            return (-1);
        }

        tail_match_list = temp;
        tail_match_list[tail_match_list_num] = tm;
        tail_match_list_num++;
    }

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