| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "common.h" |
| 25 |
#include "logging.h" |
| 26 |
#include "system.h" |
| 27 |
#include "thresholds.h" |
| 28 |
#include "units.h" |
| 29 |
|
| 30 |
int |
| 31 |
get_perfdata_limit (range * threshold, unsigned long base, |
| 32 |
unsigned long long *limit, bool percent) |
| 33 |
{ |
| 34 |
if (NULL == threshold) |
| 35 |
return -1; |
| 36 |
|
| 37 |
double threshold_limit; |
| 38 |
|
| 39 |
if (NP_RANGE_INSIDE == threshold->alert_on) |
| 40 |
{ |
| 41 |
|
| 42 |
dbg ("threshold {%g, %g} with alert_on set to true\n", |
| 43 |
threshold->start, threshold->end); |
| 44 |
return -1; |
| 45 |
} |
| 46 |
else if (threshold->start_infinity) |
| 47 |
{ |
| 48 |
|
| 49 |
dbg ("threshold {%g, %g} with start_infinity set to true\n", |
| 50 |
threshold->start, threshold->end); |
| 51 |
return -1; |
| 52 |
} |
| 53 |
else if (threshold->end_infinity) |
| 54 |
{ |
| 55 |
|
| 56 |
dbg ("threshold {%g, %g} with end_infinity set to true\n", |
| 57 |
threshold->start, threshold->end); |
| 58 |
threshold_limit = threshold->start; |
| 59 |
} |
| 60 |
else |
| 61 |
{ |
| 62 |
|
| 63 |
|
| 64 |
dbg ("threshold {%g, %g}\n", threshold->start, threshold->end); |
| 65 |
threshold_limit = threshold->end; |
| 66 |
} |
| 67 |
|
| 68 |
*limit = (unsigned long long) (base * threshold_limit); |
| 69 |
if (percent) |
| 70 |
*limit = (unsigned long long) (*limit / 100.0); |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
int |
| 76 |
get_perfdata_limit_converted (range * threshold, unsigned long base, |
| 77 |
int shift, unsigned long long *limit, |
| 78 |
bool percent) |
| 79 |
{ |
| 80 |
int error = get_perfdata_limit (threshold, base, limit, percent); |
| 81 |
if (0 != error) |
| 82 |
return error; |
| 83 |
|
| 84 |
*limit = UNIT_CONVERT (*limit, shift); |
| 85 |
return 0; |
| 86 |
} |