Code

cleaning help and usage + license
[nagiosplug.git] / plugins / check_ssh.c
index 46dd044d11ff5f204252c449cf0e8c89da11677f..1a99e24a0f7b4fb8d0ac313dfbb78642026596ce 100644 (file)
@@ -1,32 +1,45 @@
 /******************************************************************************
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
+*
+* Nagios check_ssh plugin
+*
+* License: GPL
+* Copyright (c) 1999-2006 nagios-plugins team
+*
+* Last Modified: $Date$
+*
+* Description:
+*
+* This file contains the check_ssh plugin
+*
+* License Information:
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*
+* $Id$
+* 
 ******************************************************************************/
 
-#include "common.h"
-#include "netutils.h"
-#include "utils.h"
-
 const char *progname = "check_ssh";
 const char *revision = "$Revision$";
-const char *copyright = "2000-2003";
+const char *copyright = "2000-2006";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
+#include "common.h"
+#include "netutils.h"
+#include "utils.h"
+
 #ifndef MSG_DONTWAIT
 #define MSG_DONTWAIT 0
 #endif
@@ -51,17 +64,18 @@ int ssh_connect (char *haddr, int hport, char *remote_version);
 int
 main (int argc, char **argv)
 {
-       int result;
+       int result = STATE_UNKNOWN;
 
        setlocale (LC_ALL, "");
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
 
-       if (process_arguments (argc, argv) != OK)
-               usage (_("check_ssh: could not parse arguments\n"));
+       if (process_arguments (argc, argv) == ERROR)
+               usage4 (_("Could not parse arguments"));
 
        /* initialize alarm signal handling */
        signal (SIGALRM, socket_timeout_alarm_handler);
+       
        alarm (socket_timeout);
 
        /* ssh_connect exits if error is found */
@@ -109,9 +123,7 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':                                                                       /* help */
-                       printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
-                       print_usage ();
-                       exit (STATE_UNKNOWN);
+                       usage2 (_("Unknown argument"), optarg);
                case 'V':                                                                       /* version */
                        print_revision (progname, revision);
                        exit (STATE_OK);
@@ -134,7 +146,7 @@ process_arguments (int argc, char **argv)
 #ifdef USE_IPV6
                        address_family = AF_INET6;
 #else
-                       usage (_("IPv6 support not available\n"));
+                       usage4 (_("IPv6 support not available"));
 #endif
                        break;
                case 'r':                                                                       /* remote version */
@@ -150,11 +162,9 @@ process_arguments (int argc, char **argv)
                                port = atoi (optarg);
                        }
                        else {
-                               printf ("Port number nust be a positive integer: %s\n", optarg);
-                               usage ("");
+                               usage2 (_("Port number must be a positive integer"), optarg);
                        }
                }
-
        }
 
        c = optind;
@@ -243,6 +253,7 @@ ssh_connect (char *haddr, int hport, char *remote_version)
                printf
                        (_("SSH OK - %s (protocol %s)\n"),
                         ssh_server, ssh_proto);
+               close(sd);
                exit (STATE_OK);
        }
 }
@@ -260,7 +271,9 @@ print_help (void)
        printf ("Copyright (c) 1999 Remi Paulmier <remi@sinfomic.fr>\n");
        printf (COPYRIGHT, copyright, email);
 
-       printf (_("Try to connect to an SSH server at specified server and port\n\n"));
+       printf ("%s\n", _("Try to connect to an SSH server at specified server and port"));
+
+  printf ("\n\n");
 
        print_usage ();
 
@@ -272,9 +285,8 @@ print_help (void)
 
        printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
 
-       printf (_("\
- -r, --remote-version=STRING\n\
-    Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)\n"));
+       printf (" %s\n" "-r, --remote-version=STRING");
+  printf ("    %s\n", _("Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)"));
        
        printf (_(UT_VERBOSE));
 
@@ -286,9 +298,7 @@ print_help (void)
 void
 print_usage (void)
 {
-       printf (_("\
-Usage: %s [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n"), progname);
-       printf (_(UT_HLP_VRS), progname, progname);
+  printf (_("Usage:"));
+       printf ("%s [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname);
 }
 
-/* end of check_ssh.c */