Code

Removed old terminate function (Bug 1093491)
[nagiosplug.git] / plugins / utils.c
index 5dbdb4de0c7f4beaa4233facade3beccfcf6e0a0..b9a19d3fe0c2f8f39d0fd1f5c9bfbd30c1279448 100644 (file)
@@ -53,7 +53,7 @@ max_state (int a, int b)
 
 void usage (const char *msg)
 {
-       printf ("%s", msg);
+       printf ("%s\n", msg);
        print_usage ();
        exit (STATE_UNKNOWN);
 }
@@ -73,17 +73,14 @@ usage3 (const char *msg, int arg)
        exit (STATE_UNKNOWN);
 }
 
-
 void
-support (void)
+usage4 (const char *msg)
 {
-       printf (_("\n\
-Send email to nagios-users@lists.sourceforge.net if you have questions\n\
-regarding use of this software. To submit patches or suggest improvements,\n\
-send email to nagiosplug-devel@lists.sourceforge.net\n"));
+       printf ("%s: %s\n", progname, msg);
+       print_usage();
+       exit (STATE_UNKNOWN);
 }
 
-
 char *
 clean_revstring (const char *revstring)
 {
@@ -103,11 +100,6 @@ print_revision (const char *command_name, const char *revision_string)
                strncpy (plugin_revision, "N/A", STRLEN);
        printf ("%s (%s %s) %s\n",
                                        command_name, PACKAGE, VERSION, plugin_revision);
-       printf (_("\
-The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
-copies of the plugins under the terms of the GNU General Public License.\n\
-For more information about these matters, see the file named COPYING.\n"));
-
 }
 
 const char *
@@ -141,7 +133,7 @@ void
 timeout_alarm_handler (int signo)
 {
        if (signo == SIGALRM) {
-               printf ("CRITICAL - Plugin timed out after %d seconds\n",
+               printf (_("CRITICAL - Plugin timed out after %d seconds\n"),
                                                timeout_interval);
                exit (STATE_CRITICAL);
        }
@@ -315,9 +307,6 @@ strip (char *buffer)
 }
 
 
-
-
-
 /******************************************************************************
  *
  * Copies one string to another. Any previously existing data in
@@ -343,8 +332,6 @@ strscpy (char *dest, const char *src)
 
 
 
-
-
 /******************************************************************************
  *
  * Returns a pointer to the next line of a multiline string buffer
@@ -414,9 +401,6 @@ strnl (char *str)
 }
 
 
-
-
-
 /******************************************************************************
  *
  * Like strscpy, except only the portion of the source string up to
@@ -446,7 +430,7 @@ strpcpy (char *dest, const char *src, const char *str)
        if (dest == NULL || strlen (dest) < len)
                dest = realloc (dest, len + 1);
        if (dest == NULL)
-               die (STATE_UNKNOWN, "failed realloc in strpcpy\n");
+               die (STATE_UNKNOWN, _("failed realloc in strpcpy\n"));
 
        strncpy (dest, src, len);
        dest[len] = '\0';
@@ -456,8 +440,6 @@ strpcpy (char *dest, const char *src, const char *str)
 
 
 
-
-
 /******************************************************************************
  *
  * Like strscat, except only the portion of the source string up to
@@ -490,7 +472,7 @@ strpcat (char *dest, const char *src, const char *str)
 
        dest = realloc (dest, len + l2 + 1);
        if (dest == NULL)
-               die (STATE_UNKNOWN, "failed malloc in strscat\n");
+               die (STATE_UNKNOWN, _("failed malloc in strscat\n"));
 
        strncpy (dest + len, src, l2);
        dest[len + l2] = '\0';
@@ -499,8 +481,6 @@ strpcat (char *dest, const char *src, const char *str)
 }
 
 
-
-
 /******************************************************************************
  *
  * Print perfdata in a standard format
@@ -521,8 +501,8 @@ char *perfdata (const char *label,
 {
        char *data = NULL;
 
-       if (index (label, '"'))
-               asprintf (&data, "\"%s\"=%ld%s;", label, val, uom);
+       if (strpbrk (label, "'= "))
+               asprintf (&data, "'%s'=%ld%s;", label, val, uom);
        else
                asprintf (&data, "%s=%ld%s;", label, val, uom);
 
@@ -544,3 +524,47 @@ char *perfdata (const char *label,
 
        return data;
 }
+
+
+char *fperfdata (const char *label,
+ double val,
+ const char *uom,
+ int warnp,
+ double warn,
+ int critp,
+ double crit,
+ int minp,
+ double minv,
+ int maxp,
+ double maxv)
+{
+       char *data = NULL;
+
+       if (strpbrk (label, "'= "))
+               asprintf (&data, "'%s'=", label);
+       else
+               asprintf (&data, "%s=", label);
+
+       asprintf (&data, "%s%f", data, val);
+       asprintf (&data, "%s%s;", data, uom);
+
+       if (warnp)
+               asprintf (&data, "%s%f", data, warn);
+
+       asprintf (&data, "%s;", data);
+
+       if (critp)
+               asprintf (&data, "%s%f", data, crit);
+
+       asprintf (&data, "%s;", data);
+
+       if (minp)
+               asprintf (&data, "%s%f", data, minv);
+
+       if (maxp) {
+               asprintf (&data, "%s;", data);
+               asprintf (&data, "%s%f", data, maxv);
+       }
+
+       return data;
+}