aboutsummaryrefslogtreecommitdiff
path: root/plugins/utils.c
diff options
context:
space:
mode:
authorGravatar Ton Voon <tonvoon@users.sourceforge.net> 2006-01-30 16:10:50 +0000
committerGravatar Ton Voon <tonvoon@users.sourceforge.net> 2006-01-30 16:10:50 +0000
commit795100ae5124915bb647a304d5dfe2ada2f44ab0 (patch)
treeb3fd0dc1a88ebb533f074c476ee020e32877632e /plugins/utils.c
parentc8a9bf228fdd34b021796f577a404cb8b0cba1f9 (diff)
downloadmonitoring-plugins-795100ae5124915bb647a304d5dfe2ada2f44ab0.tar.gz
Added libtap tests for utils.c library functions. Removed redundant
test files git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1303 f882894a-f735-0410-b71e-b25c423dba1c
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 8b31c5a2..dbb25202 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -265,7 +265,62 @@ is_option (char *str)
return FALSE;
}
+void set_threshold_start (threshold *this, double value) {
+ this->start = value;
+ this->start_infinity = FALSE;
+}
+
+void set_threshold_end (threshold *this, double value) {
+ this->end = value;
+ this->end_infinity = FALSE;
+}
+
+threshold
+*parse_threshold (char *str) {
+ threshold *temp_threshold;
+ double start;
+ double end;
+ char *end_str;
+ temp_threshold = (threshold *) malloc(sizeof(threshold));
+
+ /* Set defaults */
+ temp_threshold->start = 0;
+ temp_threshold->start_infinity = FALSE;
+ temp_threshold->end = 0;
+ temp_threshold->end_infinity = TRUE;
+ temp_threshold->alert_on = OUTSIDE;
+
+ if (str[0] == '@') {
+ temp_threshold->alert_on = INSIDE;
+ str++;
+ }
+
+ end_str = index(str, ':');
+ if (end_str != NULL) {
+ if (str[0] == '~') {
+ temp_threshold->start_infinity = TRUE;
+ } else {
+ start = strtod(str, NULL); /* Will stop at the ':' */
+ set_threshold_start(temp_threshold, start);
+ }
+ end_str++; /* Move past the ':' */
+ } else {
+ end_str = str;
+ }
+ end = strtod(end_str, NULL);
+ if (strcmp(end_str, "") != 0) {
+ set_threshold_end(temp_threshold, end);
+ }
+
+ if (temp_threshold->start_infinity == TRUE ||
+ temp_threshold->end_infinity == TRUE ||
+ temp_threshold->start <= temp_threshold->end) {
+ return temp_threshold;
+ }
+ free(temp_threshold);
+ return NULL;
+}
#ifdef NEED_GETTIMEOFDAY
int