summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerhard Lausser <gerhard.lausser@consol.de>2015-04-19 01:12:44 +0200
committerSven Nierlein <sven@nierlein.de>2015-04-21 19:11:56 +0200
commit81be2afd957c2c5d50bdf37301e0af679fedb8e9 (patch)
treec5b734e51b1806de051b41575c426ddc4272b7e6
parent500f8aec81c3a378e22c6ec767cf6d8fbc9f77b4 (diff)
downloadmonitoring-plugins-81be2af.tar.gz
add sperfdata function which can handle threshold ranges
-rw-r--r--plugins/utils.c40
1 files changed, 40 insertions, 0 deletions
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,
630 630
631 return data; 631 return data;
632} 632}
633
634char *sperfdata (const char *label,
635 double val,
636 const char *uom,
637 char *warn,
638 char *crit,
639 int minp,
640 double minv,
641 int maxp,
642 double maxv)
643{
644 char *data = NULL;
645 if (strpbrk (label, "'= "))
646 xasprintf (&data, "'%s'=", label);
647 else
648 xasprintf (&data, "%s=", label);
649
650 xasprintf (&data, "%s%f", data, val);
651 xasprintf (&data, "%s%s;", data, uom);
652
653 if (warn!=NULL)
654 xasprintf (&data, "%s%s", data, warn);
655
656 xasprintf (&data, "%s;", data);
657
658 if (crit!=NULL)
659 xasprintf (&data, "%s%s", data, crit);
660
661 xasprintf (&data, "%s;", data);
662
663 if (minp)
664 xasprintf (&data, "%s%f", data, minv);
665
666 if (maxp) {
667 xasprintf (&data, "%s;", data);
668 xasprintf (&data, "%s%f", data, maxv);
669 }
670
671 return data;
672}