diff options
| -rw-r--r-- | lib/utils_base.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c index 1e92b29b..5ba865c9 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
| @@ -33,12 +33,12 @@ | |||
| 33 | #include <unistd.h> | 33 | #include <unistd.h> |
| 34 | #include <sys/types.h> | 34 | #include <sys/types.h> |
| 35 | 35 | ||
| 36 | #define np_free(ptr) \ | 36 | #define np_free(ptr) \ |
| 37 | { \ | 37 | { \ |
| 38 | if (ptr) { \ | 38 | if (ptr) { \ |
| 39 | free(ptr); \ | 39 | free(ptr); \ |
| 40 | ptr = NULL; \ | 40 | ptr = NULL; \ |
| 41 | } \ | 41 | } \ |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | monitoring_plugin *this_monitoring_plugin = NULL; | 44 | monitoring_plugin *this_monitoring_plugin = NULL; |
| @@ -153,7 +153,8 @@ range *parse_range_string(char *str) { | |||
| 153 | set_range_end(temp_range, end); | 153 | set_range_end(temp_range, end); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | if (temp_range->start_infinity == true || temp_range->end_infinity == true || temp_range->start <= temp_range->end) { | 156 | if (temp_range->start_infinity == true || temp_range->end_infinity == true || |
| 157 | temp_range->start <= temp_range->end) { | ||
| 157 | return temp_range; | 158 | return temp_range; |
| 158 | } | 159 | } |
| 159 | free(temp_range); | 160 | free(temp_range); |
| @@ -205,12 +206,14 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) { | |||
| 205 | printf("Threshold not set"); | 206 | printf("Threshold not set"); |
| 206 | } else { | 207 | } else { |
| 207 | if (my_threshold->warning) { | 208 | if (my_threshold->warning) { |
| 208 | printf("Warning: start=%g end=%g; ", my_threshold->warning->start, my_threshold->warning->end); | 209 | printf("Warning: start=%g end=%g; ", my_threshold->warning->start, |
| 210 | my_threshold->warning->end); | ||
| 209 | } else { | 211 | } else { |
| 210 | printf("Warning not set; "); | 212 | printf("Warning not set; "); |
| 211 | } | 213 | } |
| 212 | if (my_threshold->critical) { | 214 | if (my_threshold->critical) { |
| 213 | printf("Critical: start=%g end=%g", my_threshold->critical->start, my_threshold->critical->end); | 215 | printf("Critical: start=%g end=%g", my_threshold->critical->start, |
| 216 | my_threshold->critical->end); | ||
| 214 | } else { | 217 | } else { |
| 215 | printf("Critical not set"); | 218 | printf("Critical not set"); |
| 216 | } | 219 | } |
| @@ -225,7 +228,8 @@ bool mp_check_range(const mp_perfdata_value value, const mp_range my_range) { | |||
| 225 | if (!my_range.end_infinity && !my_range.start_infinity) { | 228 | if (!my_range.end_infinity && !my_range.start_infinity) { |
| 226 | // range: .........|---inside---|........... | 229 | // range: .........|---inside---|........... |
| 227 | // value | 230 | // value |
| 228 | is_inside = ((cmp_perfdata_value(value, my_range.start) >= 0) && (cmp_perfdata_value(value, my_range.end) <= 0)); | 231 | is_inside = ((cmp_perfdata_value(value, my_range.start) >= 0) && |
| 232 | (cmp_perfdata_value(value, my_range.end) <= 0)); | ||
| 229 | } else if (!my_range.start_infinity && my_range.end_infinity) { | 233 | } else if (!my_range.start_infinity && my_range.end_infinity) { |
| 230 | // range: .........|---inside--------- | 234 | // range: .........|---inside--------- |
| 231 | // value | 235 | // value |
| @@ -239,7 +243,8 @@ bool mp_check_range(const mp_perfdata_value value, const mp_range my_range) { | |||
| 239 | is_inside = true; | 243 | is_inside = true; |
| 240 | } | 244 | } |
| 241 | 245 | ||
| 242 | if ((is_inside && my_range.alert_on_inside_range == INSIDE) || (!is_inside && my_range.alert_on_inside_range == OUTSIDE)) { | 246 | if ((is_inside && my_range.alert_on_inside_range == INSIDE) || |
| 247 | (!is_inside && my_range.alert_on_inside_range == OUTSIDE)) { | ||
| 243 | return true; | 248 | return true; |
| 244 | } | 249 | } |
| 245 | 250 | ||
| @@ -557,8 +562,8 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
| 557 | this_state->state_data = NULL; | 562 | this_state->state_data = NULL; |
| 558 | 563 | ||
| 559 | /* Calculate filename */ | 564 | /* Calculate filename */ |
| 560 | ret = asprintf(&temp_filename, "%s/%lu/%s/%s", _np_state_calculate_location_prefix(), (unsigned long)geteuid(), | 565 | ret = asprintf(&temp_filename, "%s/%lu/%s/%s", _np_state_calculate_location_prefix(), |
| 561 | this_monitoring_plugin->plugin_name, this_state->name); | 566 | (unsigned long)geteuid(), this_monitoring_plugin->plugin_name, this_state->name); |
| 562 | if (ret < 0) { | 567 | if (ret < 0) { |
| 563 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); | 568 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
| 564 | } | 569 | } |
