X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_ssh.c;h=f3a351e6800d82dd24b608705c76bc4501cf7936;hb=11b35b92e3195d230bef359f6a0679ae4414716b;hp=3efc2e625ad9aa12b8db68d013222506cd4c3798;hpb=ba7ba99b42086cf6ffc797fee4029af41950b194;p=nagiosplug.git diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index 3efc2e6..f3a351e 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c @@ -39,6 +39,7 @@ int ssh_connect (char *haddr, short hport); int main (int argc, char **argv) { + int result; if (process_arguments (argc, argv) == ERROR) usage ("Could not parse arguments\n"); @@ -48,11 +49,11 @@ main (int argc, char **argv) alarm (socket_timeout); /* ssh_connect exits if error is found */ - ssh_connect (server_name, port); + result = ssh_connect (server_name, port); alarm (0); - return (STATE_OK); + return (result); } @@ -63,7 +64,6 @@ process_arguments (int argc, char **argv) int c; char *tmp = NULL; -#ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { {"version", no_argument, 0, 'V'}, @@ -73,7 +73,6 @@ process_arguments (int argc, char **argv) {"host", required_argument, 0, 'H'}, {0, 0, 0, 0} }; -#endif if (argc < 2) return ERROR; @@ -83,11 +82,8 @@ process_arguments (int argc, char **argv) strcpy (argv[c], "-t"); while (1) { -#ifdef HAVE_GETOPT_H c = getopt_long (argc, argv, "+Vhvt:H:p:", long_options, &option_index); -#else - c = getopt (argc, argv, "+Vhvt:H:p:"); -#endif + if (c == -1 || c == EOF) break; @@ -126,13 +122,13 @@ process_arguments (int argc, char **argv) } c = optind; - if (server_name == NULL && argv[c]) { + if (server_name == NULL && c < argc) { if (is_host (argv[c])) { server_name = argv[c++]; } } - if (port == -1 && argv[c]) { + if (port == -1 && c < argc) { if (is_intpos (argv[c])) { port = atoi (argv[c++]); } @@ -195,7 +191,7 @@ ssh_connect (char *haddr, short hport) ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. "); ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0; printf - ("SSH ok - %s (protocol %s)\n", + ("SSH OK - %s (protocol %s)\n", ssh_server, ssh_proto); asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision); send (sd, buffer, strlen (buffer), MSG_DONTWAIT);