return fc_config_set_instance(dir, ci->values[0].value.string);
} /* int fc_config_add_dir_instance */
-static int fc_config_add_dir_name(fc_directory_conf_t *dir,
- oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("filecount plugin: The `Name' config option needs exactly one "
- "string argument.");
- return -1;
- }
-
- char *temp = strdup(ci->values[0].value.string);
- if (temp == NULL) {
- ERROR("filecount plugin: strdup failed.");
- return -1;
- }
-
- sfree(dir->name);
- dir->name = temp;
-
- return 0;
-} /* int fc_config_add_dir_name */
-
static int fc_config_add_dir_mtime(fc_directory_conf_t *dir,
oconfig_item_t *ci) {
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_STRING) &&
else if (strcasecmp("Instance", option->key) == 0)
status = fc_config_add_dir_instance(dir, option);
else if (strcasecmp("Name", option->key) == 0)
- status = fc_config_add_dir_name(dir, option);
+ status = cf_util_get_string(option, &dir->name);
else if (strcasecmp("MTime", option->key) == 0)
status = fc_config_add_dir_mtime(dir, option);
else if (strcasecmp("Size", option->key) == 0)
* </Metric>
* </Plugin>
*/
-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;
for (int 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);
+ cf_util_get_string(child, &map->type);
else if (strcasecmp("TypeInstance", child->key) == 0)
- gmond_config_set_string(child, &map->type_instance);
+ cf_util_get_string(child, &map->type_instance);
else if (strcasecmp("DataSource", child->key) == 0)
- gmond_config_set_string(child, &map->ds_name);
+ cf_util_get_string(child, &map->ds_name);
else {
WARNING("gmond plugin: Unknown configuration option `%s' ignored.",
child->key);
return 0;
} /* }}} int cmc_page_init_memc */
-static int cmc_config_add_string(const char *name, char **dest, /* {{{ */
- oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("memcachec plugin: `%s' needs exactly one string argument.", name);
- return -1;
- }
-
- sfree(*dest);
- *dest = strdup(ci->values[0].value.string);
- if (*dest == NULL)
- return -1;
-
- return 0;
-} /* }}} int cmc_config_add_string */
-
static int cmc_config_add_match_dstype(int *dstype_ret, /* {{{ */
oconfig_item_t *ci) {
int dstype;
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Regex", child->key) == 0)
- status = cmc_config_add_string("Regex", &match->regex, child);
+ status = cf_util_get_string(child, &match->regex);
else if (strcasecmp("ExcludeRegex", child->key) == 0)
- status =
- cmc_config_add_string("ExcludeRegex", &match->exclude_regex, child);
+ status = cf_util_get_string(child, &match->exclude_regex);
else if (strcasecmp("DSType", child->key) == 0)
status = cmc_config_add_match_dstype(&match->dstype, child);
else if (strcasecmp("Type", child->key) == 0)
- status = cmc_config_add_string("Type", &match->type, child);
+ status = cf_util_get_string(child, &match->type);
else if (strcasecmp("Instance", child->key) == 0)
- status = cmc_config_add_string("Instance", &match->instance, child);
+ status = cf_util_get_string(child, &match->instance);
else {
WARNING("memcachec plugin: Option `%s' not allowed here.", child->key);
status = -1;
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Server", child->key) == 0)
- status = cmc_config_add_string("Server", &page->server, child);
+ status = cf_util_get_string(child, &page->server);
else if (strcasecmp("Key", child->key) == 0)
- status = cmc_config_add_string("Key", &page->key, child);
+ status = cf_util_get_string(child, &page->key);
else if (strcasecmp("Plugin", child->key) == 0)
- status = cmc_config_add_string("Plugin", &page->plugin_name, child);
+ status = cf_util_get_string(child, &page->plugin_name);
else if (strcasecmp("Match", child->key) == 0)
/* Be liberal with failing matches => don't set `status'. */
cmc_config_add_match(page, child);
/*
* Configuration handling
*/
-/* Sets a given flag if the boolean argument is true and unsets the flag if it
- * is false. On error, the flag-field is not changed. */
-static int cna_config_bool_to_flag(const oconfig_item_t *ci, /* {{{ */
- uint32_t *flags, uint32_t flag) {
- if ((ci == NULL) || (flags == NULL))
- return EINVAL;
-
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
- WARNING("netapp plugin: The %s option needs exactly one boolean argument.",
- ci->key);
- return -1;
- }
-
- if (ci->values[0].value.boolean)
- *flags |= flag;
- else
- *flags &= ~flag;
-
- return 0;
-} /* }}} int cna_config_bool_to_flag */
-
-/* Handling of the "Interval" option which is allowed in every block. */
-static int cna_config_get_interval(const oconfig_item_t *ci, /* {{{ */
- cna_interval_t *out_interval) {
- cdtime_t tmp = 0;
- int status;
-
- status = cf_util_get_cdtime(ci, &tmp);
- if (status != 0)
- return status;
-
- out_interval->interval = tmp;
- out_interval->last_read = 0;
-
- return 0;
-} /* }}} int cna_config_get_interval */
/* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
* <VolumePerf /> block. */
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_volume_perf->interval);
+ cf_util_get_cdtime(item, &cfg_volume_perf->interval.interval);
else if (!strcasecmp(item->key, "GetIO"))
cna_config_volume_perf_option(cfg_volume_perf, item);
else if (!strcasecmp(item->key, "GetOps"))
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_quota->interval);
+ cf_util_get_cdtime(item, &cfg_quota->interval.interval);
else
WARNING("netapp plugin: The option %s is not allowed within "
"`Quota' blocks.",
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_disk->interval);
+ cf_util_get_cdtime(item, &cfg_disk->interval.interval);
else if (strcasecmp(item->key, "GetBusy") == 0)
- cna_config_bool_to_flag(item, &cfg_disk->flags, CFG_DISK_BUSIEST);
+ cf_util_get_flag(item, &cfg_disk->flags, CFG_DISK_BUSIEST);
}
if ((cfg_disk->flags & CFG_DISK_ALL) == 0) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_wafl->interval);
+ cf_util_get_cdtime(item, &cfg_wafl->interval.interval);
else if (!strcasecmp(item->key, "GetNameCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
else if (!strcasecmp(item->key, "GetDirCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
else if (!strcasecmp(item->key, "GetBufferCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
else if (!strcasecmp(item->key, "GetInodeCache"))
- cna_config_bool_to_flag(item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
+ cf_util_get_flag(item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
else
WARNING("netapp plugin: The %s config option is not allowed within "
"`WAFL' blocks.",
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_volume_usage->interval);
+ cf_util_get_cdtime(item, &cfg_volume_usage->interval.interval);
else if (!strcasecmp(item->key, "GetCapacity"))
cna_config_volume_usage_option(cfg_volume_usage, item);
else if (!strcasecmp(item->key, "GetSnapshot"))
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
- cna_config_get_interval(item, &cfg_snapvault->interval);
+ cf_util_get_cdtime(item, &cfg_snapvault->interval.interval);
else
WARNING("netapp plugin: The option %s is not allowed within "
"`SnapVault' blocks.",
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0) {
- cna_config_get_interval(item, &cfg_system->interval);
+ cf_util_get_cdtime(item, &cfg_system->interval.interval);
} else if (!strcasecmp(item->key, "GetCPULoad")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_CPU);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_CPU);
} else if (!strcasecmp(item->key, "GetInterfaces")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_NET);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_NET);
} else if (!strcasecmp(item->key, "GetDiskOps")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_OPS);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_OPS);
} else if (!strcasecmp(item->key, "GetDiskIO")) {
- cna_config_bool_to_flag(item, &cfg_system->flags, CFG_SYSTEM_DISK);
+ cf_util_get_flag(item, &cfg_system->flags, CFG_SYSTEM_DISK);
} else {
WARNING("netapp plugin: The %s config option is not allowed within "
"`System' blocks.",
/*
* configuration handling
*/
-
-static int tbl_config_set_s(char *name, char **var, oconfig_item_t *ci) {
- if (ci->values_num != 1 || ci->values[0].type != OCONFIG_TYPE_STRING) {
- log_err("\"%s\" expects a single string argument.", name);
- return 1;
- }
-
- sfree(*var);
- *var = sstrdup(ci->values[0].value.string);
- return 0;
-} /* tbl_config_set_separator */
-
static int tbl_config_append_array_i(char *name, size_t **var, size_t *len,
oconfig_item_t *ci) {
if (ci->values_num < 1) {
oconfig_item_t *c = ci->children + i;
if (strcasecmp(c->key, "Type") == 0)
- tbl_config_set_s(c->key, &res->type, c);
+ cf_util_get_string(c, &res->type);
else if (strcasecmp(c->key, "InstancePrefix") == 0)
- tbl_config_set_s(c->key, &res->instance_prefix, c);
+ cf_util_get_string(c, &res->instance_prefix);
else if (strcasecmp(c->key, "InstancesFrom") == 0)
tbl_config_append_array_i(c->key, &res->instances, &res->instances_num,
c);
oconfig_item_t *c = ci->children + i;
if (strcasecmp(c->key, "Separator") == 0)
- tbl_config_set_s(c->key, &tbl->sep, c);
+ cf_util_get_string(c, &tbl->sep);
else if (strcasecmp(c->key, "Plugin") == 0)
- tbl_config_set_s(c->key, &tbl->plugin_name, c);
+ cf_util_get_string(c, &tbl->plugin_name);
else if (strcasecmp(c->key, "Instance") == 0)
- tbl_config_set_s(c->key, &tbl->instance, c);
+ cf_util_get_string(c, &tbl->instance);
else if (strcasecmp(c->key, "Result") == 0)
tbl_config_result(tbl, c);
else
* The following approximately two hundred functions are used to handle the
* configuration and fill the threshold list.
* {{{ */
-static int ut_config_type_datasource(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("threshold values: The `DataSource' option needs exactly one "
- "string argument.");
- return -1;
- }
-
- sstrncpy(th->data_source, ci->values[0].value.string,
- sizeof(th->data_source));
-
- return 0;
-} /* int ut_config_type_datasource */
-
-static int ut_config_type_instance(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("threshold values: The `Instance' option needs exactly one "
- "string argument.");
- return -1;
- }
-
- sstrncpy(th->type_instance, ci->values[0].value.string,
- sizeof(th->type_instance));
-
- return 0;
-} /* int ut_config_type_instance */
-
-static int ut_config_type_max(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- WARNING("threshold values: The `%s' option needs exactly one "
- "number argument.",
- ci->key);
- return -1;
- }
-
- if (strcasecmp(ci->key, "WarningMax") == 0)
- th->warning_max = ci->values[0].value.number;
- else
- th->failure_max = ci->values[0].value.number;
-
- return 0;
-} /* int ut_config_type_max */
-
-static int ut_config_type_min(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- WARNING("threshold values: The `%s' option needs exactly one "
- "number argument.",
- ci->key);
- return -1;
- }
-
- if (strcasecmp(ci->key, "WarningMin") == 0)
- th->warning_min = ci->values[0].value.number;
- else
- th->failure_min = ci->values[0].value.number;
-
- return 0;
-} /* int ut_config_type_min */
-
-static int ut_config_type_hits(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- WARNING("threshold values: The `%s' option needs exactly one "
- "number argument.",
- ci->key);
- return -1;
- }
-
- th->hits = ci->values[0].value.number;
-
- return 0;
-} /* int ut_config_type_hits */
-
-static int ut_config_type_hysteresis(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- WARNING("threshold values: The `%s' option needs exactly one "
- "number argument.",
- ci->key);
- return -1;
- }
-
- th->hysteresis = ci->values[0].value.number;
-
- return 0;
-} /* int ut_config_type_hysteresis */
-
static int ut_config_type(const threshold_t *th_orig, oconfig_item_t *ci) {
threshold_t th;
int status = 0;
oconfig_item_t *option = ci->children + i;
if (strcasecmp("Instance", option->key) == 0)
- status = ut_config_type_instance(&th, option);
+ status = cf_util_get_string_buffer(option, th.type_instance,
+ sizeof(th.type_instance));
else if (strcasecmp("DataSource", option->key) == 0)
- status = ut_config_type_datasource(&th, option);
- else if ((strcasecmp("WarningMax", option->key) == 0) ||
- (strcasecmp("FailureMax", option->key) == 0))
- status = ut_config_type_max(&th, option);
- else if ((strcasecmp("WarningMin", option->key) == 0) ||
- (strcasecmp("FailureMin", option->key) == 0))
- status = ut_config_type_min(&th, option);
+ status = cf_util_get_string_buffer(option, th.data_source,
+ sizeof(th.data_source));
+ else if (strcasecmp("WarningMax", option->key) == 0)
+ status = cf_util_get_double(option, &th.warning_max);
+ else if (strcasecmp("FailureMax", option->key) == 0)
+ status = cf_util_get_double(option, &th.failure_max);
+ else if (strcasecmp("WarningMin", option->key) == 0)
+ status = cf_util_get_double(option, &th.warning_min);
+ else if (strcasecmp("FailureMin", option->key) == 0)
+ status = cf_util_get_double(option, &th.failure_min);
else if (strcasecmp("Interesting", option->key) == 0)
status = cf_util_get_flag(option, &th.flags, UT_FLAG_INTERESTING);
else if (strcasecmp("Invert", option->key) == 0)
else if (strcasecmp("Percentage", option->key) == 0)
status = cf_util_get_flag(option, &th.flags, UT_FLAG_PERCENTAGE);
else if (strcasecmp("Hits", option->key) == 0)
- status = ut_config_type_hits(&th, option);
+ status = cf_util_get_int(option, &th.hits);
else if (strcasecmp("Hysteresis", option->key) == 0)
- status = ut_config_type_hysteresis(&th, option);
+ status = cf_util_get_double(option, &th.hysteresis);
else {
WARNING("threshold values: Option `%s' not allowed inside a `Type' "
"block.",
return status;
} /* int ut_config_type */
-static int ut_config_plugin_instance(threshold_t *th, oconfig_item_t *ci) {
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("threshold values: The `Instance' option needs exactly one "
- "string argument.");
- return -1;
- }
-
- sstrncpy(th->plugin_instance, ci->values[0].value.string,
- sizeof(th->plugin_instance));
-
- return 0;
-} /* int ut_config_plugin_instance */
-
static int ut_config_plugin(const threshold_t *th_orig, oconfig_item_t *ci) {
threshold_t th;
int status = 0;
if (strcasecmp("Type", option->key) == 0)
status = ut_config_type(&th, option);
else if (strcasecmp("Instance", option->key) == 0)
- status = ut_config_plugin_instance(&th, option);
+ status = cf_util_get_string_buffer(option, th.plugin_instance,
+ sizeof(th.plugin_instance));
else {
WARNING("threshold values: Option `%s' not allowed inside a `Plugin' "
"block.",
/*
* Config Private functions
*/
-static int udb_config_set_string(char **ret_string, /* {{{ */
- oconfig_item_t *ci) {
- char *string;
-
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("db query utils: The `%s' config option "
- "needs exactly one string argument.",
- ci->key);
- return -1;
- }
-
- string = strdup(ci->values[0].value.string);
- if (string == NULL) {
- ERROR("db query utils: strdup failed.");
- return -1;
- }
-
- if (*ret_string != NULL)
- free(*ret_string);
- *ret_string = string;
-
- return 0;
-} /* }}} int udb_config_set_string */
-
static int udb_config_add_string(char ***ret_array, /* {{{ */
size_t *ret_array_len, oconfig_item_t *ci) {
char **array;
size_t array_len;
if (ci->values_num < 1) {
- WARNING("db query utils: The `%s' config option "
- "needs at least one argument.",
- ci->key);
+ P_WARNING("The `%s' config option "
+ "needs at least one argument.",
+ ci->key);
return -1;
}
for (int i = 0; i < ci->values_num; i++) {
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
- WARNING("db query utils: Argument %i to the `%s' option "
- "is not a string.",
- i + 1, ci->key);
+ P_WARNING("Argument %i to the `%s' option "
+ "is not a string.",
+ i + 1, ci->key);
return -1;
}
}
array_len = *ret_array_len;
array = realloc(*ret_array, sizeof(char *) * (array_len + ci->values_num));
if (array == NULL) {
- ERROR("db query utils: realloc failed.");
+ P_ERROR("udb_config_add_string: realloc failed.");
return -1;
}
*ret_array = array;
for (int i = 0; i < ci->values_num; i++) {
array[array_len] = strdup(ci->values[i].value.string);
if (array[array_len] == NULL) {
- ERROR("db query utils: strdup failed.");
+ P_ERROR("udb_config_add_string: strdup failed.");
*ret_array_len = array_len;
return -1;
}
static int udb_config_set_uint(unsigned int *ret_value, /* {{{ */
oconfig_item_t *ci) {
- double tmp;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
- WARNING("db query utils: The `%s' config option "
- "needs exactly one numeric argument.",
- ci->key);
+ P_WARNING("The `%s' config option "
+ "needs exactly one numeric argument.",
+ ci->key);
return -1;
}
- tmp = ci->values[0].value.number;
- if ((tmp < 0.0) || (tmp > ((double)UINT_MAX)))
+ double tmp = ci->values[0].value.number;
+ if ((tmp < 0.0) || (tmp > ((double)UINT_MAX))) {
+ P_WARNING("The value given for the `%s` option is out of range.", ci->key);
return -ERANGE;
+ }
*ret_value = (unsigned int)(tmp + .5);
return 0;
vl.values = calloc(r->values_num, sizeof(*vl.values));
if (vl.values == NULL) {
- ERROR("db query utils: calloc failed.");
+ P_ERROR("udb_result_submit: calloc failed.");
return -1;
}
vl.values_len = r_area->ds->ds_num;
char *value_str = r_area->values_buffer[i];
if (0 != parse_value(value_str, &vl.values[i], r_area->ds->ds[i].type)) {
- ERROR("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
- value_str, DS_TYPE_TO_STRING(r_area->ds->ds[i].type));
+ P_ERROR("udb_result_submit: Parsing `%s' as %s failed.", value_str,
+ DS_TYPE_TO_STRING(r_area->ds->ds[i].type));
errno = EINVAL;
free(vl.values);
return -1;
int status = strjoin(vl.type_instance, sizeof(vl.type_instance),
r_area->instances_buffer, r->instances_num, "-");
if (status < 0) {
- ERROR(
+ P_ERROR(
"udb_result_submit: creating type_instance failed with status %d.",
status);
return status;
int status = strjoin(tmp, sizeof(tmp), r_area->instances_buffer,
r->instances_num, "-");
if (status < 0) {
- ERROR(
+ P_ERROR(
"udb_result_submit: creating type_instance failed with status %d.",
status);
return status;
if (r->metadata_num > 0) {
vl.meta = meta_data_create();
if (vl.meta == NULL) {
- ERROR("db query utils:: meta_data_create failed.");
+ P_ERROR("udb_result_submit: meta_data_create failed.");
free(vl.values);
return -ENOMEM;
}
int status = meta_data_add_string(vl.meta, r->metadata[i],
r_area->metadata_buffer[i]);
if (status != 0) {
- ERROR("db query utils:: meta_data_add_string failed.");
+ P_ERROR("udb_result_submit: meta_data_add_string failed.");
meta_data_destroy(vl.meta);
vl.meta = NULL;
free(vl.values);
/* Read `ds' and check number of values {{{ */
prep_area->ds = plugin_get_ds(r->type);
if (prep_area->ds == NULL) {
- ERROR("db query utils: udb_result_prepare_result: Type `%s' is not "
- "known by the daemon. See types.db(5) for details.",
- r->type);
+ P_ERROR("udb_result_prepare_result: Type `%s' is not "
+ "known by the daemon. See types.db(5) for details.",
+ r->type);
BAIL_OUT(-1);
}
if (prep_area->ds->ds_num != r->values_num) {
- ERROR("db query utils: udb_result_prepare_result: The type `%s' "
- "requires exactly %" PRIsz
- " value%s, but the configuration specifies %" PRIsz ".",
- r->type, prep_area->ds->ds_num,
- (prep_area->ds->ds_num == 1) ? "" : "s", r->values_num);
+ P_ERROR("udb_result_prepare_result: The type `%s' "
+ "requires exactly %" PRIsz
+ " value%s, but the configuration specifies %" PRIsz ".",
+ r->type, prep_area->ds->ds_num,
+ (prep_area->ds->ds_num == 1) ? "" : "s", r->values_num);
BAIL_OUT(-1);
}
/* }}} */
prep_area->instances_pos =
(size_t *)calloc(r->instances_num, sizeof(size_t));
if (prep_area->instances_pos == NULL) {
- ERROR("db query utils: udb_result_prepare_result: calloc failed.");
+ P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->instances_buffer =
(char **)calloc(r->instances_num, sizeof(char *));
if (prep_area->instances_buffer == NULL) {
- ERROR("db query utils: udb_result_prepare_result: calloc failed.");
+ P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
} /* if (r->instances_num > 0) */
prep_area->values_pos = (size_t *)calloc(r->values_num, sizeof(size_t));
if (prep_area->values_pos == NULL) {
- ERROR("db query utils: udb_result_prepare_result: calloc failed.");
+ P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->values_buffer = (char **)calloc(r->values_num, sizeof(char *));
if (prep_area->values_buffer == NULL) {
- ERROR("db query utils: udb_result_prepare_result: calloc failed.");
+ P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->metadata_pos = (size_t *)calloc(r->metadata_num, sizeof(size_t));
if (prep_area->metadata_pos == NULL) {
- ERROR("db query utils: udb_result_prepare_result: calloc failed.");
+ P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->metadata_buffer = (char **)calloc(r->metadata_num, sizeof(char *));
if (prep_area->metadata_buffer == NULL) {
- ERROR("db query utils: udb_result_prepare_result: calloc failed.");
+ P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
}
if (j >= column_num) {
- ERROR("db query utils: udb_result_prepare_result: "
- "Column `%s' could not be found.",
- r->instances[i]);
+ P_ERROR("udb_result_prepare_result: "
+ "Column `%s' could not be found.",
+ r->instances[i]);
BAIL_OUT(-ENOENT);
}
} /* }}} for (i = 0; i < r->instances_num; i++) */
}
if (j >= column_num) {
- ERROR("db query utils: udb_result_prepare_result: "
- "Column `%s' could not be found.",
- r->values[i]);
+ P_ERROR("udb_result_prepare_result: "
+ "Column `%s' could not be found.",
+ r->values[i]);
BAIL_OUT(-ENOENT);
}
} /* }}} for (i = 0; i < r->values_num; i++) */
}
if (j >= column_num) {
- ERROR("db query utils: udb_result_prepare_result: "
- "Metadata column `%s' could not be found.",
- r->values[i]);
+ P_ERROR("udb_result_prepare_result: "
+ "Metadata column `%s' could not be found.",
+ r->values[i]);
BAIL_OUT(-ENOENT);
}
} /* }}} for (i = 0; i < r->metadata_num; i++) */
int status;
if (ci->values_num != 0) {
- WARNING("db query utils: The `Result' block doesn't accept "
- "any arguments. Ignoring %i argument%s.",
- ci->values_num, (ci->values_num == 1) ? "" : "s");
+ P_WARNING("The `Result' block doesn't accept "
+ "any arguments. Ignoring %i argument%s.",
+ ci->values_num, (ci->values_num == 1) ? "" : "s");
}
r = calloc(1, sizeof(*r));
if (r == NULL) {
- ERROR("db query utils: calloc failed.");
+ P_ERROR("udb_result_create: calloc failed.");
return -1;
}
r->type = NULL;
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Type", child->key) == 0)
- status = udb_config_set_string(&r->type, child);
+ status = cf_util_get_string(child, &r->type);
else if (strcasecmp("InstancePrefix", child->key) == 0)
- status = udb_config_set_string(&r->instance_prefix, child);
+ status = cf_util_get_string(child, &r->instance_prefix);
else if (strcasecmp("InstancesFrom", child->key) == 0)
status = udb_config_add_string(&r->instances, &r->instances_num, child);
else if (strcasecmp("ValuesFrom", child->key) == 0)
else if (strcasecmp("MetadataFrom", child->key) == 0)
status = udb_config_add_string(&r->metadata, &r->metadata_num, child);
else {
- WARNING("db query utils: Query `%s': Option `%s' not allowed here.",
- query_name, child->key);
+ P_WARNING("Query `%s': Option `%s' not allowed here.", query_name,
+ child->key);
status = -1;
}
/* Check that all necessary options have been given. */
while (status == 0) {
if (r->type == NULL) {
- WARNING("db query utils: `Type' not given for "
- "result in query `%s'",
- query_name);
+ P_WARNING("udb_result_create: `Type' not given for "
+ "result in query `%s'",
+ query_name);
status = -1;
}
if (r->values == NULL) {
- WARNING("db query utils: `ValuesFrom' not given for "
- "result in query `%s'",
- query_name);
+ P_WARNING("udb_result_create: `ValuesFrom' not given for "
+ "result in query `%s'",
+ query_name);
status = -1;
}
query_list_len = *ret_query_list_len;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- WARNING("db query utils: The `Query' block "
- "needs exactly one string argument.");
+ P_WARNING("udb_result_create: The `Query' block "
+ "needs exactly one string argument.");
return -1;
}
q = calloc(1, sizeof(*q));
if (q == NULL) {
- ERROR("db query utils: calloc failed.");
+ P_ERROR("udb_query_create: calloc failed.");
return -1;
}
q->min_version = 0;
q->results = NULL;
q->plugin_instance_from = NULL;
- status = udb_config_set_string(&q->name, ci);
+ status = cf_util_get_string(ci, &q->name);
if (status != 0) {
sfree(q);
return status;
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Statement", child->key) == 0)
- status = udb_config_set_string(&q->statement, child);
+ status = cf_util_get_string(child, &q->statement);
else if (strcasecmp("Result", child->key) == 0)
status = udb_result_create(q->name, &q->results, child);
else if (strcasecmp("MinVersion", child->key) == 0)
else if (strcasecmp("MaxVersion", child->key) == 0)
status = udb_config_set_uint(&q->max_version, child);
else if (strcasecmp("PluginInstanceFrom", child->key) == 0)
- status = udb_config_set_string(&q->plugin_instance_from, child);
+ status = cf_util_get_string(child, &q->plugin_instance_from);
/* Call custom callbacks */
else if (cb != NULL) {
status = (*cb)(q, child);
if (status != 0) {
- WARNING("db query utils: The configuration callback failed "
- "to handle `%s'.",
- child->key);
+ P_WARNING("The configuration callback failed "
+ "to handle `%s'.",
+ child->key);
}
} else {
- WARNING("db query utils: Query `%s': Option `%s' not allowed here.",
- q->name, child->key);
+ P_WARNING("Query `%s': Option `%s' not allowed here.", q->name,
+ child->key);
status = -1;
}
/* Check that all necessary options have been given. */
if (status == 0) {
if (q->statement == NULL) {
- WARNING("db query utils: Query `%s': No `Statement' given.", q->name);
+ P_WARNING("Query `%s': No `Statement' given.", q->name);
status = -1;
}
if (q->results == NULL) {
- WARNING("db query utils: Query `%s': No (valid) `Result' block given.",
- q->name);
+ P_WARNING("Query `%s': No (valid) `Result' block given.", q->name);
status = -1;
}
} /* if (status == 0) */
temp = realloc(query_list, sizeof(*query_list) * (query_list_len + 1));
if (temp == NULL) {
- ERROR("db query utils: realloc failed");
+ P_ERROR("udb_query_create: realloc failed");
status = -1;
} else {
query_list = temp;
if ((name == NULL) || (src_list == NULL) || (dst_list == NULL) ||
(dst_list_len == NULL)) {
- ERROR("db query utils: udb_query_pick_from_list_by_name: "
- "Invalid argument.");
+ P_ERROR("udb_query_pick_from_list_by_name: "
+ "Invalid argument.");
return -EINVAL;
}
tmp_list_len = *dst_list_len;
tmp_list = realloc(*dst_list, (tmp_list_len + 1) * sizeof(udb_query_t *));
if (tmp_list == NULL) {
- ERROR("db query utils: realloc failed.");
+ P_ERROR("udb_query_pick_from_list_by_name: realloc failed.");
return -ENOMEM;
}
} /* for (i = 0; i < src_list_len; i++) */
if (num_added <= 0) {
- ERROR("db query utils: Cannot find query `%s'. Make sure the <Query> "
- "block is above the database definition!",
- name);
+ P_ERROR("Cannot find query `%s'. Make sure the <Query> "
+ "block is above the database definition!",
+ name);
return -ENOENT;
} else {
- DEBUG("db query utils: Added %i versions of query `%s'.", num_added, name);
+ DEBUG("Added %i versions of query `%s'.", num_added, name);
}
return 0;
if ((ci == NULL) || (src_list == NULL) || (dst_list == NULL) ||
(dst_list_len == NULL)) {
- ERROR("db query utils: udb_query_pick_from_list: "
- "Invalid argument.");
+ P_ERROR("udb_query_pick_from_list: "
+ "Invalid argument.");
return -EINVAL;
}
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
- ERROR("db query utils: The `%s' config option "
- "needs exactly one string argument.",
- ci->key);
+ P_ERROR("The `%s' config option "
+ "needs exactly one string argument.",
+ ci->key);
return -1;
}
name = ci->values[0].value.string;
if ((prep_area->column_num < 1) || (prep_area->host == NULL) ||
(prep_area->plugin == NULL) || (prep_area->db_name == NULL)) {
- ERROR("db query utils: Query `%s': Query is not prepared; "
- "can't handle result.",
- q->name);
+ P_ERROR("Query `%s': Query is not prepared; "
+ "can't handle result.",
+ q->name);
return -EINVAL;
}
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG /* {{{ */
do {
for (size_t i = 0; i < prep_area->column_num; i++) {
- DEBUG("db query utils: udb_query_handle_result (%s, %s): "
+ DEBUG("udb_query_handle_result (%s, %s): "
"column[%" PRIsz "] = %s;",
prep_area->db_name, q->name, i, column_values[i]);
}
}
if (success == 0) {
- ERROR("db query utils: udb_query_handle_result (%s, %s): "
- "All results failed.",
- prep_area->db_name, q->name);
+ P_ERROR("udb_query_handle_result (%s, %s): "
+ "All results failed.",
+ prep_area->db_name, q->name);
return -1;
}
if ((prep_area->host == NULL) || (prep_area->plugin == NULL) ||
(prep_area->db_name == NULL)) {
- ERROR("db query utils: Query `%s': Prepare failed: Out of memory.",
- q->name);
+ P_ERROR("Query `%s': Prepare failed: Out of memory.", q->name);
udb_query_finish_result(q, prep_area);
return -ENOMEM;
}
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG
do {
for (size_t i = 0; i < column_num; i++) {
- DEBUG("db query utils: udb_query_prepare_result: "
+ DEBUG("udb_query_prepare_result: "
"query = %s; column[%" PRIsz "] = %s;",
q->name, i, column_names[i]);
}
}
if (i >= column_num) {
- ERROR("db query utils: udb_query_prepare_result: "
- "Column `%s' from `PluginInstanceFrom' could not be found.",
- q->plugin_instance_from);
+ P_ERROR("udb_query_prepare_result: "
+ "Column `%s' from `PluginInstanceFrom' could not be found.",
+ q->plugin_instance_from);
udb_query_finish_result(q, prep_area);
return -ENOENT;
}
for (r = q->results, r_area = prep_area->result_prep_areas; r != NULL;
r = r->next, r_area = r_area->next) {
if (!r_area) {
- ERROR("db query utils: Query `%s': Invalid number of result "
- "preparation areas.",
- q->name);
+ P_ERROR("Query `%s': Invalid number of result "
+ "preparation areas.",
+ q->name);
udb_query_finish_result(q, prep_area);
return -EINVAL;
}
else if (ds->ds[ds_num].type == DS_TYPE_ABSOLUTE)
BUFFER_ADD("%" PRIu64, vl->values[ds_num].absolute);
else {
- ERROR("gr_format_values plugin: Unknown data source type: %i",
- ds->ds[ds_num].type);
+ P_ERROR("gr_format_values: Unknown data source type: %i",
+ ds->ds[ds_num].type);
return -1;
}
if (flags & GRAPHITE_STORE_RATES) {
rates = uc_get_rate(ds, vl);
if (rates == NULL) {
- ERROR("format_graphite: error with uc_get_rate");
+ P_ERROR("format_graphite: error with uc_get_rate");
return -1;
}
}
status = gr_format_name(key, sizeof(key), vl, ds_name, prefix, postfix,
escape_char, flags);
if (status != 0) {
- ERROR("format_graphite: error with gr_format_name");
+ P_ERROR("format_graphite: error with gr_format_name");
sfree(rates);
return status;
}
* `values'. */
status = gr_format_values(values, sizeof(values), i, ds, vl, rates);
if (status != 0) {
- ERROR("format_graphite: error with gr_format_values");
+ P_ERROR("format_graphite: error with gr_format_values");
sfree(rates);
return status;
}
(size_t)snprintf(message, sizeof(message), "%s %s %u\r\n", key, values,
(unsigned int)CDTIME_T_TO_TIME_T(vl->time));
if (message_len >= sizeof(message)) {
- ERROR("format_graphite: message buffer too small: "
- "Need %" PRIsz " bytes.",
- message_len + 1);
+ P_ERROR("format_graphite: message buffer too small: "
+ "Need %" PRIsz " bytes.",
+ message_len + 1);
sfree(rates);
return -ENOMEM;
}
/* Append it in case we got multiple data set */
if ((buffer_pos + message_len) >= buffer_size) {
- ERROR("format_graphite: target buffer too small");
+ P_ERROR("format_graphite: target buffer too small");
sfree(rates);
return -ENOMEM;
}
args = calloc(1, sizeof(*args));
if (args == NULL) {
- ERROR("srrd_create_args_create: calloc failed.");
+ P_ERROR("srrd_create_args_create: calloc failed.");
return NULL;
}
args->filename = NULL;
args->filename = strdup(filename);
if (args->filename == NULL) {
- ERROR("srrd_create_args_create: strdup failed.");
+ P_ERROR("srrd_create_args_create: strdup failed.");
srrd_create_args_destroy(args);
return NULL;
}
args->argv = calloc((size_t)(argc + 1), sizeof(*args->argv));
if (args->argv == NULL) {
- ERROR("srrd_create_args_create: calloc failed.");
+ P_ERROR("srrd_create_args_create: calloc failed.");
srrd_create_args_destroy(args);
return NULL;
}
for (args->argc = 0; args->argc < argc; args->argc++) {
args->argv[args->argc] = strdup(argv[args->argc]);
if (args->argv[args->argc] == NULL) {
- ERROR("srrd_create_args_create: strdup failed.");
+ P_ERROR("srrd_create_args_create: strdup failed.");
srrd_create_args_destroy(args);
return NULL;
}
rra_types[j], cfg->xff, cdp_len, cdp_num);
if ((status < 0) || ((size_t)status >= sizeof(buffer))) {
- ERROR("rra_get: Buffer would have been truncated.");
+ P_ERROR("rra_get: Buffer would have been truncated.");
continue;
}
ds_def = calloc(ds->ds_num, sizeof(*ds_def));
if (ds_def == NULL) {
- ERROR("rrdtool plugin: calloc failed: %s", STRERRNO);
+ P_ERROR("ds_get: calloc failed: %s", STRERRNO);
return -1;
}
else if (d->type == DS_TYPE_ABSOLUTE)
type = "ABSOLUTE";
else {
- ERROR("rrdtool plugin: Unknown DS type: %i", d->type);
+ P_ERROR("ds_get: Unknown DS type: %i", d->type);
break;
}
status = rrd_create_r(filename_copy, pdp_step, last_up, argc, (void *)argv);
if (status != 0) {
- WARNING("rrdtool plugin: rrd_create_r (%s) failed: %s", filename,
- rrd_get_error());
+ P_WARNING("srrd_create: rrd_create_r (%s) failed: %s", filename,
+ rrd_get_error());
}
sfree(filename_copy);
new_argc = 6 + argc;
new_argv = malloc((new_argc + 1) * sizeof(*new_argv));
if (new_argv == NULL) {
- ERROR("rrdtool plugin: malloc failed.");
+ P_ERROR("srrd_create: malloc failed.");
return -1;
}
pthread_mutex_unlock(&librrd_lock);
if (status != 0) {
- WARNING("rrdtool plugin: rrd_create (%s) failed: %s", filename,
- rrd_get_error());
+ P_WARNING("srrd_create: rrd_create (%s) failed: %s", filename,
+ rrd_get_error());
}
sfree(new_argv);
status = lock_file(args->filename);
if (status != 0) {
if (status == EEXIST)
- NOTICE("srrd_create_thread: File \"%s\" is already being created.",
- args->filename);
+ P_NOTICE("srrd_create_thread: File \"%s\" is already being created.",
+ args->filename);
else
- ERROR("srrd_create_thread: Unable to lock file \"%s\".", args->filename);
+ P_ERROR("srrd_create_thread: Unable to lock file \"%s\".",
+ args->filename);
srrd_create_args_destroy(args);
return 0;
}
status = srrd_create(tmpfile, args->pdp_step, args->last_up, args->argc,
(void *)args->argv);
if (status != 0) {
- WARNING("srrd_create_thread: srrd_create (%s) returned status %i.",
- args->filename, status);
+ P_WARNING("srrd_create_thread: srrd_create (%s) returned status %i.",
+ args->filename, status);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
status = rename(tmpfile, args->filename);
if (status != 0) {
- ERROR("srrd_create_thread: rename (\"%s\", \"%s\") failed: %s", tmpfile,
- args->filename, STRERRNO);
+ P_ERROR("srrd_create_thread: rename (\"%s\", \"%s\") failed: %s", tmpfile,
+ args->filename, STRERRNO);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
status = pthread_create(&thread, &attr, srrd_create_thread, args);
if (status != 0) {
- ERROR("srrd_create_async: pthread_create failed: %s", STRERROR(status));
+ P_ERROR("srrd_create_async: pthread_create failed: %s", STRERROR(status));
pthread_attr_destroy(&attr);
srrd_create_args_destroy(args);
return status;
return -1;
if ((rra_num = rra_get(&rra_def, vl, cfg)) < 1) {
- ERROR("cu_rrd_create_file failed: Could not calculate RRAs");
+ P_ERROR("cu_rrd_create_file failed: Could not calculate RRAs");
return -1;
}
if ((ds_num = ds_get(&ds_def, ds, vl, cfg)) < 1) {
- ERROR("cu_rrd_create_file failed: Could not calculate DSes");
+ P_ERROR("cu_rrd_create_file failed: Could not calculate DSes");
rra_free(rra_num, rra_def);
return -1;
}
argc = ds_num + rra_num;
if ((argv = malloc(sizeof(*argv) * (argc + 1))) == NULL) {
- ERROR("cu_rrd_create_file failed: %s", STRERRNO);
+ P_ERROR("cu_rrd_create_file failed: %s", STRERRNO);
rra_free(rra_num, rra_def);
ds_free(ds_num, ds_def);
return -1;
status = srrd_create_async(filename, stepsize, last_up, argc,
(const char **)argv);
if (status != 0)
- WARNING("cu_rrd_create_file: srrd_create_async (%s) "
- "returned status %i.",
- filename, status);
+ P_WARNING("cu_rrd_create_file: srrd_create_async (%s) "
+ "returned status %i.",
+ filename, status);
} else /* synchronous */
{
status = lock_file(filename);
if (status != 0) {
if (status == EEXIST)
- NOTICE("cu_rrd_create_file: File \"%s\" is already being created.",
- filename);
+ P_NOTICE("cu_rrd_create_file: File \"%s\" is already being created.",
+ filename);
else
- ERROR("cu_rrd_create_file: Unable to lock file \"%s\".", filename);
+ P_ERROR("cu_rrd_create_file: Unable to lock file \"%s\".", filename);
} else {
status =
srrd_create(filename, stepsize, last_up, argc, (const char **)argv);
if (status != 0) {
- WARNING("cu_rrd_create_file: srrd_create (%s) returned status %i.",
- filename, status);
+ P_WARNING("cu_rrd_create_file: srrd_create (%s) returned status %i.",
+ filename, status);
} else {
DEBUG("cu_rrd_create_file: Successfully created RRD file \"%s\".",
filename);
} else if (strcasecmp("Port", child->key) == 0) {
host->port = cf_util_get_port_number(child);
if (host->port == -1) {
- ERROR("write_riemann plugin: Invalid argument "
- "configured for the \"Port\" "
- "option.");
break;
}
} else if (strcasecmp("Protocol", child->key) == 0) {
char tmp[16];
status = cf_util_get_string_buffer(child, tmp, sizeof(tmp));
- if (status != 0) {
- ERROR("write_riemann plugin: cf_util_get_"
- "string_buffer failed with "
- "status %i.",
- status);
+ if (status != 0)
break;
- }
if (strcasecmp("UDP", tmp) == 0)
host->client_type = RIEMANN_CLIENT_UDP;
tmp);
} else if (strcasecmp("TLSCAFile", child->key) == 0) {
status = cf_util_get_string(child, &host->tls_ca_file);
- if (status != 0) {
- ERROR("write_riemann plugin: cf_util_get_"
- "string_buffer failed with "
- "status %i.",
- status);
+ if (status != 0)
break;
- }
} else if (strcasecmp("TLSCertFile", child->key) == 0) {
status = cf_util_get_string(child, &host->tls_cert_file);
- if (status != 0) {
- ERROR("write_riemann plugin: cf_util_get_"
- "string_buffer failed with "
- "status %i.",
- status);
+ if (status != 0)
break;
- }
} else if (strcasecmp("TLSKeyFile", child->key) == 0) {
status = cf_util_get_string(child, &host->tls_key_file);
- if (status != 0) {
- ERROR("write_riemann plugin: cf_util_get_"
- "string_buffer failed with "
- "status %i.",
- status);
+ if (status != 0)
break;
- }
} else if (strcasecmp("StoreRates", child->key) == 0) {
status = cf_util_get_boolean(child, &host->store_rates);
if (status != 0)
break;
} else if (strcasecmp("Port", child->key) == 0) {
status = cf_util_get_service(child, &host->service);
- if (status != 0) {
- ERROR("write_sensu plugin: Invalid argument "
- "configured for the \"Port\" "
- "option.");
+ if (status != 0)
break;
- }
} else if (strcasecmp("StoreRates", child->key) == 0) {
status = cf_util_get_boolean(child, &host->store_rates);
if (status != 0)