src/utils_threshold.c: Implement configuration of multiple data sources per type.
[collectd.git] / src / utils_threshold.c
1 /**
2  * collectd - src/utils_threshold.c
3  * Copyright (C) 2007,2008  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Author:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #include "collectd.h"
23 #include "common.h"
24 #include "plugin.h"
25 #include "utils_avltree.h"
26 #include "utils_cache.h"
27
28 #include <assert.h>
29 #include <pthread.h>
30
31 /*
32  * Private data structures
33  * {{{ */
34 #define UT_FLAG_INVERT  0x01
35 #define UT_FLAG_PERSIST 0x02
36
37 typedef struct threshold_s
38 {
39   char host[DATA_MAX_NAME_LEN];
40   char plugin[DATA_MAX_NAME_LEN];
41   char plugin_instance[DATA_MAX_NAME_LEN];
42   char type[DATA_MAX_NAME_LEN];
43   char type_instance[DATA_MAX_NAME_LEN];
44   char data_source[DATA_MAX_NAME_LEN];
45   gauge_t warning_min;
46   gauge_t warning_max;
47   gauge_t failure_min;
48   gauge_t failure_max;
49   int flags;
50   struct threshold_s *next;
51 } threshold_t;
52 /* }}} */
53
54 /*
55  * Private (static) variables
56  * {{{ */
57 static c_avl_tree_t   *threshold_tree = NULL;
58 static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
59 /* }}} */
60
61 /*
62  * Threshold management
63  * ====================
64  * The following functions add, delete, search, etc. configured thresholds to
65  * the underlying AVL trees.
66  * {{{ */
67 static threshold_t *threshold_get (const char *hostname,
68     const char *plugin, const char *plugin_instance,
69     const char *type, const char *type_instance)
70 {
71   char name[6 * DATA_MAX_NAME_LEN];
72   threshold_t *th = NULL;
73
74   format_name (name, sizeof (name),
75       (hostname == NULL) ? "" : hostname,
76       (plugin == NULL) ? "" : plugin, plugin_instance,
77       (type == NULL) ? "" : type, type_instance);
78   name[sizeof (name) - 1] = '\0';
79
80   if (c_avl_get (threshold_tree, name, (void *) &th) == 0)
81     return (th);
82   else
83     return (NULL);
84 } /* threshold_t *threshold_get */
85
86 static int ut_threshold_add (const threshold_t *th)
87 {
88   char name[6 * DATA_MAX_NAME_LEN];
89   char *name_copy;
90   threshold_t *th_copy;
91   threshold_t *th_ptr;
92   int status = 0;
93
94   if (format_name (name, sizeof (name), th->host,
95         th->plugin, th->plugin_instance,
96         th->type, th->type_instance) != 0)
97   {
98     ERROR ("ut_threshold_add: format_name failed.");
99     return (-1);
100   }
101
102   name_copy = strdup (name);
103   if (name_copy == NULL)
104   {
105     ERROR ("ut_threshold_add: strdup failed.");
106     return (-1);
107   }
108
109   th_copy = (threshold_t *) malloc (sizeof (threshold_t));
110   if (th_copy == NULL)
111   {
112     sfree (name_copy);
113     ERROR ("ut_threshold_add: malloc failed.");
114     return (-1);
115   }
116   memcpy (th_copy, th, sizeof (threshold_t));
117   th_copy = NULL;
118
119   DEBUG ("ut_threshold_add: Adding entry `%s'", name);
120
121   pthread_mutex_lock (&threshold_lock);
122
123   th_ptr = threshold_get (th->host, th->plugin, th->plugin_instance,
124       th->type, th->type_instance);
125
126   while ((th_ptr != NULL) && (th_ptr->next != NULL))
127     th_ptr = th_ptr->next;
128
129   if (th_ptr == NULL) /* no such threshold yet */
130   {
131     status = c_avl_insert (threshold_tree, name_copy, th_copy);
132   }
133   else /* th_ptr points to the last threshold in the list */
134   {
135     th_ptr->next = th_copy;
136     /* name_copy isn't needed */
137     sfree (name_copy);
138   }
139
140   pthread_mutex_unlock (&threshold_lock);
141
142   if (status != 0)
143   {
144     ERROR ("ut_threshold_add: c_avl_insert (%s) failed.", name);
145     sfree (name_copy);
146     sfree (th_copy);
147   }
148
149   return (status);
150 } /* int ut_threshold_add */
151 /*
152  * End of the threshold management functions
153  * }}} */
154
155 /*
156  * Configuration
157  * =============
158  * The following approximately two hundred functions are used to handle the
159  * configuration and fill the threshold list.
160  * {{{ */
161 static int ut_config_type_datasource (threshold_t *th, oconfig_item_t *ci)
162 {
163   if ((ci->values_num != 1)
164       || (ci->values[0].type != OCONFIG_TYPE_STRING))
165   {
166     WARNING ("threshold values: The `DataSource' option needs exactly one "
167         "string argument.");
168     return (-1);
169   }
170
171   sstrncpy (th->data_source, ci->values[0].value.string,
172       sizeof (th->data_source));
173
174   return (0);
175 } /* int ut_config_type_datasource */
176
177 static int ut_config_type_instance (threshold_t *th, oconfig_item_t *ci)
178 {
179   if ((ci->values_num != 1)
180       || (ci->values[0].type != OCONFIG_TYPE_STRING))
181   {
182     WARNING ("threshold values: The `Instance' option needs exactly one "
183         "string argument.");
184     return (-1);
185   }
186
187   strncpy (th->type_instance, ci->values[0].value.string,
188       sizeof (th->type_instance));
189   th->type_instance[sizeof (th->type_instance) - 1] = '\0';
190
191   return (0);
192 } /* int ut_config_type_instance */
193
194 static int ut_config_type_max (threshold_t *th, oconfig_item_t *ci)
195 {
196   if ((ci->values_num != 1)
197       || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
198   {
199     WARNING ("threshold values: The `%s' option needs exactly one "
200         "number argument.", ci->key);
201     return (-1);
202   }
203
204   if (strcasecmp (ci->key, "WarningMax") == 0)
205     th->warning_max = ci->values[0].value.number;
206   else
207     th->failure_max = ci->values[0].value.number;
208
209   return (0);
210 } /* int ut_config_type_max */
211
212 static int ut_config_type_min (threshold_t *th, oconfig_item_t *ci)
213 {
214   if ((ci->values_num != 1)
215       || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
216   {
217     WARNING ("threshold values: The `%s' option needs exactly one "
218         "number argument.", ci->key);
219     return (-1);
220   }
221
222   if (strcasecmp (ci->key, "WarningMin") == 0)
223     th->warning_min = ci->values[0].value.number;
224   else
225     th->failure_min = ci->values[0].value.number;
226
227   return (0);
228 } /* int ut_config_type_min */
229
230 static int ut_config_type_invert (threshold_t *th, oconfig_item_t *ci)
231 {
232   if ((ci->values_num != 1)
233       || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
234   {
235     WARNING ("threshold values: The `Invert' option needs exactly one "
236         "boolean argument.");
237     return (-1);
238   }
239
240   if (ci->values[0].value.boolean)
241     th->flags |= UT_FLAG_INVERT;
242   else
243     th->flags &= ~UT_FLAG_INVERT;
244
245   return (0);
246 } /* int ut_config_type_invert */
247
248 static int ut_config_type_persist (threshold_t *th, oconfig_item_t *ci)
249 {
250   if ((ci->values_num != 1)
251       || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
252   {
253     WARNING ("threshold values: The `Persist' option needs exactly one "
254         "boolean argument.");
255     return (-1);
256   }
257
258   if (ci->values[0].value.boolean)
259     th->flags |= UT_FLAG_PERSIST;
260   else
261     th->flags &= ~UT_FLAG_PERSIST;
262
263   return (0);
264 } /* int ut_config_type_persist */
265
266 static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
267 {
268   int i;
269   threshold_t th;
270   int status = 0;
271
272   if ((ci->values_num != 1)
273       || (ci->values[0].type != OCONFIG_TYPE_STRING))
274   {
275     WARNING ("threshold values: The `Type' block needs exactly one string "
276         "argument.");
277     return (-1);
278   }
279
280   if (ci->children_num < 1)
281   {
282     WARNING ("threshold values: The `Type' block needs at least one option.");
283     return (-1);
284   }
285
286   memcpy (&th, th_orig, sizeof (th));
287   strncpy (th.type, ci->values[0].value.string, sizeof (th.type));
288   th.type[sizeof (th.type) - 1] = '\0';
289
290   th.warning_min = NAN;
291   th.warning_max = NAN;
292   th.failure_min = NAN;
293   th.failure_max = NAN;
294
295   for (i = 0; i < ci->children_num; i++)
296   {
297     oconfig_item_t *option = ci->children + i;
298     status = 0;
299
300     if (strcasecmp ("Instance", option->key) == 0)
301       status = ut_config_type_instance (&th, option);
302     if (strcasecmp ("DataSource", option->key) == 0)
303       status = ut_config_type_datasource (&th, option);
304     else if ((strcasecmp ("WarningMax", option->key) == 0)
305         || (strcasecmp ("FailureMax", option->key) == 0))
306       status = ut_config_type_max (&th, option);
307     else if ((strcasecmp ("WarningMin", option->key) == 0)
308         || (strcasecmp ("FailureMin", option->key) == 0))
309       status = ut_config_type_min (&th, option);
310     else if (strcasecmp ("Invert", option->key) == 0)
311       status = ut_config_type_invert (&th, option);
312     else if (strcasecmp ("Persist", option->key) == 0)
313       status = ut_config_type_persist (&th, option);
314     else
315     {
316       WARNING ("threshold values: Option `%s' not allowed inside a `Type' "
317           "block.", option->key);
318       status = -1;
319     }
320
321     if (status != 0)
322       break;
323   }
324
325   if (status == 0)
326   {
327     status = ut_threshold_add (&th);
328   }
329
330   return (status);
331 } /* int ut_config_type */
332
333 static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci)
334 {
335   if ((ci->values_num != 1)
336       || (ci->values[0].type != OCONFIG_TYPE_STRING))
337   {
338     WARNING ("threshold values: The `Instance' option needs exactly one "
339         "string argument.");
340     return (-1);
341   }
342
343   strncpy (th->plugin_instance, ci->values[0].value.string,
344       sizeof (th->plugin_instance));
345   th->plugin_instance[sizeof (th->plugin_instance) - 1] = '\0';
346
347   return (0);
348 } /* int ut_config_plugin_instance */
349
350 static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
351 {
352   int i;
353   threshold_t th;
354   int status = 0;
355
356   if ((ci->values_num != 1)
357       || (ci->values[0].type != OCONFIG_TYPE_STRING))
358   {
359     WARNING ("threshold values: The `Plugin' block needs exactly one string "
360         "argument.");
361     return (-1);
362   }
363
364   if (ci->children_num < 1)
365   {
366     WARNING ("threshold values: The `Plugin' block needs at least one nested "
367         "block.");
368     return (-1);
369   }
370
371   memcpy (&th, th_orig, sizeof (th));
372   strncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
373   th.plugin[sizeof (th.plugin) - 1] = '\0';
374
375   for (i = 0; i < ci->children_num; i++)
376   {
377     oconfig_item_t *option = ci->children + i;
378     status = 0;
379
380     if (strcasecmp ("Type", option->key) == 0)
381       status = ut_config_type (&th, option);
382     else if (strcasecmp ("Instance", option->key) == 0)
383       status = ut_config_plugin_instance (&th, option);
384     else
385     {
386       WARNING ("threshold values: Option `%s' not allowed inside a `Plugin' "
387           "block.", option->key);
388       status = -1;
389     }
390
391     if (status != 0)
392       break;
393   }
394
395   return (status);
396 } /* int ut_config_plugin */
397
398 static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
399 {
400   int i;
401   threshold_t th;
402   int status = 0;
403
404   if ((ci->values_num != 1)
405       || (ci->values[0].type != OCONFIG_TYPE_STRING))
406   {
407     WARNING ("threshold values: The `Host' block needs exactly one string "
408         "argument.");
409     return (-1);
410   }
411
412   if (ci->children_num < 1)
413   {
414     WARNING ("threshold values: The `Host' block needs at least one nested "
415         "block.");
416     return (-1);
417   }
418
419   memcpy (&th, th_orig, sizeof (th));
420   strncpy (th.host, ci->values[0].value.string, sizeof (th.host));
421   th.host[sizeof (th.host) - 1] = '\0';
422
423   for (i = 0; i < ci->children_num; i++)
424   {
425     oconfig_item_t *option = ci->children + i;
426     status = 0;
427
428     if (strcasecmp ("Type", option->key) == 0)
429       status = ut_config_type (&th, option);
430     else if (strcasecmp ("Plugin", option->key) == 0)
431       status = ut_config_plugin (&th, option);
432     else
433     {
434       WARNING ("threshold values: Option `%s' not allowed inside a `Host' "
435           "block.", option->key);
436       status = -1;
437     }
438
439     if (status != 0)
440       break;
441   }
442
443   return (status);
444 } /* int ut_config_host */
445
446 int ut_config (const oconfig_item_t *ci)
447 {
448   int i;
449   int status = 0;
450
451   threshold_t th;
452
453   if (ci->values_num != 0)
454   {
455     ERROR ("threshold values: The `Threshold' block may not have any "
456         "arguments.");
457     return (-1);
458   }
459
460   if (threshold_tree == NULL)
461   {
462     threshold_tree = c_avl_create ((void *) strcmp);
463     if (threshold_tree == NULL)
464     {
465       ERROR ("ut_config: c_avl_create failed.");
466       return (-1);
467     }
468   }
469
470   memset (&th, '\0', sizeof (th));
471   th.warning_min = NAN;
472   th.warning_max = NAN;
473   th.failure_min = NAN;
474   th.failure_max = NAN;
475     
476   for (i = 0; i < ci->children_num; i++)
477   {
478     oconfig_item_t *option = ci->children + i;
479     status = 0;
480
481     if (strcasecmp ("Type", option->key) == 0)
482       status = ut_config_type (&th, option);
483     else if (strcasecmp ("Plugin", option->key) == 0)
484       status = ut_config_plugin (&th, option);
485     else if (strcasecmp ("Host", option->key) == 0)
486       status = ut_config_host (&th, option);
487     else
488     {
489       WARNING ("threshold values: Option `%s' not allowed here.", option->key);
490       status = -1;
491     }
492
493     if (status != 0)
494       break;
495   }
496
497   return (status);
498 } /* int um_config */
499 /*
500  * End of the functions used to configure threshold values.
501  */
502 /* }}} */
503
504 static threshold_t *threshold_search (const data_set_t *ds,
505     const value_list_t *vl)
506 {
507   threshold_t *th;
508
509   if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
510           ds->type, vl->type_instance)) != NULL)
511     return (th);
512   else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
513           ds->type, NULL)) != NULL)
514     return (th);
515   else if ((th = threshold_get (vl->host, vl->plugin, NULL,
516           ds->type, vl->type_instance)) != NULL)
517     return (th);
518   else if ((th = threshold_get (vl->host, vl->plugin, NULL,
519           ds->type, NULL)) != NULL)
520     return (th);
521   else if ((th = threshold_get (vl->host, "", NULL,
522           ds->type, vl->type_instance)) != NULL)
523     return (th);
524   else if ((th = threshold_get (vl->host, "", NULL,
525           ds->type, NULL)) != NULL)
526     return (th);
527   else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
528           ds->type, vl->type_instance)) != NULL)
529     return (th);
530   else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
531           ds->type, NULL)) != NULL)
532     return (th);
533   else if ((th = threshold_get ("", vl->plugin, NULL,
534           ds->type, vl->type_instance)) != NULL)
535     return (th);
536   else if ((th = threshold_get ("", vl->plugin, NULL,
537           ds->type, NULL)) != NULL)
538     return (th);
539   else if ((th = threshold_get ("", "", NULL,
540           ds->type, vl->type_instance)) != NULL)
541     return (th);
542   else if ((th = threshold_get ("", "", NULL,
543           ds->type, NULL)) != NULL)
544     return (th);
545
546   return (NULL);
547 } /* threshold_t *threshold_search */
548
549 /* TODO: Split this into two functions, one that iterates over all threshold
550  * definitions and one that checks if (a) the threshold matches (the data
551  * source matches) and (b) if the threshold is satisfied or not. Break at the
552  * first matching threshold. */
553 int ut_check_threshold (const data_set_t *ds, const value_list_t *vl)
554 {
555   notification_t n;
556   threshold_t *th;
557   gauge_t *values;
558   int i;
559
560   int state_orig;
561   int state_new = STATE_OKAY;
562   int ds_index = 0;
563
564   char *buf;
565   size_t bufsize;
566   int status;
567
568   if (threshold_tree == NULL)
569     return (0);
570
571   /* Is this lock really necessary? So far, thresholds are only inserted at
572    * startup. -octo */
573   pthread_mutex_lock (&threshold_lock);
574   th = threshold_search (ds, vl);
575   pthread_mutex_unlock (&threshold_lock);
576   if (th == NULL)
577     return (0);
578
579   DEBUG ("ut_check_threshold: Found matching threshold");
580
581   values = uc_get_rate (ds, vl);
582   if (values == NULL)
583     return (0);
584
585   state_orig = uc_get_state (ds, vl);
586
587   for (i = 0; i < ds->ds_num; i++)
588   {
589     int is_inverted = 0;
590     int is_warning = 0;
591     int is_failure = 0;
592
593     if ((th->flags & UT_FLAG_INVERT) != 0)
594     {
595       is_inverted = 1;
596       is_warning--;
597       is_failure--;
598     }
599     if ((!isnan (th->failure_min) && (th->failure_min > values[i]))
600         || (!isnan (th->failure_max) && (th->failure_max < values[i])))
601       is_failure++;
602     if ((!isnan (th->warning_min) && (th->warning_min > values[i]))
603         || (!isnan (th->warning_max) && (th->warning_max < values[i])))
604       is_warning++;
605
606     if ((is_failure != 0) && (state_new != STATE_ERROR))
607     {
608       state_new = STATE_ERROR;
609       ds_index = i;
610     }
611     else if ((is_warning != 0)
612         && (state_new != STATE_ERROR)
613         && (state_new != STATE_WARNING))
614     {
615       state_new = STATE_WARNING;
616       ds_index = i;
617     }
618   }
619
620   if (state_new != state_orig)
621     uc_set_state (ds, vl, state_new);
622
623   /* Return here if we're not going to send a notification */
624   if ((state_new == state_orig)
625       && ((state_new == STATE_OKAY)
626         || ((th->flags & UT_FLAG_PERSIST) == 0)))
627   {
628     sfree (values);
629     return (0);
630   }
631
632   NOTIFICATION_INIT_VL (&n, vl, ds);
633   {
634     /* Copy the associative members */
635     if (state_new == STATE_OKAY)
636       n.severity = NOTIF_OKAY;
637     else if (state_new == STATE_WARNING)
638       n.severity = NOTIF_WARNING;
639     else
640       n.severity = NOTIF_FAILURE;
641
642     n.time = vl->time;
643
644     buf = n.message;
645     bufsize = sizeof (n.message);
646
647     status = snprintf (buf, bufsize, "Host %s, plugin %s",
648         vl->host, vl->plugin);
649     buf += status;
650     bufsize -= status;
651
652     if (vl->plugin_instance[0] != '\0')
653     {
654       status = snprintf (buf, bufsize, " (instance %s)",
655           vl->plugin_instance);
656       buf += status;
657       bufsize -= status;
658     }
659
660     status = snprintf (buf, bufsize, " type %s", ds->type);
661     buf += status;
662     bufsize -= status;
663
664     if (vl->type_instance[0] != '\0')
665     {
666       status = snprintf (buf, bufsize, " (instance %s)",
667           vl->type_instance);
668       buf += status;
669       bufsize -= status;
670     }
671   }
672
673   /* Send a okay notification */
674   if (state_new == STATE_OKAY)
675   {
676     status = snprintf (buf, bufsize, ": All data sources are within range again.");
677     buf += status;
678     bufsize -= status;
679   }
680   else
681   {
682     double min;
683     double max;
684
685     min = (state_new == STATE_ERROR) ? th->failure_min : th->warning_min;
686     max = (state_new == STATE_ERROR) ? th->failure_max : th->warning_max;
687
688     if (th->flags & UT_FLAG_INVERT)
689     {
690       if (!isnan (min) && !isnan (max))
691       {
692         status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
693             "%f. That is within the %s region of %f and %f.",
694             ds->ds[ds_index].name, values[ds_index],
695             (state_new == STATE_ERROR) ? "failure" : "warning",
696             min, min);
697       }
698       else
699       {
700         status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
701             "%f. That is %s the %s threshold of %f.",
702             ds->ds[ds_index].name, values[ds_index],
703             isnan (min) ? "below" : "above",
704             (state_new == STATE_ERROR) ? "failure" : "warning",
705             isnan (min) ? max : min);
706       }
707     }
708     else /* is not inverted */
709     {
710       status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
711           "%f. That is %s the %s threshold of %f.",
712           ds->ds[ds_index].name, values[ds_index],
713           (values[ds_index] < min) ? "below" : "above",
714           (state_new == STATE_ERROR) ? "failure" : "warning",
715           (values[ds_index] < min) ? min : max);
716     }
717     buf += status;
718     bufsize -= status;
719   }
720
721   plugin_dispatch_notification (&n);
722
723   sfree (values);
724
725   return (0);
726 } /* int ut_check_threshold */
727
728 int ut_check_interesting (const char *name)
729 {
730   char *name_copy = NULL;
731   char *host = NULL;
732   char *plugin = NULL;
733   char *plugin_instance = NULL;
734   char *type = NULL;
735   char *type_instance = NULL;
736   int status;
737   data_set_t ds;
738   value_list_t vl;
739   threshold_t *th;
740
741   /* If there is no tree nothing is interesting. */
742   if (threshold_tree == NULL)
743     return (0);
744
745   name_copy = strdup (name);
746   if (name_copy == NULL)
747   {
748     ERROR ("ut_check_interesting: strdup failed.");
749     return (-1);
750   }
751
752   status = parse_identifier (name_copy, &host,
753       &plugin, &plugin_instance, &type, &type_instance);
754   if (status != 0)
755   {
756     ERROR ("ut_check_interesting: parse_identifier failed.");
757     return (-1);
758   }
759
760   memset (&ds, '\0', sizeof (ds));
761   memset (&vl, '\0', sizeof (vl));
762
763   strncpy (vl.host, host, sizeof (vl.host));
764   vl.host[sizeof (vl.host) - 1] = '\0';
765   strncpy (vl.plugin, plugin, sizeof (vl.plugin));
766   vl.plugin[sizeof (vl.plugin) - 1] = '\0';
767   if (plugin_instance != NULL)
768   {
769     strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
770     vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0';
771   }
772   strncpy (ds.type, type, sizeof (ds.type));
773   ds.type[sizeof (ds.type) - 1] = '\0';
774   if (type_instance != NULL)
775   {
776     strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
777     vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
778   }
779
780   sfree (name_copy);
781   host = plugin = plugin_instance = type = type_instance = NULL;
782
783   th = threshold_search (&ds, &vl);
784   if (th == NULL)
785     return (0);
786   if ((th->flags & UT_FLAG_PERSIST) == 0)
787     return (1);
788   return (2);
789 } /* int ut_check_interesting */
790
791 /* vim: set sw=2 ts=8 sts=2 tw=78 fdm=marker : */