Merge branch 'collectd-4.2'
[collectd.git] / src / utils_threshold.c
index d7792f7..ecdbfbe 100644 (file)
@@ -50,7 +50,7 @@ typedef struct threshold_s
 /*
  * Private (static) variables
  * {{{ */
-static avl_tree_t     *threshold_tree = NULL;
+static c_avl_tree_t   *threshold_tree = NULL;
 static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
 /* }}} */
 
@@ -94,12 +94,12 @@ static int ut_threshold_add (const threshold_t *th)
   DEBUG ("ut_threshold_add: Adding entry `%s'", name);
 
   pthread_mutex_lock (&threshold_lock);
-  status = avl_insert (threshold_tree, name_copy, th_copy);
+  status = c_avl_insert (threshold_tree, name_copy, th_copy);
   pthread_mutex_unlock (&threshold_lock);
 
   if (status != 0)
   {
-    ERROR ("ut_threshold_add: avl_insert (%s) failed.", name);
+    ERROR ("ut_threshold_add: c_avl_insert (%s) failed.", name);
     sfree (name_copy);
     sfree (th_copy);
   }
@@ -181,6 +181,24 @@ static int ut_config_type_invert (threshold_t *th, oconfig_item_t *ci)
   return (0);
 } /* int ut_config_type_invert */
 
+static int ut_config_type_persist (threshold_t *th, oconfig_item_t *ci)
+{
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+  {
+    WARNING ("threshold values: The `Persist' option needs exactly one "
+       "boolean argument.");
+    return (-1);
+  }
+
+  if (ci->values[0].value.boolean)
+    th->flags |= UT_FLAG_PERSIST;
+  else
+    th->flags &= ~UT_FLAG_PERSIST;
+
+  return (0);
+} /* int ut_config_type_persist */
+
 static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
 {
   int i;
@@ -221,6 +239,8 @@ static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
       status = ut_config_type_min (&th, option);
     else if (strcasecmp ("Invert", option->key) == 0)
       status = ut_config_type_invert (&th, option);
+    else if (strcasecmp ("Persist", option->key) == 0)
+      status = ut_config_type_persist (&th, option);
     else
     {
       WARNING ("threshold values: Option `%s' not allowed inside a `Type' "
@@ -362,10 +382,10 @@ int ut_config (const oconfig_item_t *ci)
 
   if (threshold_tree == NULL)
   {
-    threshold_tree = avl_create ((void *) strcmp);
+    threshold_tree = c_avl_create ((void *) strcmp);
     if (threshold_tree == NULL)
     {
-      ERROR ("ut_config: avl_create failed.");
+      ERROR ("ut_config: c_avl_create failed.");
       return (-1);
     }
   }
@@ -415,7 +435,7 @@ static threshold_t *threshold_get (const char *hostname,
       (type == NULL) ? "" : type, type_instance);
   name[sizeof (name) - 1] = '\0';
 
-  if (avl_get (threshold_tree, name, (void *) &th) == 0)
+  if (c_avl_get (threshold_tree, name, (void *) &th) == 0)
     return (th);
   else
     return (NULL);
@@ -637,10 +657,11 @@ int ut_check_interesting (const char *name)
   host = plugin = plugin_instance = type = type_instance = NULL;
 
   th = threshold_search (&ds, &vl);
-  if (th != NULL)
-    return (1);
-  else
+  if (th == NULL)
     return (0);
+  if ((th->flags & UT_FLAG_PERSIST) == 0)
+    return (1);
+  return (2);
 } /* int ut_check_interesting */
 
 /* vim: set sw=2 ts=8 sts=2 tw=78 fdm=marker : */