2 * collectd - src/threshold.c
3 * Copyright (C) 2007-2010 Florian Forster
4 * Copyright (C) 2008-2009 Sebastian Harl
5 * Copyright (C) 2009 Andrés J. Díaz
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; only version 2 of the License is applicable.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Florian octo Forster <octo at collectd.org>
22 * Sebastian Harl <sh at tokkee.org>
23 * Andrés J. Díaz <ajdiaz at connectical.com>
29 #include "utils_avltree.h"
30 #include "utils_cache.h"
36 * Private data structures
38 #define UT_FLAG_INVERT 0x01
39 #define UT_FLAG_PERSIST 0x02
40 #define UT_FLAG_PERCENTAGE 0x04
41 #define UT_FLAG_INTERESTING 0x08
42 typedef struct threshold_s
44 char host[DATA_MAX_NAME_LEN];
45 char plugin[DATA_MAX_NAME_LEN];
46 char plugin_instance[DATA_MAX_NAME_LEN];
47 char type[DATA_MAX_NAME_LEN];
48 char type_instance[DATA_MAX_NAME_LEN];
49 char data_source[DATA_MAX_NAME_LEN];
57 struct threshold_s *next;
62 * Private (static) variables
64 static c_avl_tree_t *threshold_tree = NULL;
65 static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
69 * Threshold management
70 * ====================
71 * The following functions add, delete, search, etc. configured thresholds to
72 * the underlying AVL trees.
75 * threshold_t *threshold_get
77 * Retrieve one specific threshold configuration. For looking up a threshold
78 * matching a value_list_t, see "threshold_search" below. Returns NULL if the
79 * specified threshold doesn't exist.
81 static threshold_t *threshold_get (const char *hostname,
82 const char *plugin, const char *plugin_instance,
83 const char *type, const char *type_instance)
85 char name[6 * DATA_MAX_NAME_LEN];
86 threshold_t *th = NULL;
88 format_name (name, sizeof (name),
89 (hostname == NULL) ? "" : hostname,
90 (plugin == NULL) ? "" : plugin, plugin_instance,
91 (type == NULL) ? "" : type, type_instance);
92 name[sizeof (name) - 1] = '\0';
94 if (c_avl_get (threshold_tree, name, (void *) &th) == 0)
98 } /* }}} threshold_t *threshold_get */
101 * int ut_threshold_add
103 * Adds a threshold configuration to the list of thresholds. The threshold_t
104 * structure is copied and may be destroyed after this call. Returns zero on
105 * success, non-zero otherwise.
107 static int ut_threshold_add (const threshold_t *th)
109 char name[6 * DATA_MAX_NAME_LEN];
111 threshold_t *th_copy;
115 if (format_name (name, sizeof (name), th->host,
116 th->plugin, th->plugin_instance,
117 th->type, th->type_instance) != 0)
119 ERROR ("ut_threshold_add: format_name failed.");
123 name_copy = strdup (name);
124 if (name_copy == NULL)
126 ERROR ("ut_threshold_add: strdup failed.");
130 th_copy = (threshold_t *) malloc (sizeof (threshold_t));
134 ERROR ("ut_threshold_add: malloc failed.");
137 memcpy (th_copy, th, sizeof (threshold_t));
140 DEBUG ("ut_threshold_add: Adding entry `%s'", name);
142 pthread_mutex_lock (&threshold_lock);
144 th_ptr = threshold_get (th->host, th->plugin, th->plugin_instance,
145 th->type, th->type_instance);
147 while ((th_ptr != NULL) && (th_ptr->next != NULL))
148 th_ptr = th_ptr->next;
150 if (th_ptr == NULL) /* no such threshold yet */
152 status = c_avl_insert (threshold_tree, name_copy, th_copy);
154 else /* th_ptr points to the last threshold in the list */
156 th_ptr->next = th_copy;
157 /* name_copy isn't needed */
161 pthread_mutex_unlock (&threshold_lock);
165 ERROR ("ut_threshold_add: c_avl_insert (%s) failed.", name);
171 } /* }}} int ut_threshold_add */
174 * threshold_t *threshold_search
176 * Searches for a threshold configuration using all the possible variations of
177 * "Host", "Plugin" and "Type" blocks. Returns NULL if no threshold could be
179 * XXX: This is likely the least efficient function in collectd.
181 static threshold_t *threshold_search (const value_list_t *vl)
185 if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
186 vl->type, vl->type_instance)) != NULL)
188 else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
189 vl->type, NULL)) != NULL)
191 else if ((th = threshold_get (vl->host, vl->plugin, NULL,
192 vl->type, vl->type_instance)) != NULL)
194 else if ((th = threshold_get (vl->host, vl->plugin, NULL,
195 vl->type, NULL)) != NULL)
197 else if ((th = threshold_get (vl->host, "", NULL,
198 vl->type, vl->type_instance)) != NULL)
200 else if ((th = threshold_get (vl->host, "", NULL,
201 vl->type, NULL)) != NULL)
203 else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
204 vl->type, vl->type_instance)) != NULL)
206 else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
207 vl->type, NULL)) != NULL)
209 else if ((th = threshold_get ("", vl->plugin, NULL,
210 vl->type, vl->type_instance)) != NULL)
212 else if ((th = threshold_get ("", vl->plugin, NULL,
213 vl->type, NULL)) != NULL)
215 else if ((th = threshold_get ("", "", NULL,
216 vl->type, vl->type_instance)) != NULL)
218 else if ((th = threshold_get ("", "", NULL,
219 vl->type, NULL)) != NULL)
223 } /* }}} threshold_t *threshold_search */
228 * The following approximately two hundred functions are used to handle the
229 * configuration and fill the threshold list.
231 static int ut_config_type_datasource (threshold_t *th, oconfig_item_t *ci)
233 if ((ci->values_num != 1)
234 || (ci->values[0].type != OCONFIG_TYPE_STRING))
236 WARNING ("threshold values: The `DataSource' option needs exactly one "
241 sstrncpy (th->data_source, ci->values[0].value.string,
242 sizeof (th->data_source));
245 } /* int ut_config_type_datasource */
247 static int ut_config_type_instance (threshold_t *th, oconfig_item_t *ci)
249 if ((ci->values_num != 1)
250 || (ci->values[0].type != OCONFIG_TYPE_STRING))
252 WARNING ("threshold values: The `Instance' option needs exactly one "
257 sstrncpy (th->type_instance, ci->values[0].value.string,
258 sizeof (th->type_instance));
261 } /* int ut_config_type_instance */
263 static int ut_config_type_max (threshold_t *th, oconfig_item_t *ci)
265 if ((ci->values_num != 1)
266 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
268 WARNING ("threshold values: The `%s' option needs exactly one "
269 "number argument.", ci->key);
273 if (strcasecmp (ci->key, "WarningMax") == 0)
274 th->warning_max = ci->values[0].value.number;
276 th->failure_max = ci->values[0].value.number;
279 } /* int ut_config_type_max */
281 static int ut_config_type_min (threshold_t *th, oconfig_item_t *ci)
283 if ((ci->values_num != 1)
284 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
286 WARNING ("threshold values: The `%s' option needs exactly one "
287 "number argument.", ci->key);
291 if (strcasecmp (ci->key, "WarningMin") == 0)
292 th->warning_min = ci->values[0].value.number;
294 th->failure_min = ci->values[0].value.number;
297 } /* int ut_config_type_min */
299 static int ut_config_type_hits (threshold_t *th, oconfig_item_t *ci)
301 if ((ci->values_num != 1)
302 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
304 WARNING ("threshold values: The `%s' option needs exactly one "
305 "number argument.", ci->key);
309 th->hits = ci->values[0].value.number;
312 } /* int ut_config_type_hits */
314 static int ut_config_type_hysteresis (threshold_t *th, oconfig_item_t *ci)
316 if ((ci->values_num != 1)
317 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
319 WARNING ("threshold values: The `%s' option needs exactly one "
320 "number argument.", ci->key);
324 th->hysteresis = ci->values[0].value.number;
327 } /* int ut_config_type_hysteresis */
329 static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
335 if ((ci->values_num != 1)
336 || (ci->values[0].type != OCONFIG_TYPE_STRING))
338 WARNING ("threshold values: The `Type' block needs exactly one string "
343 if (ci->children_num < 1)
345 WARNING ("threshold values: The `Type' block needs at least one option.");
349 memcpy (&th, th_orig, sizeof (th));
350 sstrncpy (th.type, ci->values[0].value.string, sizeof (th.type));
352 th.warning_min = NAN;
353 th.warning_max = NAN;
354 th.failure_min = NAN;
355 th.failure_max = NAN;
358 th.flags = UT_FLAG_INTERESTING; /* interesting by default */
360 for (i = 0; i < ci->children_num; i++)
362 oconfig_item_t *option = ci->children + i;
365 if (strcasecmp ("Instance", option->key) == 0)
366 status = ut_config_type_instance (&th, option);
367 else if (strcasecmp ("DataSource", option->key) == 0)
368 status = ut_config_type_datasource (&th, option);
369 else if ((strcasecmp ("WarningMax", option->key) == 0)
370 || (strcasecmp ("FailureMax", option->key) == 0))
371 status = ut_config_type_max (&th, option);
372 else if ((strcasecmp ("WarningMin", option->key) == 0)
373 || (strcasecmp ("FailureMin", option->key) == 0))
374 status = ut_config_type_min (&th, option);
375 else if (strcasecmp ("Interesting", option->key) == 0)
376 status = cf_util_get_flag (option, &th.flags, UT_FLAG_INTERESTING);
377 else if (strcasecmp ("Invert", option->key) == 0)
378 status = cf_util_get_flag (option, &th.flags, UT_FLAG_INVERT);
379 else if (strcasecmp ("Persist", option->key) == 0)
380 status = cf_util_get_flag (option, &th.flags, UT_FLAG_PERSIST);
381 else if (strcasecmp ("Percentage", option->key) == 0)
382 status = cf_util_get_flag (option, &th.flags, UT_FLAG_PERCENTAGE);
383 else if (strcasecmp ("Hits", option->key) == 0)
384 status = ut_config_type_hits (&th, option);
385 else if (strcasecmp ("Hysteresis", option->key) == 0)
386 status = ut_config_type_hysteresis (&th, option);
389 WARNING ("threshold values: Option `%s' not allowed inside a `Type' "
390 "block.", option->key);
400 status = ut_threshold_add (&th);
404 } /* int ut_config_type */
406 static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci)
408 if ((ci->values_num != 1)
409 || (ci->values[0].type != OCONFIG_TYPE_STRING))
411 WARNING ("threshold values: The `Instance' option needs exactly one "
416 sstrncpy (th->plugin_instance, ci->values[0].value.string,
417 sizeof (th->plugin_instance));
420 } /* int ut_config_plugin_instance */
422 static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
428 if ((ci->values_num != 1)
429 || (ci->values[0].type != OCONFIG_TYPE_STRING))
431 WARNING ("threshold values: The `Plugin' block needs exactly one string "
436 if (ci->children_num < 1)
438 WARNING ("threshold values: The `Plugin' block needs at least one nested "
443 memcpy (&th, th_orig, sizeof (th));
444 sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
446 for (i = 0; i < ci->children_num; i++)
448 oconfig_item_t *option = ci->children + i;
451 if (strcasecmp ("Type", option->key) == 0)
452 status = ut_config_type (&th, option);
453 else if (strcasecmp ("Instance", option->key) == 0)
454 status = ut_config_plugin_instance (&th, option);
457 WARNING ("threshold values: Option `%s' not allowed inside a `Plugin' "
458 "block.", option->key);
467 } /* int ut_config_plugin */
469 static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
475 if ((ci->values_num != 1)
476 || (ci->values[0].type != OCONFIG_TYPE_STRING))
478 WARNING ("threshold values: The `Host' block needs exactly one string "
483 if (ci->children_num < 1)
485 WARNING ("threshold values: The `Host' block needs at least one nested "
490 memcpy (&th, th_orig, sizeof (th));
491 sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host));
493 for (i = 0; i < ci->children_num; i++)
495 oconfig_item_t *option = ci->children + i;
498 if (strcasecmp ("Type", option->key) == 0)
499 status = ut_config_type (&th, option);
500 else if (strcasecmp ("Plugin", option->key) == 0)
501 status = ut_config_plugin (&th, option);
504 WARNING ("threshold values: Option `%s' not allowed inside a `Host' "
505 "block.", option->key);
514 } /* int ut_config_host */
516 int ut_config (oconfig_item_t *ci)
523 if (threshold_tree == NULL)
525 threshold_tree = c_avl_create ((void *) strcmp);
526 if (threshold_tree == NULL)
528 ERROR ("ut_config: c_avl_create failed.");
533 memset (&th, '\0', sizeof (th));
534 th.warning_min = NAN;
535 th.warning_max = NAN;
536 th.failure_min = NAN;
537 th.failure_max = NAN;
541 th.flags = UT_FLAG_INTERESTING; /* interesting by default */
543 for (i = 0; i < ci->children_num; i++)
545 oconfig_item_t *option = ci->children + i;
548 if (strcasecmp ("Type", option->key) == 0)
549 status = ut_config_type (&th, option);
550 else if (strcasecmp ("Plugin", option->key) == 0)
551 status = ut_config_plugin (&th, option);
552 else if (strcasecmp ("Host", option->key) == 0)
553 status = ut_config_host (&th, option);
556 WARNING ("threshold values: Option `%s' not allowed here.", option->key);
565 } /* int um_config */
567 * End of the functions used to configure threshold values.
572 * int ut_report_state
574 * Checks if the `state' differs from the old state and creates a notification
578 static int ut_report_state (const data_set_t *ds,
579 const value_list_t *vl,
580 const threshold_t *th,
581 const gauge_t *values,
593 /* Check if hits matched */
594 if ( (th->hits != 0) )
596 int hits = uc_get_hits(ds,vl);
597 /* The STATE_OKAY always reset hits, or if hits reaise the limit */
598 if ( (state == STATE_OKAY) || (hits > th->hits) )
600 DEBUG("ut_report_state: reset uc_get_hits = 0");
601 uc_set_hits(ds,vl,0); /* reset hit counter and notify */
603 DEBUG("ut_report_state: th->hits = %d, uc_get_hits = %d",th->hits,uc_get_hits(ds,vl));
604 (void) uc_inc_hits(ds,vl,1); /* increase hit counter */
607 } /* end check hits */
609 state_old = uc_get_state (ds, vl);
611 /* If the state didn't change, only report if `persistent' is specified and
612 * the state is not `okay'. */
613 if (state == state_old)
615 if ((th->flags & UT_FLAG_PERSIST) == 0)
617 else if (state == STATE_OKAY)
621 if (state != state_old)
622 uc_set_state (ds, vl, state);
624 NOTIFICATION_INIT_VL (&n, vl);
627 bufsize = sizeof (n.message);
629 if (state == STATE_OKAY)
630 n.severity = NOTIF_OKAY;
631 else if (state == STATE_WARNING)
632 n.severity = NOTIF_WARNING;
634 n.severity = NOTIF_FAILURE;
638 status = ssnprintf (buf, bufsize, "Host %s, plugin %s",
639 vl->host, vl->plugin);
643 if (vl->plugin_instance[0] != '\0')
645 status = ssnprintf (buf, bufsize, " (instance %s)",
646 vl->plugin_instance);
651 status = ssnprintf (buf, bufsize, " type %s", vl->type);
655 if (vl->type_instance[0] != '\0')
657 status = ssnprintf (buf, bufsize, " (instance %s)",
663 plugin_notification_meta_add_string (&n, "DataSource",
664 ds->ds[ds_index].name);
665 plugin_notification_meta_add_double (&n, "CurrentValue", values[ds_index]);
666 plugin_notification_meta_add_double (&n, "WarningMin", th->warning_min);
667 plugin_notification_meta_add_double (&n, "WarningMax", th->warning_max);
668 plugin_notification_meta_add_double (&n, "FailureMin", th->failure_min);
669 plugin_notification_meta_add_double (&n, "FailureMax", th->failure_max);
671 /* Send an okay notification */
672 if (state == STATE_OKAY)
674 if (state_old == STATE_MISSING)
675 status = ssnprintf (buf, bufsize,
676 ": Value is no longer missing.");
678 status = ssnprintf (buf, bufsize,
679 ": All data sources are within range again.");
688 min = (state == STATE_ERROR) ? th->failure_min : th->warning_min;
689 max = (state == STATE_ERROR) ? th->failure_max : th->warning_max;
691 if (th->flags & UT_FLAG_INVERT)
693 if (!isnan (min) && !isnan (max))
695 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
696 "%f. That is within the %s region of %f%s and %f%s.",
697 ds->ds[ds_index].name, values[ds_index],
698 (state == STATE_ERROR) ? "failure" : "warning",
699 min, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "",
700 max, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
704 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
705 "%f. That is %s the %s threshold of %f%s.",
706 ds->ds[ds_index].name, values[ds_index],
707 isnan (min) ? "below" : "above",
708 (state == STATE_ERROR) ? "failure" : "warning",
709 isnan (min) ? max : min,
710 ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
713 else if (th->flags & UT_FLAG_PERCENTAGE)
720 for (i = 0; i < vl->values_len; i++)
722 if (isnan (values[i]))
731 value = 100.0 * values[ds_index] / sum;
733 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
734 "%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
735 ds->ds[ds_index].name, values[ds_index], value,
736 (value < min) ? "below" : "above",
737 (state == STATE_ERROR) ? "failure" : "warning",
738 (value < min) ? min : max);
740 else /* is not inverted */
742 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
743 "%f. That is %s the %s threshold of %f.",
744 ds->ds[ds_index].name, values[ds_index],
745 (values[ds_index] < min) ? "below" : "above",
746 (state == STATE_ERROR) ? "failure" : "warning",
747 (values[ds_index] < min) ? min : max);
753 plugin_dispatch_notification (&n);
755 plugin_notification_meta_free (n.meta);
757 } /* }}} int ut_report_state */
760 * int ut_check_one_data_source
762 * Checks one data source against the given threshold configuration. If the
763 * `DataSource' option is set in the threshold, and the name does NOT match,
764 * `okay' is returned. If the threshold does match, its failure and warning
765 * min and max values are checked and `failure' or `warning' is returned if
769 static int ut_check_one_data_source (const data_set_t *ds,
770 const value_list_t __attribute__((unused)) *vl,
771 const threshold_t *th,
772 const gauge_t *values,
778 int prev_state = STATE_OKAY;
780 /* check if this threshold applies to this data source */
783 ds_name = ds->ds[ds_index].name;
784 if ((th->data_source[0] != 0)
785 && (strcmp (ds_name, th->data_source) != 0))
789 if ((th->flags & UT_FLAG_INVERT) != 0)
795 /* XXX: This is an experimental code, not optimized, not fast, not reliable,
796 * and probably, do not work as you expect. Enjoy! :D */
797 if ( (th->hysteresis > 0) && ((prev_state = uc_get_state(ds,vl)) != STATE_OKAY) )
802 if ( (!isnan (th->failure_min) && ((th->failure_min + th->hysteresis) < values[ds_index])) ||
803 (!isnan (th->failure_max) && ((th->failure_max - th->hysteresis) > values[ds_index])) )
808 if ( (!isnan (th->warning_min) && ((th->warning_min + th->hysteresis) < values[ds_index])) ||
809 (!isnan (th->warning_max) && ((th->warning_max - th->hysteresis) > values[ds_index])) )
815 else { /* no hysteresis */
816 if ((!isnan (th->failure_min) && (th->failure_min > values[ds_index]))
817 || (!isnan (th->failure_max) && (th->failure_max < values[ds_index])))
820 if ((!isnan (th->warning_min) && (th->warning_min > values[ds_index]))
821 || (!isnan (th->warning_max) && (th->warning_max < values[ds_index])))
826 return (STATE_ERROR);
829 return (STATE_WARNING);
832 } /* }}} int ut_check_one_data_source */
835 * int ut_check_one_threshold
837 * Checks all data sources of a value list against the given threshold, using
838 * the ut_check_one_data_source function above. Returns the worst status,
839 * which is `okay' if nothing has failed.
840 * Returns less than zero if the data set doesn't have any data sources.
842 static int ut_check_one_threshold (const data_set_t *ds,
843 const value_list_t *vl,
844 const threshold_t *th,
845 const gauge_t *values,
851 gauge_t values_copy[ds->ds_num];
853 memcpy (values_copy, values, sizeof (values_copy));
855 if ((th->flags & UT_FLAG_PERCENTAGE) != 0)
862 WARNING ("ut_check_one_threshold: The %s type has only one data "
863 "source, but you have configured to check this as a percentage. "
864 "That doesn't make much sense, because the percentage will always "
865 "be 100%%!", ds->type);
868 /* Prepare `sum' and `num'. */
869 for (i = 0; i < ds->ds_num; i++)
870 if (!isnan (values[i]))
876 if ((num == 0) /* All data sources are undefined. */
877 || (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
879 for (i = 0; i < ds->ds_num; i++)
880 values_copy[i] = NAN;
882 else /* We can actually calculate the percentage. */
884 for (i = 0; i < ds->ds_num; i++)
885 values_copy[i] = 100.0 * values[i] / sum;
887 } /* if (UT_FLAG_PERCENTAGE) */
889 for (i = 0; i < ds->ds_num; i++)
893 status = ut_check_one_data_source (ds, vl, th, values_copy, i);
899 } /* for (ds->ds_num) */
901 if (ret_ds_index != NULL)
902 *ret_ds_index = ds_index;
905 } /* }}} int ut_check_one_threshold */
908 * int ut_check_threshold
910 * Gets a list of matching thresholds and searches for the worst status by one
911 * of the thresholds. Then reports that status using the ut_report_state
913 * Returns zero on success and if no threshold has been configured. Returns
914 * less than zero on failure.
916 static int ut_check_threshold (const data_set_t *ds, const value_list_t *vl,
917 __attribute__((unused)) user_data_t *ud)
923 int worst_state = -1;
924 threshold_t *worst_th = NULL;
925 int worst_ds_index = -1;
927 if (threshold_tree == NULL)
930 /* Is this lock really necessary? So far, thresholds are only inserted at
932 pthread_mutex_lock (&threshold_lock);
933 th = threshold_search (vl);
934 pthread_mutex_unlock (&threshold_lock);
938 DEBUG ("ut_check_threshold: Found matching threshold(s)");
940 values = uc_get_rate (ds, vl);
948 status = ut_check_one_threshold (ds, vl, th, values, &ds_index);
951 ERROR ("ut_check_threshold: ut_check_one_threshold failed.");
956 if (worst_state < status)
958 worst_state = status;
960 worst_ds_index = ds_index;
966 status = ut_report_state (ds, vl, worst_th, values,
967 worst_ds_index, worst_state);
970 ERROR ("ut_check_threshold: ut_report_state failed.");
978 } /* }}} int ut_check_threshold */
983 * This function is called whenever a value goes "missing".
985 static int ut_missing (const value_list_t *vl,
986 __attribute__((unused)) user_data_t *ud)
989 cdtime_t missing_time;
990 char identifier[6 * DATA_MAX_NAME_LEN];
993 th = threshold_search (vl);
997 missing_time = cdtime () - vl->time;
998 FORMAT_VL (identifier, sizeof (identifier), vl);
1000 NOTIFICATION_INIT_VL (&n, vl);
1001 ssnprintf (n.message, sizeof (n.message),
1002 "%s has not been updated for %.3f seconds.",
1003 identifier, CDTIME_T_TO_DOUBLE (missing_time));
1005 plugin_dispatch_notification (&n);
1008 } /* }}} int ut_missing */
1010 void module_register (void)
1012 plugin_register_complex_config ("threshold", ut_config);
1013 plugin_register_missing ("threshold", ut_missing,
1014 /* user data = */ NULL);
1015 plugin_register_write ("threshold", ut_check_threshold,
1016 /* user data = */ NULL);
1019 /* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */