diff options
-rw-r--r-- | plugins/utils.c | 44 | ||||
-rw-r--r-- | plugins/utils.h | 12 |
2 files changed, 56 insertions, 0 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index 5c809ec..aad3006 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -497,3 +497,47 @@ strpcat (char *dest, const char *src, const char *str) | |||
497 | 497 | ||
498 | return dest; | 498 | return dest; |
499 | } | 499 | } |
500 | |||
501 | |||
502 | |||
503 | |||
504 | /****************************************************************************** | ||
505 | * | ||
506 | * Print perfdata in a standard format | ||
507 | * | ||
508 | ******************************************************************************/ | ||
509 | |||
510 | char *perfdata (const char *label, | ||
511 | long int val, | ||
512 | const char *uom, | ||
513 | int warnp, | ||
514 | long int warn, | ||
515 | int critp, | ||
516 | long int crit, | ||
517 | int minp, | ||
518 | long int minv, | ||
519 | int maxp, | ||
520 | long int maxv) | ||
521 | { | ||
522 | char *data = NULL; | ||
523 | |||
524 | asprintf (&data, "\"%s\"=%ld%s;", label, val, uom); | ||
525 | |||
526 | if (warnp) | ||
527 | asprintf (&data, "%s%ld;", data, warn); | ||
528 | else | ||
529 | asprintf (&data, "%s;", data); | ||
530 | |||
531 | if (critp) | ||
532 | asprintf (&data, "%s%ld;", data, crit); | ||
533 | else | ||
534 | asprintf (&data, "%s;", data); | ||
535 | |||
536 | if (minp) | ||
537 | asprintf (&data, "%s%ld", data, minv); | ||
538 | |||
539 | if (maxp) | ||
540 | asprintf (&data, "%s;%ld", data, maxv); | ||
541 | |||
542 | return data; | ||
543 | } | ||
diff --git a/plugins/utils.h b/plugins/utils.h index efdbed4..282f299 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -79,6 +79,18 @@ const char *state_text (int result); | |||
79 | 79 | ||
80 | #define max(a,b) (((a)>(b))?(a):(b)) | 80 | #define max(a,b) (((a)>(b))?(a):(b)) |
81 | 81 | ||
82 | char *perfdata (const char *label, | ||
83 | long int val, | ||
84 | const char *uom, | ||
85 | int warnp, | ||
86 | long int warn, | ||
87 | int critp, | ||
88 | long int crit, | ||
89 | int minp, | ||
90 | long int minv, | ||
91 | int maxp, | ||
92 | long int maxv); | ||
93 | |||
82 | /* The idea here is that, although not every plugin will use all of these, | 94 | /* The idea here is that, although not every plugin will use all of these, |
83 | most will or should. Therefore, for consistency, these very common | 95 | most will or should. Therefore, for consistency, these very common |
84 | options should have only these meanings throughout the overall suite */ | 96 | options should have only these meanings throughout the overall suite */ |