summaryrefslogtreecommitdiffstats
path: root/plugins/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/utils.c')
-rw-r--r--plugins/utils.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/plugins/utils.c b/plugins/utils.c
index 8b31c5a..dbb2520 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -265,7 +265,62 @@ is_option (char *str)
265 return FALSE; 265 return FALSE;
266} 266}
267 267
268void set_threshold_start (threshold *this, double value) {
269 this->start = value;
270 this->start_infinity = FALSE;
271}
272
273void set_threshold_end (threshold *this, double value) {
274 this->end = value;
275 this->end_infinity = FALSE;
276}
277
278threshold
279*parse_threshold (char *str) {
280 threshold *temp_threshold;
281 double start;
282 double end;
283 char *end_str;
268 284
285 temp_threshold = (threshold *) malloc(sizeof(threshold));
286
287 /* Set defaults */
288 temp_threshold->start = 0;
289 temp_threshold->start_infinity = FALSE;
290 temp_threshold->end = 0;
291 temp_threshold->end_infinity = TRUE;
292 temp_threshold->alert_on = OUTSIDE;
293
294 if (str[0] == '@') {
295 temp_threshold->alert_on = INSIDE;
296 str++;
297 }
298
299 end_str = index(str, ':');
300 if (end_str != NULL) {
301 if (str[0] == '~') {
302 temp_threshold->start_infinity = TRUE;
303 } else {
304 start = strtod(str, NULL); /* Will stop at the ':' */
305 set_threshold_start(temp_threshold, start);
306 }
307 end_str++; /* Move past the ':' */
308 } else {
309 end_str = str;
310 }
311 end = strtod(end_str, NULL);
312 if (strcmp(end_str, "") != 0) {
313 set_threshold_end(temp_threshold, end);
314 }
315
316 if (temp_threshold->start_infinity == TRUE ||
317 temp_threshold->end_infinity == TRUE ||
318 temp_threshold->start <= temp_threshold->end) {
319 return temp_threshold;
320 }
321 free(temp_threshold);
322 return NULL;
323}
269 324
270#ifdef NEED_GETTIMEOFDAY 325#ifdef NEED_GETTIMEOFDAY
271int 326int