Explorar o código

function to make perfdata output

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@696 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop %!s(int64=22) %!d(string=hai) anos
pai
achega
68e8cc5f4d
Modificáronse 2 ficheiros con 56 adicións e 0 borrados
  1. 44 0
      plugins/utils.c
  2. 12 0
      plugins/utils.h

+ 44 - 0
plugins/utils.c

@@ -497,3 +497,47 @@ strpcat (char *dest, const char *src, const char *str)
 
 	return dest;
 }
+
+
+
+
+/******************************************************************************
+ *
+ * Print perfdata in a standard format
+ *
+ ******************************************************************************/
+
+char *perfdata (const char *label,
+ long int val,
+ const char *uom,
+ int warnp,
+ long int warn,
+ int critp,
+ long int crit,
+ int minp,
+ long int minv,
+ int maxp,
+ long int maxv)
+{
+	char *data = NULL;
+
+	asprintf (&data, "\"%s\"=%ld%s;", label, val, uom);
+
+	if (warnp)
+		asprintf (&data, "%s%ld;", data, warn);
+	else
+		asprintf (&data, "%s;", data);
+
+	if (critp)
+		asprintf (&data, "%s%ld;", data, crit);
+	else
+		asprintf (&data, "%s;", data);
+
+	if (minp)
+		asprintf (&data, "%s%ld", data, minv);
+
+	if (maxp)
+		asprintf (&data, "%s;%ld", data, maxv);
+
+	return data;
+}

+ 12 - 0
plugins/utils.h

@@ -79,6 +79,18 @@ const char *state_text (int result);
 
 #define max(a,b) (((a)>(b))?(a):(b))
 
+char *perfdata (const char *label,
+ long int val,
+ const char *uom,
+ int warnp,
+ long int warn,
+ int critp,
+ long int crit,
+ int minp,
+ long int minv,
+ int maxp,
+ long int maxv);
+
 /* The idea here is that, although not every plugin will use all of these, 
    most will or should.  Therefore, for consistency, these very common 
    options should have only these meanings throughout the overall suite */