diff options
Diffstat (limited to 'plugins/utils.c')
| -rw-r--r-- | plugins/utils.c | 298 |
1 files changed, 153 insertions, 145 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index 6d366e3d..41fe5fcf 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
| @@ -42,54 +42,6 @@ extern const char *progname; | |||
| 42 | 42 | ||
| 43 | time_t start_time, end_time; | 43 | time_t start_time, end_time; |
| 44 | 44 | ||
| 45 | /* ************************************************************************** | ||
| 46 | * max_state(STATE_x, STATE_y) | ||
| 47 | * compares STATE_x to STATE_y and returns result based on the following | ||
| 48 | * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL | ||
| 49 | * | ||
| 50 | * Note that numerically the above does not hold | ||
| 51 | ****************************************************************************/ | ||
| 52 | |||
| 53 | int max_state(int a, int b) { | ||
| 54 | if (a == STATE_CRITICAL || b == STATE_CRITICAL) | ||
| 55 | return STATE_CRITICAL; | ||
| 56 | else if (a == STATE_WARNING || b == STATE_WARNING) | ||
| 57 | return STATE_WARNING; | ||
| 58 | else if (a == STATE_OK || b == STATE_OK) | ||
| 59 | return STATE_OK; | ||
| 60 | else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) | ||
| 61 | return STATE_UNKNOWN; | ||
| 62 | else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) | ||
| 63 | return STATE_DEPENDENT; | ||
| 64 | else | ||
| 65 | return max(a, b); | ||
| 66 | } | ||
| 67 | |||
| 68 | /* ************************************************************************** | ||
| 69 | * max_state_alt(STATE_x, STATE_y) | ||
| 70 | * compares STATE_x to STATE_y and returns result based on the following | ||
| 71 | * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL | ||
| 72 | * | ||
| 73 | * The main difference between max_state_alt and max_state it that it doesn't | ||
| 74 | * allow setting a default to UNKNOWN. It will instead prioritixe any valid | ||
| 75 | * non-OK state. | ||
| 76 | ****************************************************************************/ | ||
| 77 | |||
| 78 | int max_state_alt(int a, int b) { | ||
| 79 | if (a == STATE_CRITICAL || b == STATE_CRITICAL) | ||
| 80 | return STATE_CRITICAL; | ||
| 81 | else if (a == STATE_WARNING || b == STATE_WARNING) | ||
| 82 | return STATE_WARNING; | ||
| 83 | else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) | ||
| 84 | return STATE_UNKNOWN; | ||
| 85 | else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) | ||
| 86 | return STATE_DEPENDENT; | ||
| 87 | else if (a == STATE_OK || b == STATE_OK) | ||
| 88 | return STATE_OK; | ||
| 89 | else | ||
| 90 | return max(a, b); | ||
| 91 | } | ||
| 92 | |||
| 93 | void usage(const char *msg) { | 45 | void usage(const char *msg) { |
| 94 | printf("%s\n", msg); | 46 | printf("%s\n", msg); |
| 95 | print_usage(); | 47 | print_usage(); |
| @@ -137,41 +89,46 @@ bool is_numeric(char *number) { | |||
| 137 | char tmp[1]; | 89 | char tmp[1]; |
| 138 | float x; | 90 | float x; |
| 139 | 91 | ||
| 140 | if (!number) | 92 | if (!number) { |
| 141 | return false; | 93 | return false; |
| 142 | else if (sscanf(number, "%f%c", &x, tmp) == 1) | 94 | } else if (sscanf(number, "%f%c", &x, tmp) == 1) { |
| 143 | return true; | 95 | return true; |
| 144 | else | 96 | } else { |
| 145 | return false; | 97 | return false; |
| 98 | } | ||
| 146 | } | 99 | } |
| 147 | 100 | ||
| 148 | bool is_positive(char *number) { | 101 | bool is_positive(char *number) { |
| 149 | if (is_numeric(number) && atof(number) > 0.0) | 102 | if (is_numeric(number) && atof(number) > 0.0) { |
| 150 | return true; | 103 | return true; |
| 151 | else | 104 | } else { |
| 152 | return false; | 105 | return false; |
| 106 | } | ||
| 153 | } | 107 | } |
| 154 | 108 | ||
| 155 | bool is_negative(char *number) { | 109 | bool is_negative(char *number) { |
| 156 | if (is_numeric(number) && atof(number) < 0.0) | 110 | if (is_numeric(number) && atof(number) < 0.0) { |
| 157 | return true; | 111 | return true; |
| 158 | else | 112 | } else { |
| 159 | return false; | 113 | return false; |
| 114 | } | ||
| 160 | } | 115 | } |
| 161 | 116 | ||
| 162 | bool is_nonnegative(char *number) { | 117 | bool is_nonnegative(char *number) { |
| 163 | if (is_numeric(number) && atof(number) >= 0.0) | 118 | if (is_numeric(number) && atof(number) >= 0.0) { |
| 164 | return true; | 119 | return true; |
| 165 | else | 120 | } else { |
| 166 | return false; | 121 | return false; |
| 122 | } | ||
| 167 | } | 123 | } |
| 168 | 124 | ||
| 169 | bool is_percentage(char *number) { | 125 | bool is_percentage(char *number) { |
| 170 | int x; | 126 | int x; |
| 171 | if (is_numeric(number) && (x = atof(number)) >= 0 && x <= 100) | 127 | if (is_numeric(number) && (x = atof(number)) >= 0 && x <= 100) { |
| 172 | return true; | 128 | return true; |
| 173 | else | 129 | } else { |
| 174 | return false; | 130 | return false; |
| 131 | } | ||
| 175 | } | 132 | } |
| 176 | 133 | ||
| 177 | bool is_percentage_expression(const char str[]) { | 134 | bool is_percentage_expression(const char str[]) { |
| @@ -204,36 +161,41 @@ bool is_percentage_expression(const char str[]) { | |||
| 204 | bool is_integer(char *number) { | 161 | bool is_integer(char *number) { |
| 205 | long int n; | 162 | long int n; |
| 206 | 163 | ||
| 207 | if (!number || (strspn(number, "-0123456789 ") != strlen(number))) | 164 | if (!number || (strspn(number, "-0123456789 ") != strlen(number))) { |
| 208 | return false; | 165 | return false; |
| 166 | } | ||
| 209 | 167 | ||
| 210 | n = strtol(number, NULL, 10); | 168 | n = strtol(number, NULL, 10); |
| 211 | 169 | ||
| 212 | if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX) | 170 | if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX) { |
| 213 | return true; | 171 | return true; |
| 214 | else | 172 | } else { |
| 215 | return false; | 173 | return false; |
| 174 | } | ||
| 216 | } | 175 | } |
| 217 | 176 | ||
| 218 | bool is_intpos(char *number) { | 177 | bool is_intpos(char *number) { |
| 219 | if (is_integer(number) && atoi(number) > 0) | 178 | if (is_integer(number) && atoi(number) > 0) { |
| 220 | return true; | 179 | return true; |
| 221 | else | 180 | } else { |
| 222 | return false; | 181 | return false; |
| 182 | } | ||
| 223 | } | 183 | } |
| 224 | 184 | ||
| 225 | bool is_intneg(char *number) { | 185 | bool is_intneg(char *number) { |
| 226 | if (is_integer(number) && atoi(number) < 0) | 186 | if (is_integer(number) && atoi(number) < 0) { |
| 227 | return true; | 187 | return true; |
| 228 | else | 188 | } else { |
| 229 | return false; | 189 | return false; |
| 190 | } | ||
| 230 | } | 191 | } |
| 231 | 192 | ||
| 232 | bool is_intnonneg(char *number) { | 193 | bool is_intnonneg(char *number) { |
| 233 | if (is_integer(number) && atoi(number) >= 0) | 194 | if (is_integer(number) && atoi(number) >= 0) { |
| 234 | return true; | 195 | return true; |
| 235 | else | 196 | } else { |
| 236 | return false; | 197 | return false; |
| 198 | } | ||
| 237 | } | 199 | } |
| 238 | 200 | ||
| 239 | /* | 201 | /* |
| @@ -295,19 +257,21 @@ bool is_uint64(char *number, uint64_t *target) { | |||
| 295 | 257 | ||
| 296 | bool is_intpercent(char *number) { | 258 | bool is_intpercent(char *number) { |
| 297 | int i; | 259 | int i; |
| 298 | if (is_integer(number) && (i = atoi(number)) >= 0 && i <= 100) | 260 | if (is_integer(number) && (i = atoi(number)) >= 0 && i <= 100) { |
| 299 | return true; | 261 | return true; |
| 300 | else | 262 | } else { |
| 301 | return false; | 263 | return false; |
| 264 | } | ||
| 302 | } | 265 | } |
| 303 | 266 | ||
| 304 | bool is_option(char *str) { | 267 | bool is_option(char *str) { |
| 305 | if (!str) | 268 | if (!str) { |
| 306 | return false; | 269 | return false; |
| 307 | else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) | 270 | } else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) { |
| 308 | return true; | 271 | return true; |
| 309 | else | 272 | } else { |
| 310 | return false; | 273 | return false; |
| 274 | } | ||
| 311 | } | 275 | } |
| 312 | 276 | ||
| 313 | #ifdef NEED_GETTIMEOFDAY | 277 | #ifdef NEED_GETTIMEOFDAY |
| @@ -321,7 +285,8 @@ double delta_time(struct timeval tv) { | |||
| 321 | struct timeval now; | 285 | struct timeval now; |
| 322 | 286 | ||
| 323 | gettimeofday(&now, NULL); | 287 | gettimeofday(&now, NULL); |
| 324 | return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000); | 288 | return ((double)(now.tv_sec - tv.tv_sec) + |
| 289 | (double)(now.tv_usec - tv.tv_usec) / (double)1000000); | ||
| 325 | } | 290 | } |
| 326 | 291 | ||
| 327 | long deltime(struct timeval tv) { | 292 | long deltime(struct timeval tv) { |
| @@ -336,10 +301,11 @@ void strip(char *buffer) { | |||
| 336 | 301 | ||
| 337 | for (x = strlen(buffer); x >= 1; x--) { | 302 | for (x = strlen(buffer); x >= 1; x--) { |
| 338 | i = x - 1; | 303 | i = x - 1; |
| 339 | if (buffer[i] == ' ' || buffer[i] == '\r' || buffer[i] == '\n' || buffer[i] == '\t') | 304 | if (buffer[i] == ' ' || buffer[i] == '\r' || buffer[i] == '\n' || buffer[i] == '\t') { |
| 340 | buffer[i] = '\0'; | 305 | buffer[i] = '\0'; |
| 341 | else | 306 | } else { |
| 342 | break; | 307 | break; |
| 308 | } | ||
| 343 | } | 309 | } |
| 344 | return; | 310 | return; |
| 345 | } | 311 | } |
| @@ -357,8 +323,9 @@ void strip(char *buffer) { | |||
| 357 | *****************************************************************************/ | 323 | *****************************************************************************/ |
| 358 | 324 | ||
| 359 | char *strscpy(char *dest, const char *src) { | 325 | char *strscpy(char *dest, const char *src) { |
| 360 | if (src == NULL) | 326 | if (src == NULL) { |
| 361 | return NULL; | 327 | return NULL; |
| 328 | } | ||
| 362 | 329 | ||
| 363 | xasprintf(&dest, "%s", src); | 330 | xasprintf(&dest, "%s", src); |
| 364 | 331 | ||
| @@ -417,17 +384,21 @@ char *strscpy(char *dest, const char *src) { | |||
| 417 | 384 | ||
| 418 | char *strnl(char *str) { | 385 | char *strnl(char *str) { |
| 419 | size_t len; | 386 | size_t len; |
| 420 | if (str == NULL) | 387 | if (str == NULL) { |
| 421 | return NULL; | 388 | return NULL; |
| 389 | } | ||
| 422 | str = strpbrk(str, "\r\n"); | 390 | str = strpbrk(str, "\r\n"); |
| 423 | if (str == NULL) | 391 | if (str == NULL) { |
| 424 | return NULL; | 392 | return NULL; |
| 393 | } | ||
| 425 | len = strspn(str, "\r\n"); | 394 | len = strspn(str, "\r\n"); |
| 426 | if (str[len] == '\0') | 395 | if (str[len] == '\0') { |
| 427 | return NULL; | 396 | return NULL; |
| 397 | } | ||
| 428 | str += len; | 398 | str += len; |
| 429 | if (strlen(str) == 0) | 399 | if (strlen(str) == 0) { |
| 430 | return NULL; | 400 | return NULL; |
| 401 | } | ||
| 431 | return str; | 402 | return str; |
| 432 | } | 403 | } |
| 433 | 404 | ||
| @@ -450,15 +421,18 @@ char *strnl(char *str) { | |||
| 450 | char *strpcpy(char *dest, const char *src, const char *str) { | 421 | char *strpcpy(char *dest, const char *src, const char *str) { |
| 451 | size_t len; | 422 | size_t len; |
| 452 | 423 | ||
| 453 | if (src) | 424 | if (src) { |
| 454 | len = strcspn(src, str); | 425 | len = strcspn(src, str); |
| 455 | else | 426 | } else { |
| 456 | return NULL; | 427 | return NULL; |
| 428 | } | ||
| 457 | 429 | ||
| 458 | if (dest == NULL || strlen(dest) < len) | 430 | if (dest == NULL || strlen(dest) < len) { |
| 459 | dest = realloc(dest, len + 1); | 431 | dest = realloc(dest, len + 1); |
| 460 | if (dest == NULL) | 432 | } |
| 433 | if (dest == NULL) { | ||
| 461 | die(STATE_UNKNOWN, _("failed realloc in strpcpy\n")); | 434 | die(STATE_UNKNOWN, _("failed realloc in strpcpy\n")); |
| 435 | } | ||
| 462 | 436 | ||
| 463 | strncpy(dest, src, len); | 437 | strncpy(dest, src, len); |
| 464 | dest[len] = '\0'; | 438 | dest[len] = '\0'; |
| @@ -482,10 +456,11 @@ char *strpcpy(char *dest, const char *src, const char *str) { | |||
| 482 | char *strpcat(char *dest, const char *src, const char *str) { | 456 | char *strpcat(char *dest, const char *src, const char *str) { |
| 483 | size_t len, l2; | 457 | size_t len, l2; |
| 484 | 458 | ||
| 485 | if (dest) | 459 | if (dest) { |
| 486 | len = strlen(dest); | 460 | len = strlen(dest); |
| 487 | else | 461 | } else { |
| 488 | len = 0; | 462 | len = 0; |
| 463 | } | ||
| 489 | 464 | ||
| 490 | if (src) { | 465 | if (src) { |
| 491 | l2 = strcspn(src, str); | 466 | l2 = strcspn(src, str); |
| @@ -494,8 +469,9 @@ char *strpcat(char *dest, const char *src, const char *str) { | |||
| 494 | } | 469 | } |
| 495 | 470 | ||
| 496 | dest = realloc(dest, len + l2 + 1); | 471 | dest = realloc(dest, len + l2 + 1); |
| 497 | if (dest == NULL) | 472 | if (dest == NULL) { |
| 498 | die(STATE_UNKNOWN, _("failed malloc in strscat\n")); | 473 | die(STATE_UNKNOWN, _("failed malloc in strscat\n")); |
| 474 | } | ||
| 499 | 475 | ||
| 500 | strncpy(dest + len, src, l2); | 476 | strncpy(dest + len, src, l2); |
| 501 | dest[len + l2] = '\0'; | 477 | dest[len + l2] = '\0'; |
| @@ -511,8 +487,9 @@ char *strpcat(char *dest, const char *src, const char *str) { | |||
| 511 | 487 | ||
| 512 | int xvasprintf(char **strp, const char *fmt, va_list ap) { | 488 | int xvasprintf(char **strp, const char *fmt, va_list ap) { |
| 513 | int result = vasprintf(strp, fmt, ap); | 489 | int result = vasprintf(strp, fmt, ap); |
| 514 | if (result == -1 || *strp == NULL) | 490 | if (result == -1 || *strp == NULL) { |
| 515 | die(STATE_UNKNOWN, _("failed malloc in xvasprintf\n")); | 491 | die(STATE_UNKNOWN, _("failed malloc in xvasprintf\n")); |
| 492 | } | ||
| 516 | return result; | 493 | return result; |
| 517 | } | 494 | } |
| 518 | 495 | ||
| @@ -531,126 +508,147 @@ int xasprintf(char **strp, const char *fmt, ...) { | |||
| 531 | * | 508 | * |
| 532 | ******************************************************************************/ | 509 | ******************************************************************************/ |
| 533 | 510 | ||
| 534 | char *perfdata(const char *label, long int val, const char *uom, int warnp, long int warn, int critp, long int crit, int minp, | 511 | char *perfdata(const char *label, long int val, const char *uom, bool warnp, long int warn, |
| 535 | long int minv, int maxp, long int maxv) { | 512 | bool critp, long int crit, bool minp, long int minv, bool maxp, long int maxv) { |
| 536 | char *data = NULL; | 513 | char *data = NULL; |
| 537 | 514 | ||
| 538 | if (strpbrk(label, "'= ")) | 515 | if (strpbrk(label, "'= ")) { |
| 539 | xasprintf(&data, "'%s'=%ld%s;", label, val, uom); | 516 | xasprintf(&data, "'%s'=%ld%s;", label, val, uom); |
| 540 | else | 517 | } else { |
| 541 | xasprintf(&data, "%s=%ld%s;", label, val, uom); | 518 | xasprintf(&data, "%s=%ld%s;", label, val, uom); |
| 519 | } | ||
| 542 | 520 | ||
| 543 | if (warnp) | 521 | if (warnp) { |
| 544 | xasprintf(&data, "%s%ld;", data, warn); | 522 | xasprintf(&data, "%s%ld;", data, warn); |
| 545 | else | 523 | } else { |
| 546 | xasprintf(&data, "%s;", data); | 524 | xasprintf(&data, "%s;", data); |
| 525 | } | ||
| 547 | 526 | ||
| 548 | if (critp) | 527 | if (critp) { |
| 549 | xasprintf(&data, "%s%ld;", data, crit); | 528 | xasprintf(&data, "%s%ld;", data, crit); |
| 550 | else | 529 | } else { |
| 551 | xasprintf(&data, "%s;", data); | 530 | xasprintf(&data, "%s;", data); |
| 531 | } | ||
| 552 | 532 | ||
| 553 | if (minp) | 533 | if (minp) { |
| 554 | xasprintf(&data, "%s%ld;", data, minv); | 534 | xasprintf(&data, "%s%ld;", data, minv); |
| 555 | else | 535 | } else { |
| 556 | xasprintf(&data, "%s;", data); | 536 | xasprintf(&data, "%s;", data); |
| 537 | } | ||
| 557 | 538 | ||
| 558 | if (maxp) | 539 | if (maxp) { |
| 559 | xasprintf(&data, "%s%ld", data, maxv); | 540 | xasprintf(&data, "%s%ld", data, maxv); |
| 541 | } | ||
| 560 | 542 | ||
| 561 | return data; | 543 | return data; |
| 562 | } | 544 | } |
| 563 | 545 | ||
| 564 | char *perfdata_uint64(const char *label, uint64_t val, const char *uom, int warnp, /* Warning present */ | 546 | char *perfdata_uint64(const char *label, uint64_t val, const char *uom, |
| 565 | uint64_t warn, int critp, /* Critical present */ | 547 | bool warnp, /* Warning present */ |
| 566 | uint64_t crit, int minp, /* Minimum present */ | 548 | uint64_t warn, bool critp, /* Critical present */ |
| 567 | uint64_t minv, int maxp, /* Maximum present */ | 549 | uint64_t crit, bool minp, /* Minimum present */ |
| 550 | uint64_t minv, bool maxp, /* Maximum present */ | ||
| 568 | uint64_t maxv) { | 551 | uint64_t maxv) { |
| 569 | char *data = NULL; | 552 | char *data = NULL; |
| 570 | 553 | ||
| 571 | if (strpbrk(label, "'= ")) | 554 | if (strpbrk(label, "'= ")) { |
| 572 | xasprintf(&data, "'%s'=%" PRIu64 "%s;", label, val, uom); | 555 | xasprintf(&data, "'%s'=%" PRIu64 "%s;", label, val, uom); |
| 573 | else | 556 | } else { |
| 574 | xasprintf(&data, "%s=%" PRIu64 "%s;", label, val, uom); | 557 | xasprintf(&data, "%s=%" PRIu64 "%s;", label, val, uom); |
| 558 | } | ||
| 575 | 559 | ||
| 576 | if (warnp) | 560 | if (warnp) { |
| 577 | xasprintf(&data, "%s%" PRIu64 ";", data, warn); | 561 | xasprintf(&data, "%s%" PRIu64 ";", data, warn); |
| 578 | else | 562 | } else { |
| 579 | xasprintf(&data, "%s;", data); | 563 | xasprintf(&data, "%s;", data); |
| 564 | } | ||
| 580 | 565 | ||
| 581 | if (critp) | 566 | if (critp) { |
| 582 | xasprintf(&data, "%s%" PRIu64 ";", data, crit); | 567 | xasprintf(&data, "%s%" PRIu64 ";", data, crit); |
| 583 | else | 568 | } else { |
| 584 | xasprintf(&data, "%s;", data); | 569 | xasprintf(&data, "%s;", data); |
| 570 | } | ||
| 585 | 571 | ||
| 586 | if (minp) | 572 | if (minp) { |
| 587 | xasprintf(&data, "%s%" PRIu64 ";", data, minv); | 573 | xasprintf(&data, "%s%" PRIu64 ";", data, minv); |
| 588 | else | 574 | } else { |
| 589 | xasprintf(&data, "%s;", data); | 575 | xasprintf(&data, "%s;", data); |
| 576 | } | ||
| 590 | 577 | ||
| 591 | if (maxp) | 578 | if (maxp) { |
| 592 | xasprintf(&data, "%s%" PRIu64, data, maxv); | 579 | xasprintf(&data, "%s%" PRIu64, data, maxv); |
| 580 | } | ||
| 593 | 581 | ||
| 594 | return data; | 582 | return data; |
| 595 | } | 583 | } |
| 596 | 584 | ||
| 597 | char *perfdata_int64(const char *label, int64_t val, const char *uom, int warnp, /* Warning present */ | 585 | char *perfdata_int64(const char *label, int64_t val, const char *uom, |
| 598 | int64_t warn, int critp, /* Critical present */ | 586 | bool warnp, /* Warning present */ |
| 599 | int64_t crit, int minp, /* Minimum present */ | 587 | int64_t warn, bool critp, /* Critical present */ |
| 600 | int64_t minv, int maxp, /* Maximum present */ | 588 | int64_t crit, bool minp, /* Minimum present */ |
| 589 | int64_t minv, bool maxp, /* Maximum present */ | ||
| 601 | int64_t maxv) { | 590 | int64_t maxv) { |
| 602 | char *data = NULL; | 591 | char *data = NULL; |
| 603 | 592 | ||
| 604 | if (strpbrk(label, "'= ")) | 593 | if (strpbrk(label, "'= ")) { |
| 605 | xasprintf(&data, "'%s'=%" PRId64 "%s;", label, val, uom); | 594 | xasprintf(&data, "'%s'=%" PRId64 "%s;", label, val, uom); |
| 606 | else | 595 | } else { |
| 607 | xasprintf(&data, "%s=%" PRId64 "%s;", label, val, uom); | 596 | xasprintf(&data, "%s=%" PRId64 "%s;", label, val, uom); |
| 597 | } | ||
| 608 | 598 | ||
| 609 | if (warnp) | 599 | if (warnp) { |
| 610 | xasprintf(&data, "%s%" PRId64 ";", data, warn); | 600 | xasprintf(&data, "%s%" PRId64 ";", data, warn); |
| 611 | else | 601 | } else { |
| 612 | xasprintf(&data, "%s;", data); | 602 | xasprintf(&data, "%s;", data); |
| 603 | } | ||
| 613 | 604 | ||
| 614 | if (critp) | 605 | if (critp) { |
| 615 | xasprintf(&data, "%s%" PRId64 ";", data, crit); | 606 | xasprintf(&data, "%s%" PRId64 ";", data, crit); |
| 616 | else | 607 | } else { |
| 617 | xasprintf(&data, "%s;", data); | 608 | xasprintf(&data, "%s;", data); |
| 609 | } | ||
| 618 | 610 | ||
| 619 | if (minp) | 611 | if (minp) { |
| 620 | xasprintf(&data, "%s%" PRId64 ";", data, minv); | 612 | xasprintf(&data, "%s%" PRId64 ";", data, minv); |
| 621 | else | 613 | } else { |
| 622 | xasprintf(&data, "%s;", data); | 614 | xasprintf(&data, "%s;", data); |
| 615 | } | ||
| 623 | 616 | ||
| 624 | if (maxp) | 617 | if (maxp) { |
| 625 | xasprintf(&data, "%s%" PRId64, data, maxv); | 618 | xasprintf(&data, "%s%" PRId64, data, maxv); |
| 619 | } | ||
| 626 | 620 | ||
| 627 | return data; | 621 | return data; |
| 628 | } | 622 | } |
| 629 | 623 | ||
| 630 | char *fperfdata(const char *label, double val, const char *uom, int warnp, double warn, int critp, double crit, int minp, double minv, | 624 | char *fperfdata(const char *label, double val, const char *uom, bool warnp, double warn, bool critp, |
| 631 | int maxp, double maxv) { | 625 | double crit, bool minp, double minv, bool maxp, double maxv) { |
| 632 | char *data = NULL; | 626 | char *data = NULL; |
| 633 | 627 | ||
| 634 | if (strpbrk(label, "'= ")) | 628 | if (strpbrk(label, "'= ")) { |
| 635 | xasprintf(&data, "'%s'=", label); | 629 | xasprintf(&data, "'%s'=", label); |
| 636 | else | 630 | } else { |
| 637 | xasprintf(&data, "%s=", label); | 631 | xasprintf(&data, "%s=", label); |
| 632 | } | ||
| 638 | 633 | ||
| 639 | xasprintf(&data, "%s%f", data, val); | 634 | xasprintf(&data, "%s%f", data, val); |
| 640 | xasprintf(&data, "%s%s;", data, uom); | 635 | xasprintf(&data, "%s%s;", data, uom); |
| 641 | 636 | ||
| 642 | if (warnp) | 637 | if (warnp) { |
| 643 | xasprintf(&data, "%s%f", data, warn); | 638 | xasprintf(&data, "%s%f", data, warn); |
| 639 | } | ||
| 644 | 640 | ||
| 645 | xasprintf(&data, "%s;", data); | 641 | xasprintf(&data, "%s;", data); |
| 646 | 642 | ||
| 647 | if (critp) | 643 | if (critp) { |
| 648 | xasprintf(&data, "%s%f", data, crit); | 644 | xasprintf(&data, "%s%f", data, crit); |
| 645 | } | ||
| 649 | 646 | ||
| 650 | xasprintf(&data, "%s;", data); | 647 | xasprintf(&data, "%s;", data); |
| 651 | 648 | ||
| 652 | if (minp) | 649 | if (minp) { |
| 653 | xasprintf(&data, "%s%f", data, minv); | 650 | xasprintf(&data, "%s%f", data, minv); |
| 651 | } | ||
| 654 | 652 | ||
| 655 | if (maxp) { | 653 | if (maxp) { |
| 656 | xasprintf(&data, "%s;", data); | 654 | xasprintf(&data, "%s;", data); |
| @@ -660,28 +658,33 @@ char *fperfdata(const char *label, double val, const char *uom, int warnp, doubl | |||
| 660 | return data; | 658 | return data; |
| 661 | } | 659 | } |
| 662 | 660 | ||
| 663 | char *sperfdata(const char *label, double val, const char *uom, char *warn, char *crit, int minp, double minv, int maxp, double maxv) { | 661 | char *sperfdata(const char *label, double val, const char *uom, char *warn, char *crit, bool minp, |
| 662 | double minv, bool maxp, double maxv) { | ||
| 664 | char *data = NULL; | 663 | char *data = NULL; |
| 665 | if (strpbrk(label, "'= ")) | 664 | if (strpbrk(label, "'= ")) { |
| 666 | xasprintf(&data, "'%s'=", label); | 665 | xasprintf(&data, "'%s'=", label); |
| 667 | else | 666 | } else { |
| 668 | xasprintf(&data, "%s=", label); | 667 | xasprintf(&data, "%s=", label); |
| 668 | } | ||
| 669 | 669 | ||
| 670 | xasprintf(&data, "%s%f", data, val); | 670 | xasprintf(&data, "%s%f", data, val); |
| 671 | xasprintf(&data, "%s%s;", data, uom); | 671 | xasprintf(&data, "%s%s;", data, uom); |
| 672 | 672 | ||
| 673 | if (warn != NULL) | 673 | if (warn != NULL) { |
| 674 | xasprintf(&data, "%s%s", data, warn); | 674 | xasprintf(&data, "%s%s", data, warn); |
| 675 | } | ||
| 675 | 676 | ||
| 676 | xasprintf(&data, "%s;", data); | 677 | xasprintf(&data, "%s;", data); |
| 677 | 678 | ||
| 678 | if (crit != NULL) | 679 | if (crit != NULL) { |
| 679 | xasprintf(&data, "%s%s", data, crit); | 680 | xasprintf(&data, "%s%s", data, crit); |
| 681 | } | ||
| 680 | 682 | ||
| 681 | xasprintf(&data, "%s;", data); | 683 | xasprintf(&data, "%s;", data); |
| 682 | 684 | ||
| 683 | if (minp) | 685 | if (minp) { |
| 684 | xasprintf(&data, "%s%f", data, minv); | 686 | xasprintf(&data, "%s%f", data, minv); |
| 687 | } | ||
| 685 | 688 | ||
| 686 | if (maxp) { | 689 | if (maxp) { |
| 687 | xasprintf(&data, "%s;", data); | 690 | xasprintf(&data, "%s;", data); |
| @@ -691,28 +694,33 @@ char *sperfdata(const char *label, double val, const char *uom, char *warn, char | |||
| 691 | return data; | 694 | return data; |
| 692 | } | 695 | } |
| 693 | 696 | ||
| 694 | char *sperfdata_int(const char *label, int val, const char *uom, char *warn, char *crit, int minp, int minv, int maxp, int maxv) { | 697 | char *sperfdata_int(const char *label, int val, const char *uom, char *warn, char *crit, bool minp, |
| 698 | int minv, bool maxp, int maxv) { | ||
| 695 | char *data = NULL; | 699 | char *data = NULL; |
| 696 | if (strpbrk(label, "'= ")) | 700 | if (strpbrk(label, "'= ")) { |
| 697 | xasprintf(&data, "'%s'=", label); | 701 | xasprintf(&data, "'%s'=", label); |
| 698 | else | 702 | } else { |
| 699 | xasprintf(&data, "%s=", label); | 703 | xasprintf(&data, "%s=", label); |
| 704 | } | ||
| 700 | 705 | ||
| 701 | xasprintf(&data, "%s%d", data, val); | 706 | xasprintf(&data, "%s%d", data, val); |
| 702 | xasprintf(&data, "%s%s;", data, uom); | 707 | xasprintf(&data, "%s%s;", data, uom); |
| 703 | 708 | ||
| 704 | if (warn != NULL) | 709 | if (warn != NULL) { |
| 705 | xasprintf(&data, "%s%s", data, warn); | 710 | xasprintf(&data, "%s%s", data, warn); |
| 711 | } | ||
| 706 | 712 | ||
| 707 | xasprintf(&data, "%s;", data); | 713 | xasprintf(&data, "%s;", data); |
| 708 | 714 | ||
| 709 | if (crit != NULL) | 715 | if (crit != NULL) { |
| 710 | xasprintf(&data, "%s%s", data, crit); | 716 | xasprintf(&data, "%s%s", data, crit); |
| 717 | } | ||
| 711 | 718 | ||
| 712 | xasprintf(&data, "%s;", data); | 719 | xasprintf(&data, "%s;", data); |
| 713 | 720 | ||
| 714 | if (minp) | 721 | if (minp) { |
| 715 | xasprintf(&data, "%s%d", data, minv); | 722 | xasprintf(&data, "%s%d", data, minv); |
| 723 | } | ||
| 716 | 724 | ||
| 717 | if (maxp) { | 725 | if (maxp) { |
| 718 | xasprintf(&data, "%s;", data); | 726 | xasprintf(&data, "%s;", data); |
