From 81be2afd957c2c5d50bdf37301e0af679fedb8e9 Mon Sep 17 00:00:00 2001 From: Gerhard Lausser Date: Sun, 19 Apr 2015 01:12:44 +0200 Subject: add sperfdata function which can handle threshold ranges --- plugins/utils.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'plugins/utils.c') diff --git a/plugins/utils.c b/plugins/utils.c index 58b153d8..7f49e7be 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -630,3 +630,43 @@ char *fperfdata (const char *label, return data; } + +char *sperfdata (const char *label, + double val, + const char *uom, + char *warn, + char *crit, + int minp, + double minv, + int maxp, + double maxv) +{ + char *data = NULL; + if (strpbrk (label, "'= ")) + xasprintf (&data, "'%s'=", label); + else + xasprintf (&data, "%s=", label); + + xasprintf (&data, "%s%f", data, val); + xasprintf (&data, "%s%s;", data, uom); + + if (warn!=NULL) + xasprintf (&data, "%s%s", data, warn); + + xasprintf (&data, "%s;", data); + + if (crit!=NULL) + xasprintf (&data, "%s%s", data, crit); + + xasprintf (&data, "%s;", data); + + if (minp) + xasprintf (&data, "%s%f", data, minv); + + if (maxp) { + xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%f", data, maxv); + } + + return data; +} -- cgit v1.2.3