- * Configuration
- * =============
- * 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)
-{
- int i;
- threshold_t th;
- int status = 0;
-
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("threshold values: The `Type' block needs exactly one string "
- "argument.");
- return (-1);
- }
-
- if (ci->children_num < 1)
- {
- WARNING ("threshold values: The `Type' block needs at least one option.");
- return (-1);
- }
-
- memcpy (&th, th_orig, sizeof (th));
- sstrncpy (th.type, ci->values[0].value.string, sizeof (th.type));
-
- th.warning_min = NAN;
- th.warning_max = NAN;
- th.failure_min = NAN;
- th.failure_max = NAN;
- th.hits = 0;
- th.hysteresis = 0;
- th.flags = UT_FLAG_INTERESTING; /* interesting by default */
-
- for (i = 0; i < ci->children_num; i++)
- {
- oconfig_item_t *option = ci->children + i;
- status = 0;
-
- if (strcasecmp ("Instance", option->key) == 0)
- status = ut_config_type_instance (&th, option);
- 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);
- 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)
- status = cf_util_get_flag (option, &th.flags, UT_FLAG_INVERT);
- else if (strcasecmp ("Persist", option->key) == 0)
- status = cf_util_get_flag (option, &th.flags, UT_FLAG_PERSIST);
- else if (strcasecmp ("PersistOK", option->key) == 0)
- status = cf_util_get_flag (option, &th.flags, UT_FLAG_PERSIST_OK);
- 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);
- else if (strcasecmp ("Hysteresis", option->key) == 0)
- status = ut_config_type_hysteresis (&th, option);
- else
- {
- WARNING ("threshold values: Option `%s' not allowed inside a `Type' "
- "block.", option->key);
- status = -1;
- }
-
- if (status != 0)
- break;
- }
-
- if (status == 0)
- {
- status = ut_threshold_add (&th);
- }
-
- 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)
-{
- int i;
- 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 (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 ("Instance", option->key) == 0)
- status = ut_config_plugin_instance (&th, option);
- 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 */
-
-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 */
-/*
- * End of the functions used to configure threshold values.
- */
-/* }}} */
-
-/*