Merge branch 'pull/collectd-4.3' into collectd-4.3
authorFlorian Forster <octo@huhu.verplant.org>
Tue, 18 Mar 2008 09:19:43 +0000 (10:19 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 18 Mar 2008 09:19:43 +0000 (10:19 +0100)
1  2 
src/utils_threshold.c

@@@ -536,90 -548,107 +548,111 @@@ int ut_check_threshold (const data_set_
      int is_failure = 0;
  
      if ((th->flags & UT_FLAG_INVERT) != 0)
 +    {
        is_inverted = 1;
 +      is_warning--;
 +      is_failure--;
 +    }
      if ((!isnan (th->failure_min) && (th->failure_min > values[i]))
        || (!isnan (th->failure_max) && (th->failure_max < values[i])))
 -      is_failure = is_inverted - 1;
 +      is_failure++;
      if ((!isnan (th->warning_min) && (th->warning_min > values[i]))
        || (!isnan (th->warning_max) && (th->warning_max < values[i])))
 -      is_warning = is_inverted - 1;
 +      is_warning++;
  
-     if ((is_failure != 0) || (is_warning != 0))
+     if ((is_failure != 0) && (state_new != STATE_ERROR))
      {
-       notification_t n;
-       char *buf;
-       size_t bufsize;
-       int status;
+       state_new = STATE_ERROR;
+       ds_index = i;
+     }
+     else if ((is_warning != 0)
+       && (state_new != STATE_ERROR)
+       && (state_new != STATE_WARNING))
+     {
+       state_new = STATE_WARNING;
+       ds_index = i;
+     }
+   }
  
-       double min;
-       double max;
+   if (state_new != state_orig)
+     uc_set_state (ds, vl, state_new);
  
-       min = (is_failure != 0) ? th->failure_min : th->warning_min;
-       max = (is_failure != 0) ? th->failure_max : th->warning_max;
+   /* Return here if we're not going to send a notification */
+   if ((state_new == state_orig)
+       && ((state_new == STATE_OKAY)
+       || ((th->flags & UT_FLAG_PERSIST) == 0)))
+   {
+     sfree (values);
+     return (0);
+   }
  
-       DEBUG ("ut_check_threshold: ds[%s]: %lf <= !%lf <= %lf (invert: %s)",
-         ds->ds[i].name, min, values[i], max,
-         is_inverted ? "true" : "false");
+   NOTIFICATION_INIT_VL (&n, vl, ds);
+   {
+     /* Copy the associative members */
+     if (state_new == STATE_OKAY)
+       n.severity = NOTIF_OKAY;
+     else if (state_new == STATE_WARNING)
+       n.severity = NOTIF_WARNING;
+     else
+       n.severity = NOTIF_FAILURE;
  
-       /* Copy the associative members */
-       NOTIFICATION_INIT_VL (&n, vl, ds);
+     n.time = vl->time;
  
-       n.severity = (is_failure != 0) ? NOTIF_FAILURE : NOTIF_WARNING;
-       n.time = vl->time;
+     buf = n.message;
+     bufsize = sizeof (n.message);
  
-       buf = n.message;
-       bufsize = sizeof (n.message);
+     status = snprintf (buf, bufsize, "Host %s, plugin %s",
+       vl->host, vl->plugin);
+     buf += status;
+     bufsize -= status;
  
-       status = snprintf (buf, bufsize, "Host %s, plugin %s",
-         vl->host, vl->plugin);
+     if (vl->plugin_instance[0] != '\0')
+     {
+       status = snprintf (buf, bufsize, " (instance %s)",
+         vl->plugin_instance);
        buf += status;
        bufsize -= status;
+     }
  
-       if (vl->plugin_instance[0] != '\0')
-       {
-       status = snprintf (buf, bufsize, " (instance %s)",
-           vl->plugin_instance);
-       buf += status;
-       bufsize -= status;
-       }
+     status = snprintf (buf, bufsize, " type %s", ds->type);
+     buf += status;
+     bufsize -= status;
  
-       status = snprintf (buf, bufsize, " type %s", ds->type);
+     if (vl->type_instance[0] != '\0')
+     {
+       status = snprintf (buf, bufsize, " (instance %s)",
+         vl->type_instance);
        buf += status;
        bufsize -= status;
+     }
+   }
  
-       if (vl->type_instance[0] != '\0')
-       {
-       status = snprintf (buf, bufsize, " (instance %s)",
-           vl->type_instance);
-       buf += status;
-       bufsize -= status;
-       }
+   /* Send a okay notification */
+   if (state_new == STATE_OKAY)
+   {
+     status = snprintf (buf, bufsize, ": All data sources are within range again.");
+     buf += status;
+     bufsize -= status;
+   }
+   else
+   {
+     double min;
+     double max;
+     min = (state_new == STATE_ERROR) ? th->failure_min : th->warning_min;
+     max = (state_new == STATE_ERROR) ? th->failure_max : th->warning_max;
  
-       if (is_inverted)
+     if (th->flags & UT_FLAG_INVERT)
+     {
+       if (!isnan (min) && !isnan (max))
        {
-       if (!isnan (min) && !isnan (max))
-       {
-         status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
-             "%f. That is within the %s region of %f and %f.",
-             ds->ds[i].name, values[i],
-             (is_failure != 0) ? "failure" : "warning",
-             min, min);
-       }
-       else
-       {
-         status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
-             "%f. That is %s the %s threshold of %f.",
-             ds->ds[i].name, values[i],
-             isnan (min) ? "below" : "above",
-             (is_failure != 0) ? "failure" : "warning",
-             isnan (min) ? max : min);
-       }
+       status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
+           "%f. That is within the %s region of %f and %f.",
+           ds->ds[ds_index].name, values[ds_index],
+           (state_new == STATE_ERROR) ? "failure" : "warning",
+           min, min);
        }
-       else /* (!is_inverted) */
+       else
        {
        status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
            "%f. That is %s the %s threshold of %f.",