2 * collectd - src/utils_threshold.c
3 * Copyright (C) 2007-2009 Florian octo Forster
4 * Copyright (C) 2008-2009 Sebastian Harl
5 * Copyright (C) 2009 Andrés J. Díaz
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; only version 2 of the License is applicable.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Florian octo Forster <octo at verplant.org>
23 * Sebastian Harl <sh at tokkee.org>
24 * Andrés J. Díaz <ajdiaz at connectical.com>
30 #include "utils_avltree.h"
31 #include "utils_cache.h"
32 #include "utils_threshold.h"
38 * Private data structures
40 #define UT_FLAG_INVERT 0x01
41 #define UT_FLAG_PERSIST 0x02
42 #define UT_FLAG_PERCENTAGE 0x04
43 #define UT_FLAG_INTERESTING 0x08
47 * Private (static) variables
49 static c_avl_tree_t *threshold_tree = NULL;
50 static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
54 * Threshold management
55 * ====================
56 * The following functions add, delete, search, etc. configured thresholds to
57 * the underlying AVL trees.
59 static threshold_t *threshold_get (const char *hostname,
60 const char *plugin, const char *plugin_instance,
61 const char *type, const char *type_instance)
63 char name[6 * DATA_MAX_NAME_LEN];
64 threshold_t *th = NULL;
66 format_name (name, sizeof (name),
67 (hostname == NULL) ? "" : hostname,
68 (plugin == NULL) ? "" : plugin, plugin_instance,
69 (type == NULL) ? "" : type, type_instance);
70 name[sizeof (name) - 1] = '\0';
72 if (c_avl_get (threshold_tree, name, (void *) &th) == 0)
76 } /* threshold_t *threshold_get */
78 static int ut_threshold_add (const threshold_t *th)
80 char name[6 * DATA_MAX_NAME_LEN];
86 if (format_name (name, sizeof (name), th->host,
87 th->plugin, th->plugin_instance,
88 th->type, th->type_instance) != 0)
90 ERROR ("ut_threshold_add: format_name failed.");
94 name_copy = strdup (name);
95 if (name_copy == NULL)
97 ERROR ("ut_threshold_add: strdup failed.");
101 th_copy = (threshold_t *) malloc (sizeof (threshold_t));
105 ERROR ("ut_threshold_add: malloc failed.");
108 memcpy (th_copy, th, sizeof (threshold_t));
111 DEBUG ("ut_threshold_add: Adding entry `%s'", name);
113 pthread_mutex_lock (&threshold_lock);
115 th_ptr = threshold_get (th->host, th->plugin, th->plugin_instance,
116 th->type, th->type_instance);
118 while ((th_ptr != NULL) && (th_ptr->next != NULL))
119 th_ptr = th_ptr->next;
121 if (th_ptr == NULL) /* no such threshold yet */
123 status = c_avl_insert (threshold_tree, name_copy, th_copy);
125 else /* th_ptr points to the last threshold in the list */
127 th_ptr->next = th_copy;
128 /* name_copy isn't needed */
132 pthread_mutex_unlock (&threshold_lock);
136 ERROR ("ut_threshold_add: c_avl_insert (%s) failed.", name);
142 } /* int ut_threshold_add */
144 * End of the threshold management functions
150 * The following approximately two hundred functions are used to handle the
151 * configuration and fill the threshold list.
153 static int ut_config_type_datasource (threshold_t *th, oconfig_item_t *ci)
155 if ((ci->values_num != 1)
156 || (ci->values[0].type != OCONFIG_TYPE_STRING))
158 WARNING ("threshold values: The `DataSource' option needs exactly one "
163 sstrncpy (th->data_source, ci->values[0].value.string,
164 sizeof (th->data_source));
167 } /* int ut_config_type_datasource */
169 static int ut_config_type_instance (threshold_t *th, oconfig_item_t *ci)
171 if ((ci->values_num != 1)
172 || (ci->values[0].type != OCONFIG_TYPE_STRING))
174 WARNING ("threshold values: The `Instance' option needs exactly one "
179 sstrncpy (th->type_instance, ci->values[0].value.string,
180 sizeof (th->type_instance));
183 } /* int ut_config_type_instance */
185 static int ut_config_type_max (threshold_t *th, oconfig_item_t *ci)
187 if ((ci->values_num != 1)
188 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
190 WARNING ("threshold values: The `%s' option needs exactly one "
191 "number argument.", ci->key);
195 if (strcasecmp (ci->key, "WarningMax") == 0)
196 th->warning_max = ci->values[0].value.number;
198 th->failure_max = ci->values[0].value.number;
201 } /* int ut_config_type_max */
203 static int ut_config_type_min (threshold_t *th, oconfig_item_t *ci)
205 if ((ci->values_num != 1)
206 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
208 WARNING ("threshold values: The `%s' option needs exactly one "
209 "number argument.", ci->key);
213 if (strcasecmp (ci->key, "WarningMin") == 0)
214 th->warning_min = ci->values[0].value.number;
216 th->failure_min = ci->values[0].value.number;
219 } /* int ut_config_type_min */
221 static int ut_config_type_interesting (threshold_t *th, oconfig_item_t *ci)
223 if ((ci->values_num != 1)
224 || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
226 WARNING ("threshold values: The `Interesting' option needs exactly one "
227 "boolean argument.");
231 if (ci->values[0].value.boolean)
232 th->flags |= UT_FLAG_INTERESTING;
234 th->flags &= ~UT_FLAG_INTERESTING;
237 } /* int ut_config_type_interesting */
239 static int ut_config_type_invert (threshold_t *th, oconfig_item_t *ci)
241 if ((ci->values_num != 1)
242 || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
244 WARNING ("threshold values: The `Invert' option needs exactly one "
245 "boolean argument.");
249 if (ci->values[0].value.boolean)
250 th->flags |= UT_FLAG_INVERT;
252 th->flags &= ~UT_FLAG_INVERT;
255 } /* int ut_config_type_invert */
257 static int ut_config_type_persist (threshold_t *th, oconfig_item_t *ci)
259 if ((ci->values_num != 1)
260 || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
262 WARNING ("threshold values: The `Persist' option needs exactly one "
263 "boolean argument.");
267 if (ci->values[0].value.boolean)
268 th->flags |= UT_FLAG_PERSIST;
270 th->flags &= ~UT_FLAG_PERSIST;
273 } /* int ut_config_type_persist */
275 static int ut_config_type_percentage(threshold_t *th, oconfig_item_t *ci)
277 if ((ci->values_num != 1)
278 || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
280 WARNING ("threshold values: The `Percentage' option needs exactly one "
281 "boolean argument.");
285 if (ci->values[0].value.boolean)
286 th->flags |= UT_FLAG_PERCENTAGE;
288 th->flags &= ~UT_FLAG_PERCENTAGE;
291 } /* int ut_config_type_percentage */
293 static int ut_config_type_hits (threshold_t *th, oconfig_item_t *ci)
295 if ((ci->values_num != 1)
296 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
298 WARNING ("threshold values: The `%s' option needs exactly one "
299 "number argument.", ci->key);
303 th->hits = ci->values[0].value.number;
306 } /* int ut_config_type_hits */
308 static int ut_config_type_hysteresis (threshold_t *th, oconfig_item_t *ci)
310 if ((ci->values_num != 1)
311 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
313 WARNING ("threshold values: The `%s' option needs exactly one "
314 "number argument.", ci->key);
318 th->hysteresis = ci->values[0].value.number;
321 } /* int ut_config_type_hysteresis */
323 static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
329 if ((ci->values_num != 1)
330 || (ci->values[0].type != OCONFIG_TYPE_STRING))
332 WARNING ("threshold values: The `Type' block needs exactly one string "
337 if (ci->children_num < 1)
339 WARNING ("threshold values: The `Type' block needs at least one option.");
343 memcpy (&th, th_orig, sizeof (th));
344 sstrncpy (th.type, ci->values[0].value.string, sizeof (th.type));
346 th.warning_min = NAN;
347 th.warning_max = NAN;
348 th.failure_min = NAN;
349 th.failure_max = NAN;
352 th.flags = UT_FLAG_INTERESTING; /* interesting by default */
354 for (i = 0; i < ci->children_num; i++)
356 oconfig_item_t *option = ci->children + i;
359 if (strcasecmp ("Instance", option->key) == 0)
360 status = ut_config_type_instance (&th, option);
361 else if (strcasecmp ("DataSource", option->key) == 0)
362 status = ut_config_type_datasource (&th, option);
363 else if ((strcasecmp ("WarningMax", option->key) == 0)
364 || (strcasecmp ("FailureMax", option->key) == 0))
365 status = ut_config_type_max (&th, option);
366 else if ((strcasecmp ("WarningMin", option->key) == 0)
367 || (strcasecmp ("FailureMin", option->key) == 0))
368 status = ut_config_type_min (&th, option);
369 else if (strcasecmp ("Interesting", option->key) == 0)
370 status = ut_config_type_interesting (&th, option);
371 else if (strcasecmp ("Invert", option->key) == 0)
372 status = ut_config_type_invert (&th, option);
373 else if (strcasecmp ("Persist", option->key) == 0)
374 status = ut_config_type_persist (&th, option);
375 else if (strcasecmp ("Percentage", option->key) == 0)
376 status = ut_config_type_percentage (&th, option);
377 else if (strcasecmp ("Hits", option->key) == 0)
378 status = ut_config_type_hits (&th, option);
379 else if (strcasecmp ("Hysteresis", option->key) == 0)
380 status = ut_config_type_hysteresis (&th, option);
383 WARNING ("threshold values: Option `%s' not allowed inside a `Type' "
384 "block.", option->key);
394 status = ut_threshold_add (&th);
398 } /* int ut_config_type */
400 static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci)
402 if ((ci->values_num != 1)
403 || (ci->values[0].type != OCONFIG_TYPE_STRING))
405 WARNING ("threshold values: The `Instance' option needs exactly one "
410 sstrncpy (th->plugin_instance, ci->values[0].value.string,
411 sizeof (th->plugin_instance));
414 } /* int ut_config_plugin_instance */
416 static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
422 if ((ci->values_num != 1)
423 || (ci->values[0].type != OCONFIG_TYPE_STRING))
425 WARNING ("threshold values: The `Plugin' block needs exactly one string "
430 if (ci->children_num < 1)
432 WARNING ("threshold values: The `Plugin' block needs at least one nested "
437 memcpy (&th, th_orig, sizeof (th));
438 sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
440 for (i = 0; i < ci->children_num; i++)
442 oconfig_item_t *option = ci->children + i;
445 if (strcasecmp ("Type", option->key) == 0)
446 status = ut_config_type (&th, option);
447 else if (strcasecmp ("Instance", option->key) == 0)
448 status = ut_config_plugin_instance (&th, option);
451 WARNING ("threshold values: Option `%s' not allowed inside a `Plugin' "
452 "block.", option->key);
461 } /* int ut_config_plugin */
463 static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
469 if ((ci->values_num != 1)
470 || (ci->values[0].type != OCONFIG_TYPE_STRING))
472 WARNING ("threshold values: The `Host' block needs exactly one string "
477 if (ci->children_num < 1)
479 WARNING ("threshold values: The `Host' block needs at least one nested "
484 memcpy (&th, th_orig, sizeof (th));
485 sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host));
487 for (i = 0; i < ci->children_num; i++)
489 oconfig_item_t *option = ci->children + i;
492 if (strcasecmp ("Type", option->key) == 0)
493 status = ut_config_type (&th, option);
494 else if (strcasecmp ("Plugin", option->key) == 0)
495 status = ut_config_plugin (&th, option);
498 WARNING ("threshold values: Option `%s' not allowed inside a `Host' "
499 "block.", option->key);
508 } /* int ut_config_host */
510 int ut_config (const oconfig_item_t *ci)
517 if (ci->values_num != 0)
519 ERROR ("threshold values: The `Threshold' block may not have any "
524 if (threshold_tree == NULL)
526 threshold_tree = c_avl_create ((void *) strcmp);
527 if (threshold_tree == NULL)
529 ERROR ("ut_config: c_avl_create failed.");
534 memset (&th, '\0', sizeof (th));
535 th.warning_min = NAN;
536 th.warning_max = NAN;
537 th.failure_min = NAN;
538 th.failure_max = NAN;
542 th.flags = UT_FLAG_INTERESTING; /* interesting by default */
544 for (i = 0; i < ci->children_num; i++)
546 oconfig_item_t *option = ci->children + i;
549 if (strcasecmp ("Type", option->key) == 0)
550 status = ut_config_type (&th, option);
551 else if (strcasecmp ("Plugin", option->key) == 0)
552 status = ut_config_plugin (&th, option);
553 else if (strcasecmp ("Host", option->key) == 0)
554 status = ut_config_host (&th, option);
557 WARNING ("threshold values: Option `%s' not allowed here.", option->key);
566 } /* int um_config */
568 * End of the functions used to configure threshold values.
572 static threshold_t *threshold_search (const value_list_t *vl)
576 if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
577 vl->type, vl->type_instance)) != NULL)
579 else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
580 vl->type, NULL)) != NULL)
582 else if ((th = threshold_get (vl->host, vl->plugin, NULL,
583 vl->type, vl->type_instance)) != NULL)
585 else if ((th = threshold_get (vl->host, vl->plugin, NULL,
586 vl->type, NULL)) != NULL)
588 else if ((th = threshold_get (vl->host, "", NULL,
589 vl->type, vl->type_instance)) != NULL)
591 else if ((th = threshold_get (vl->host, "", NULL,
592 vl->type, NULL)) != NULL)
594 else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
595 vl->type, vl->type_instance)) != NULL)
597 else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
598 vl->type, NULL)) != NULL)
600 else if ((th = threshold_get ("", vl->plugin, NULL,
601 vl->type, vl->type_instance)) != NULL)
603 else if ((th = threshold_get ("", vl->plugin, NULL,
604 vl->type, NULL)) != NULL)
606 else if ((th = threshold_get ("", "", NULL,
607 vl->type, vl->type_instance)) != NULL)
609 else if ((th = threshold_get ("", "", NULL,
610 vl->type, NULL)) != NULL)
614 } /* threshold_t *threshold_search */
617 * int ut_report_state
619 * Checks if the `state' differs from the old state and creates a notification
623 static int ut_report_state (const data_set_t *ds,
624 const value_list_t *vl,
625 const threshold_t *th,
626 const gauge_t *values,
638 /* Check if hits matched */
639 if ( (th->hits != 0) )
641 int hits = uc_get_hits(ds,vl);
642 /* The STATE_OKAY always reset hits, or if hits reaise the limit */
643 if ( (state == STATE_OKAY) || (hits > th->hits) )
645 DEBUG("ut_report_state: reset uc_get_hits = 0");
646 uc_set_hits(ds,vl,0); /* reset hit counter and notify */
648 DEBUG("ut_report_state: th->hits = %d, uc_get_hits = %d",th->hits,uc_get_hits(ds,vl));
649 (void) uc_inc_hits(ds,vl,1); /* increase hit counter */
652 } /* end check hits */
654 state_old = uc_get_state (ds, vl);
656 /* If the state didn't change, only report if `persistent' is specified and
657 * the state is not `okay'. */
658 if (state == state_old)
660 if ((th->flags & UT_FLAG_PERSIST) == 0)
662 else if (state == STATE_OKAY)
666 if (state != state_old)
667 uc_set_state (ds, vl, state);
669 NOTIFICATION_INIT_VL (&n, vl, ds);
672 bufsize = sizeof (n.message);
674 if (state == STATE_OKAY)
675 n.severity = NOTIF_OKAY;
676 else if (state == STATE_WARNING)
677 n.severity = NOTIF_WARNING;
679 n.severity = NOTIF_FAILURE;
683 status = ssnprintf (buf, bufsize, "Host %s, plugin %s",
684 vl->host, vl->plugin);
688 if (vl->plugin_instance[0] != '\0')
690 status = ssnprintf (buf, bufsize, " (instance %s)",
691 vl->plugin_instance);
696 status = ssnprintf (buf, bufsize, " type %s", vl->type);
700 if (vl->type_instance[0] != '\0')
702 status = ssnprintf (buf, bufsize, " (instance %s)",
708 plugin_notification_meta_add_string (&n, "DataSource",
709 ds->ds[ds_index].name);
710 plugin_notification_meta_add_double (&n, "CurrentValue", values[ds_index]);
711 plugin_notification_meta_add_double (&n, "WarningMin", th->warning_min);
712 plugin_notification_meta_add_double (&n, "WarningMax", th->warning_max);
713 plugin_notification_meta_add_double (&n, "FailureMin", th->failure_min);
714 plugin_notification_meta_add_double (&n, "FailureMax", th->failure_max);
716 /* Send an okay notification */
717 if (state == STATE_OKAY)
719 status = ssnprintf (buf, bufsize, ": All data sources are within range again.");
728 min = (state == STATE_ERROR) ? th->failure_min : th->warning_min;
729 max = (state == STATE_ERROR) ? th->failure_max : th->warning_max;
731 if (th->flags & UT_FLAG_INVERT)
733 if (!isnan (min) && !isnan (max))
735 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
736 "%f. That is within the %s region of %f%s and %f%s.",
737 ds->ds[ds_index].name, values[ds_index],
738 (state == STATE_ERROR) ? "failure" : "warning",
739 min, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "",
740 max, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
744 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
745 "%f. That is %s the %s threshold of %f%s.",
746 ds->ds[ds_index].name, values[ds_index],
747 isnan (min) ? "below" : "above",
748 (state == STATE_ERROR) ? "failure" : "warning",
749 isnan (min) ? max : min,
750 ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
753 else /* is not inverted */
755 status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
756 "%f. That is %s the %s threshold of %f%s.",
757 ds->ds[ds_index].name, values[ds_index],
758 (values[ds_index] < min) ? "below" : "above",
759 (state == STATE_ERROR) ? "failure" : "warning",
760 (values[ds_index] < min) ? min : max,
761 ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
767 plugin_dispatch_notification (&n);
769 plugin_notification_meta_free (n.meta);
771 } /* }}} int ut_report_state */
774 * int ut_check_one_data_source
776 * Checks one data source against the given threshold configuration. If the
777 * `DataSource' option is set in the threshold, and the name does NOT match,
778 * `okay' is returned. If the threshold does match, its failure and warning
779 * min and max values are checked and `failure' or `warning' is returned if
783 static int ut_check_one_data_source (const data_set_t *ds,
784 const value_list_t __attribute__((unused)) *vl,
785 const threshold_t *th,
786 const gauge_t *values,
792 int prev_state = STATE_OKAY;
794 /* check if this threshold applies to this data source */
797 ds_name = ds->ds[ds_index].name;
798 if ((th->data_source[0] != 0)
799 && (strcmp (ds_name, th->data_source) != 0))
803 if ((th->flags & UT_FLAG_INVERT) != 0)
809 /* XXX: This is an experimental code, not optimized, not fast, not reliable,
810 * and probably, do not work as you expect. Enjoy! :D */
811 if ( (th->hysteresis > 0) && ((prev_state = uc_get_state(ds,vl)) != STATE_OKAY) )
816 if ( (!isnan (th->failure_min) && ((th->failure_min + th->hysteresis) < values[ds_index])) ||
817 (!isnan (th->failure_max) && ((th->failure_max - th->hysteresis) > values[ds_index])) )
822 if ( (!isnan (th->warning_min) && ((th->warning_min + th->hysteresis) < values[ds_index])) ||
823 (!isnan (th->warning_max) && ((th->warning_max - th->hysteresis) > values[ds_index])) )
829 else { /* no hysteresis */
830 if ((!isnan (th->failure_min) && (th->failure_min > values[ds_index]))
831 || (!isnan (th->failure_max) && (th->failure_max < values[ds_index])))
834 if ((!isnan (th->warning_min) && (th->warning_min > values[ds_index]))
835 || (!isnan (th->warning_max) && (th->warning_max < values[ds_index])))
840 return (STATE_ERROR);
843 return (STATE_WARNING);
846 } /* }}} int ut_check_one_data_source */
849 * int ut_check_one_threshold
851 * Checks all data sources of a value list against the given threshold, using
852 * the ut_check_one_data_source function above. Returns the worst status,
853 * which is `okay' if nothing has failed.
854 * Returns less than zero if the data set doesn't have any data sources.
856 static int ut_check_one_threshold (const data_set_t *ds,
857 const value_list_t *vl,
858 const threshold_t *th,
859 const gauge_t *values,
865 gauge_t values_copy[ds->ds_num];
867 memcpy (values_copy, values, sizeof (values_copy));
869 if ((th->flags & UT_FLAG_PERCENTAGE) != 0)
876 WARNING ("ut_check_one_threshold: The %s type has only one data "
877 "source, but you have configured to check this as a percentage. "
878 "That doesn't make much sense, because the percentage will always "
879 "be 100%%!", ds->type);
882 /* Prepare `sum' and `num'. */
883 for (i = 0; i < ds->ds_num; i++)
884 if (!isnan (values[i]))
890 if ((num == 0) /* All data sources are undefined. */
891 || (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
893 for (i = 0; i < ds->ds_num; i++)
894 values_copy[i] = NAN;
896 else /* We can actually calculate the percentage. */
898 for (i = 0; i < ds->ds_num; i++)
899 values_copy[i] = 100.0 * values[i] / sum;
901 } /* if (UT_FLAG_PERCENTAGE) */
903 for (i = 0; i < ds->ds_num; i++)
907 status = ut_check_one_data_source (ds, vl, th, values_copy, i);
913 } /* for (ds->ds_num) */
915 if (ret_ds_index != NULL)
916 *ret_ds_index = ds_index;
919 } /* }}} int ut_check_one_threshold */
922 * int ut_check_threshold (PUBLIC)
924 * Gets a list of matching thresholds and searches for the worst status by one
925 * of the thresholds. Then reports that status using the ut_report_state
927 * Returns zero on success and if no threshold has been configured. Returns
928 * less than zero on failure.
930 int ut_check_threshold (const data_set_t *ds, const value_list_t *vl)
936 int worst_state = -1;
937 threshold_t *worst_th = NULL;
938 int worst_ds_index = -1;
940 if (threshold_tree == NULL)
943 /* Is this lock really necessary? So far, thresholds are only inserted at
945 pthread_mutex_lock (&threshold_lock);
946 th = threshold_search (vl);
947 pthread_mutex_unlock (&threshold_lock);
951 DEBUG ("ut_check_threshold: Found matching threshold(s)");
953 values = uc_get_rate (ds, vl);
961 status = ut_check_one_threshold (ds, vl, th, values, &ds_index);
964 ERROR ("ut_check_threshold: ut_check_one_threshold failed.");
969 if (worst_state < status)
971 worst_state = status;
973 worst_ds_index = ds_index;
979 status = ut_report_state (ds, vl, worst_th, values,
980 worst_ds_index, worst_state);
983 ERROR ("ut_check_threshold: ut_report_state failed.");
991 } /* }}} int ut_check_threshold */
994 * int ut_check_interesting (PUBLIC)
996 * Given an identification returns
997 * 0: No threshold is defined.
998 * 1: A threshold has been found. The flag `persist' is off.
999 * 2: A threshold has been found. The flag `persist' is on.
1000 * (That is, it is expected that many notifications are sent until the
1001 * problem disappears.)
1003 int ut_check_interesting (const char *name)
1005 char *name_copy = NULL;
1007 char *plugin = NULL;
1008 char *plugin_instance = NULL;
1010 char *type_instance = NULL;
1016 /* If there is no tree nothing is interesting. */
1017 if (threshold_tree == NULL)
1020 name_copy = strdup (name);
1021 if (name_copy == NULL)
1023 ERROR ("ut_check_interesting: strdup failed.");
1027 status = parse_identifier (name_copy, &host,
1028 &plugin, &plugin_instance, &type, &type_instance);
1031 ERROR ("ut_check_interesting: parse_identifier failed.");
1036 memset (&ds, '\0', sizeof (ds));
1037 memset (&vl, '\0', sizeof (vl));
1039 sstrncpy (vl.host, host, sizeof (vl.host));
1040 sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
1041 if (plugin_instance != NULL)
1042 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
1043 sstrncpy (ds.type, type, sizeof (ds.type));
1044 sstrncpy (vl.type, type, sizeof (vl.type));
1045 if (type_instance != NULL)
1046 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
1049 host = plugin = plugin_instance = type = type_instance = NULL;
1051 th = threshold_search (&vl);
1055 if ((th->flags & UT_FLAG_INTERESTING) == 0)
1058 if ((th->flags & UT_FLAG_PERSIST) == 0)
1061 } /* }}} int ut_check_interesting */
1063 int ut_search_threshold (const value_list_t *vl, /* {{{ */
1064 threshold_t *ret_threshold)
1071 t = threshold_search (vl);
1075 memcpy (ret_threshold, t, sizeof (*ret_threshold));
1076 ret_threshold->next = NULL;
1079 } /* }}} int ut_search_threshold */
1081 /* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */