Code

fixes from richard brodie (tracker id 1216576)
[nagiosplug.git] / plugins / check_fping.c
index 7b8e764fb0b490a50d997238d2ecb5d072586ad5..5ffcd16e35ed3a02bcc9fafd61b7b0774720ba33 100644 (file)
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
 ******************************************************************************/
 
 const char *progname = "check_fping";
 const char *revision = "$Revision$";
-const char *copyright = "2000-2003";
+const char *copyright = "2000-2004";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -55,6 +57,8 @@ int wrta_p = FALSE;
 int
 main (int argc, char **argv)
 {
+/* normaly should be   int result = STATE_UNKNOWN; */
+
        int status = STATE_UNKNOWN;
        char *server = NULL;
        char *command_line = NULL;
@@ -66,7 +70,7 @@ main (int argc, char **argv)
        textdomain (PACKAGE);
 
        if (process_arguments (argc, argv) == ERROR)
-               usage (_("Could not parse arguments\n"));
+               usage4 (_("Could not parse arguments"));
 
        server = strscpy (server, server_name);
 
@@ -80,7 +84,7 @@ main (int argc, char **argv)
        /* run the command */
        child_process = spopen (command_line);
        if (child_process == NULL) {
-               printf (_("Unable to open pipe: %s\n"), command_line);
+               printf (_("Could not open pipe: %s\n"), command_line);
                return STATE_UNKNOWN;
        }
 
@@ -116,7 +120,6 @@ main (int argc, char **argv)
 
 
 
-
 int
 textscan (char *buf)
 {
@@ -127,16 +130,16 @@ textscan (char *buf)
        int status = STATE_UNKNOWN;
 
        if (strstr (buf, "not found")) {
-               die (STATE_CRITICAL, _("FPING unknown - %s not found\n"), server_name);
+               die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name);
 
        }
        else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) {
-               die (STATE_CRITICAL, _("FPING critical - %s is unreachable\n"),
+               die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"),
                                                         "host");
 
        }
        else if (strstr (buf, "is down")) {
-               die (STATE_CRITICAL, _("FPING critical - %s is down\n"), server_name);
+               die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);
 
        }
        else if (strstr (buf, "is alive")) {
@@ -165,8 +168,8 @@ textscan (char *buf)
                die (status,
                      _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
                                 state_text (status), server_name, loss, rta,
-                    perfdata ("loss", (int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
-                    perfdata ("rta", (long int)(rta*1.0e3), "us", wrta_p, (long int)(wrta*1.0e3), crta_p, (long int)(crta*1.0e3), TRUE, 0, FALSE, 0));
+                    perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
+                    fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
 
        }
        else if(strstr (buf, "xmt/rcv/%loss") ) {
@@ -186,7 +189,7 @@ textscan (char *buf)
                /* loss=%.0f%%;%d;%d;0;100 */
                die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),
                     state_text (status), server_name, loss ,
-                    perfdata ("loss", (int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
+                    perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
        
        }
        else {
@@ -195,7 +198,6 @@ textscan (char *buf)
 
        return status;
 }
-\f
 
 
 
@@ -240,9 +242,7 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':                                                                       /* print short usage statement if args not parsable */
-                       printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
-                       print_usage ();
-                       exit (STATE_UNKNOWN);
+                       usage2 (_("Unknown argument"), optarg);
                case 'h':                                                                       /* help */
                        print_help ();
                        exit (STATE_OK);
@@ -254,16 +254,14 @@ process_arguments (int argc, char **argv)
                        break;
                case 'H':                                                                       /* hostname */
                        if (is_host (optarg) == FALSE) {
-                               printf (_("Invalid host name/address\n\n"));
-                               print_usage ();
-                               exit (STATE_UNKNOWN);
+                               usage2 (_("Invalid hostname/address"), optarg);
                        }
                        server_name = strscpy (server_name, optarg);
                        break;
                case 'c':
                        get_threshold (optarg, rv);
                        if (rv[RTA]) {
-                               crta = 1e3 * strtod (rv[RTA], NULL);
+                               crta = strtod (rv[RTA], NULL);
                                crta_p = TRUE;
                                rv[RTA] = NULL;
                        }
@@ -276,7 +274,7 @@ process_arguments (int argc, char **argv)
                case 'w':
                        get_threshold (optarg, rv);
                        if (rv[RTA]) {
-                               wrta = 1e3 * strtod (rv[RTA], NULL);
+                               wrta = strtod (rv[RTA], NULL);
                                wrta_p = TRUE;
                                rv[RTA] = NULL;
                        }
@@ -301,17 +299,13 @@ process_arguments (int argc, char **argv)
                }
        }
 
-
        if (server_name == NULL)
-               usage (_("Host name was not supplied\n\n"));
+               usage4 (_("Hostname was not supplied"));
 
        return OK;
 }
 
 
-
-
-
 int
 get_threshold (char *arg, char *rv[2])
 {
@@ -353,22 +347,19 @@ get_threshold (char *arg, char *rv[2])
 }
 
 
-
-
-\f
 void
 print_help (void)
 {
 
-       print_revision (progname, "$Revision$");
+       print_revision (progname, revision);
 
-       printf (_("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n"));
-       printf (_(COPYRIGHT), copyright, email);
+       printf ("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n");
+       printf (COPYRIGHT, copyright, email);
 
        printf (_("\
-This plugin will use the /bin/fping command (from saint) to ping the\n\
-specified host for a fast check if the host is alive. Note that it is\n\
-necessary to set the suid flag on fping.\n\n"));
+This plugin will use the /bin/fping command to ping the specified host\n\
+for a fast check if the host is alive.\n\
+Note that it is necessary to set the suid flag on fping.\n\n"));
 
        print_usage ();
 
@@ -399,11 +390,8 @@ percentage of packet loss to trigger an alarm state.\n"));
 }
 
 
-
-
 void
 print_usage (void)
 {
-       printf (_("Usage: %s <host_address>\n"), progname);
-       printf (_(UT_HLP_VRS), progname, progname);
+       printf ("Usage: %s <host_address>\n", progname);
 }