From f093ce8b64e8641e4fec31478f121958f9ebe6f6 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 5 Sep 2009 16:36:12 +0200 Subject: [PATCH] src/utils_threshold.[ch]: Implement `ut_search_threshold'. It allows external modules to query the threshold for a specific `value_list_t'. --- src/utils_threshold.c | 37 +++++++++++++++++++------------------ src/utils_threshold.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/utils_threshold.c b/src/utils_threshold.c index 5e98e699..2cf0b677 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -24,6 +24,7 @@ #include "plugin.h" #include "utils_avltree.h" #include "utils_cache.h" +#include "utils_threshold.h" #include #include @@ -34,24 +35,6 @@ #define UT_FLAG_INVERT 0x01 #define UT_FLAG_PERSIST 0x02 #define UT_FLAG_PERCENTAGE 0x04 - -typedef struct threshold_s -{ - char host[DATA_MAX_NAME_LEN]; - char plugin[DATA_MAX_NAME_LEN]; - char plugin_instance[DATA_MAX_NAME_LEN]; - char type[DATA_MAX_NAME_LEN]; - char type_instance[DATA_MAX_NAME_LEN]; - char data_source[DATA_MAX_NAME_LEN]; - gauge_t warning_min; - gauge_t warning_max; - gauge_t failure_min; - gauge_t failure_max; - gauge_t hysteresis; - int flags; - int hits; - struct threshold_s *next; -} threshold_t; /* }}} */ /* @@ -1045,4 +1028,22 @@ int ut_check_interesting (const char *name) return (2); } /* }}} int ut_check_interesting */ +int ut_search_threshold (const value_list_t *vl, /* {{{ */ + threshold_t *ret_threshold) +{ + threshold_t *t; + + if (vl == NULL) + return (EINVAL); + + t = threshold_search (vl); + if (t == NULL) + return (ENOENT); + + memcpy (ret_threshold, t, sizeof (*ret_threshold)); + ret_threshold->next = NULL; + + return (0); +} /* }}} int ut_search_threshold */ + /* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */ diff --git a/src/utils_threshold.h b/src/utils_threshold.h index a42c4121..369754dd 100644 --- a/src/utils_threshold.h +++ b/src/utils_threshold.h @@ -26,6 +26,24 @@ #include "liboconfig/oconfig.h" #include "plugin.h" +typedef struct threshold_s +{ + char host[DATA_MAX_NAME_LEN]; + char plugin[DATA_MAX_NAME_LEN]; + char plugin_instance[DATA_MAX_NAME_LEN]; + char type[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN]; + char data_source[DATA_MAX_NAME_LEN]; + gauge_t warning_min; + gauge_t warning_max; + gauge_t failure_min; + gauge_t failure_max; + gauge_t hysteresis; + int flags; + int hits; + struct threshold_s *next; +} threshold_t; + /* * ut_config * @@ -54,4 +72,16 @@ int ut_check_threshold (const data_set_t *ds, const value_list_t *vl); */ int ut_check_interesting (const char *name); +/* + * Given an identifier in form of a `value_list_t', searches for the best + * matching threshold configuration. `ret_threshold' may be NULL. + * + * Returns: + * 0: Success. Threshold configuration has been copied to + * `ret_threshold' (if it is non-NULL). + * ENOENT: No configuration for this identifier found. + * else: Error. + */ +int ut_search_threshold (const value_list_t *vl, threshold_t *ret_threshold); + #endif /* UTILS_THRESHOLD_H */ -- 2.11.0