int ut_config (const oconfig_item_t *ci) { int i; int status = 0; threshold_t th; if (ci->values_num != 0) { ERROR ("threshold values: The `Threshold' block may not have any " "arguments."); return (-1); } if (threshold_tree == NULL) { threshold_tree = c_avl_create ((void *) strcmp); if (threshold_tree == NULL) { ERROR ("ut_config: c_avl_create failed."); return (-1); } } memset (&th, '\0', sizeof (th)); th.warning_min = NAN; th.warning_max = NAN; th.failure_min = NAN; th.failure_max = NAN; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; status = 0; if (strcasecmp ("Type", option->key) == 0) status = ut_config_type (&th, option); else if (strcasecmp ("Plugin", option->key) == 0) status = ut_config_plugin (&th, option); else if (strcasecmp ("Host", option->key) == 0) status = ut_config_host (&th, option); else { WARNING ("threshold values: Option `%s' not allowed here.", option->key); status = -1; } if (status != 0) break; } return (status); } /* int um_config */
static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) { int i; threshold_t th; int status = 0; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("threshold values: The `Host' block needs exactly one string " "argument."); return (-1); } if (ci->children_num < 1) { WARNING ("threshold values: The `Host' block needs at least one nested " "block."); return (-1); } memcpy (&th, th_orig, sizeof (th)); sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host)); for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; status = 0; if (strcasecmp ("Type", option->key) == 0) status = ut_config_type (&th, option); else if (strcasecmp ("Plugin", option->key) == 0) status = ut_config_plugin (&th, option); else { WARNING ("threshold values: Option `%s' not allowed inside a `Host' " "block.", option->key); status = -1; } if (status != 0) break; } return (status); } /* int ut_config_host */
static int ut_config_plugin(const threshold_t *th_orig, oconfig_item_t *ci) { threshold_t th; int status = 0; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("threshold values: The `Plugin' block needs exactly one string " "argument."); return -1; } if (ci->children_num < 1) { WARNING("threshold values: The `Plugin' block needs at least one nested " "block."); return -1; } memcpy(&th, th_orig, sizeof(th)); sstrncpy(th.plugin, ci->values[0].value.string, sizeof(th.plugin)); for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; if (strcasecmp("Type", option->key) == 0) status = ut_config_type(&th, option); else if (strcasecmp("Instance", option->key) == 0) 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.", option->key); status = -1; } if (status != 0) break; } return status; } /* int ut_config_plugin */