Code

initial version of ini file parsing routines in C
[nagiosplug.git] / lib / utils_base.c
index 3dae32fbf337636a2b953affa9414cb7fb0697c6..db21ea15b47a746d0762fddca98129a4b1ce589b 100644 (file)
@@ -96,12 +96,12 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st
 
        if (warn_string != NULL) {
                if ((temp_thresholds->warning = parse_range_string(warn_string)) == NULL) {
-                       return 1;
+                       return NP_RANGE_UNPARSEABLE;
                }
        }
        if (critical_string != NULL) {
                if ((temp_thresholds->critical = parse_range_string(critical_string)) == NULL) {
-                       return 1;
+                       return NP_RANGE_UNPARSEABLE;
                }
        }
 
@@ -117,10 +117,14 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st
 void
 set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string)
 {
-       if (_set_thresholds(my_thresholds, warn_string, critical_string) == 0) {
+       switch (_set_thresholds(my_thresholds, warn_string, critical_string)) {
+       case 0:
                return;
-       } else {
+       case NP_RANGE_UNPARSEABLE:
                die(STATE_UNKNOWN, _("Range format incorrect"));
+       case NP_WARN_WITHIN_CRIT:
+               die(STATE_UNKNOWN, _("Warning level is a subset of critical and will not be alerted"));
+               break;
        }
 }
 
@@ -147,34 +151,34 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) {
 int
 check_range(double value, range *my_range)
 {
-       int false = FALSE;
-       int true = TRUE;
+       int no = FALSE;
+       int yes = TRUE;
        
        if (my_range->alert_on == INSIDE) {
-               false = TRUE;
-               true = FALSE;
+               no = TRUE;
+               yes = FALSE;
        }
 
        if (my_range->end_infinity == FALSE && my_range->start_infinity == FALSE) {
                if ((my_range->start <= value) && (value <= my_range->end)) {
-                       return false;
+                       return no;
                } else {
-                       return true;
+                       return yes;
                }
        } else if (my_range->start_infinity == FALSE && my_range->end_infinity == TRUE) {
                if (my_range->start <= value) {
-                       return false;
+                       return no;
                } else {
-                       return true;
+                       return yes;
                }
        } else if (my_range->start_infinity == TRUE && my_range->end_infinity == FALSE) {
                if (value <= my_range->end) {
-                       return false;
+                       return no;
                } else {
-                       return true;
+                       return yes;
                }
        } else {
-               return false;
+               return no;
        }
 }