Example #1
0
static redis_query_t *redis_config_query (oconfig_item_t *ci) /* {{{ */
{
    redis_query_t *rq;
    int status;
    int i;

    rq = calloc(1, sizeof(*rq));
    if (rq == NULL) {
        ERROR("redis plugin: calloc failed adding redis_query.");
        return NULL;
    }
    status = cf_util_get_string_buffer(ci, rq->query, sizeof(rq->query));
    if (status != 0)
        goto err;

    /*
     * Default to a gauge type.
     */
    (void)strncpy(rq->type, "gauge", sizeof(rq->type));
    (void)sstrncpy(rq->instance, rq->query, sizeof(rq->instance));
    replace_special(rq->instance, sizeof(rq->instance));

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

        if (strcasecmp("Type", option->key) == 0) {
            status = cf_util_get_string_buffer(option, rq->type, sizeof(rq->type));
        } else if (strcasecmp("Instance", option->key) == 0) {
            status = cf_util_get_string_buffer(option, rq->instance, sizeof(rq->instance));
        } else {
            WARNING("redis plugin: unknown configuration option: %s", option->key);
            status = -1;
        }
        if (status != 0)
            goto err;
    }
    return rq;
 err:
    free(rq);
    return NULL;
} /* }}} */
Example #2
0
static int tbl_config_table (oconfig_item_t *ci)
{
	tbl_t *tbl;

	int status = 0;
	size_t i;

	if ((1 != ci->values_num)
			|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
		log_err ("<Table> expects a single string argument.");
		return 1;
	}

	tbl = realloc (tables, (tables_num + 1) * sizeof (*tables));
	if (NULL == tbl) {
		char errbuf[1024];
		log_err ("realloc failed: %s.",
				sstrerror (errno, errbuf, sizeof (errbuf)));
		return -1;
	}

	tables = tbl;
	++tables_num;

	tbl = tables + tables_num - 1;
	tbl_setup (tbl, ci->values[0].value.string);

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

		if (0 == strcasecmp (c->key, "Separator"))
			tbl_config_set_s (c->key, &tbl->sep, c);
		else if (0 == strcasecmp (c->key, "Instance"))
			tbl_config_set_s (c->key, &tbl->instance, c);
		else if (0 == strcasecmp (c->key, "Result"))
			tbl_config_result (tbl, c);
		else
			log_warn ("Ignoring unknown config key \"%s\" "
					"in <Table %s>.", c->key, tbl->file);
	}

	if (NULL == tbl->sep) {
		log_err ("Table \"%s\" does not specify any separator.", tbl->file);
		status = 1;
	} else {
		strunescape (tbl->sep, strlen (tbl->sep) + 1);
	}

	if (NULL == tbl->instance) {
		tbl->instance = sstrdup (tbl->file);
		replace_special (tbl->instance, strlen (tbl->instance));
	}

	if (NULL == tbl->results) {
		log_err ("Table \"%s\" does not specify any (valid) results.",
				tbl->file);
		status = 1;
	}

	if (0 != status) {
		tbl_clear (tbl);
		--tables_num;
		return status;
	}

	for (i = 0; i < tbl->results_num; ++i) {
		tbl_result_t *res = tbl->results + i;
		size_t j;

		for (j = 0; j < res->instances_num; ++j)
			if (res->instances[j] > tbl->max_colnum)
				tbl->max_colnum = res->instances[j];

		for (j = 0; j < res->values_num; ++j)
			if (res->values[j] > tbl->max_colnum)
				tbl->max_colnum = res->values[j];
	}
	return 0;
} /* tbl_config_table */
Example #3
0
static int tbl_config_table(oconfig_item_t *ci) {
  if (ci->values_num != 1 || ci->values[0].type != OCONFIG_TYPE_STRING) {
    log_err("<Table> expects a single string argument.");
    return 1;
  }

  tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
  if (tbl == NULL) {
    log_err("realloc failed: %s.", STRERRNO);
    return -1;
  }

  tables = tbl;

  tbl = tables + tables_num;
  tbl_setup(tbl, ci->values[0].value.string);

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

    if (strcasecmp(c->key, "Separator") == 0)
      cf_util_get_string(c, &tbl->sep);
    else if (strcasecmp(c->key, "Plugin") == 0)
      cf_util_get_string(c, &tbl->plugin_name);
    else if (strcasecmp(c->key, "Instance") == 0)
      cf_util_get_string(c, &tbl->instance);
    else if (strcasecmp(c->key, "Result") == 0)
      tbl_config_result(tbl, c);
    else
      log_warn("Ignoring unknown config key \"%s\" "
               "in <Table %s>.",
               c->key, tbl->file);
  }

  int status = 0;
  if (tbl->sep == NULL) {
    log_err("Table \"%s\" does not specify any separator.", tbl->file);
    status = 1;
  } else {
    strunescape(tbl->sep, strlen(tbl->sep) + 1);
  }

  if (tbl->instance == NULL) {
    tbl->instance = sstrdup(tbl->file);
    replace_special(tbl->instance, strlen(tbl->instance));
  }

  if (tbl->results == NULL) {
    assert(tbl->results_num == 0);
    log_err("Table \"%s\" does not specify any (valid) results.", tbl->file);
    status = 1;
  }

  if (status != 0) {
    tbl_clear(tbl);
    return status;
  }

  for (size_t i = 0; i < tbl->results_num; ++i) {
    tbl_result_t *res = tbl->results + i;

    for (size_t j = 0; j < res->instances_num; ++j)
      if (res->instances[j] > tbl->max_colnum)
        tbl->max_colnum = res->instances[j];

    for (size_t j = 0; j < res->values_num; ++j)
      if (res->values[j] > tbl->max_colnum)
        tbl->max_colnum = res->values[j];
  }

  tables_num++;
  return 0;
} /* tbl_config_table */