Back to index

nagios-plugins  1.4.16
Defines | Functions | Variables
check_ssh.c File Reference
#include "common.h"
#include "netutils.h"
#include "utils.h"

Go to the source code of this file.

Defines

#define MSG_DONTWAIT   0
#define SSH_DFL_PORT   22
#define BUFF_SZ   256

Functions

int process_arguments (int, char **)
int validate_arguments (void)
void print_help (void)
void print_usage (void)
int ssh_connect (char *haddr, int hport, char *remote_version)
int main (int argc, char **argv)

Variables

const char * progname = "check_ssh"
const char * copyright = "2000-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
int port = -1
char * server_name = NULL
char * remote_version = NULL
int verbose = FALSE

Define Documentation

#define BUFF_SZ   256

Definition at line 44 of file check_ssh.c.

#define MSG_DONTWAIT   0

Definition at line 40 of file check_ssh.c.

#define SSH_DFL_PORT   22

Definition at line 43 of file check_ssh.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file check_ssh.c.

{
       int result = STATE_UNKNOWN;

       setlocale (LC_ALL, "");
       bindtextdomain (PACKAGE, LOCALEDIR);
       textdomain (PACKAGE);

       /* Parse extra opts if any */
       argv=np_extra_opts (&argc, argv, progname);

       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 */
       result = ssh_connect (server_name, port, remote_version);

       alarm (0);

       return (result);
}

Here is the call graph for this function:

void print_help ( void  )
void print_usage ( void  )

Definition at line 389 of file check_cpqarray.c.

{
  printf("cpqarrayd [options]\n");
  printf("   -h         prints this text\n");
  printf("   -d         enables debugging\n");
}
int process_arguments ( int  argc,
char **  argv 
)
int ssh_connect ( char *  haddr,
int  hport,
char *  remote_version 
)

Definition at line 209 of file check_ssh.c.

{
       int sd;
       int result;
       char *output = NULL;
       char *buffer = NULL;
       char *ssh_proto = NULL;
       char *ssh_server = NULL;
       static char *rev_no = VERSION;
       struct timeval tv;
       double elapsed_time;

       gettimeofday(&tv, NULL);

       result = my_tcp_connect (haddr, hport, &sd);

       if (result != STATE_OK)
              return result;

       output = (char *) malloc (BUFF_SZ + 1);
       memset (output, 0, BUFF_SZ + 1);
       recv (sd, output, BUFF_SZ, 0);
       if (strncmp (output, "SSH", 3)) {
              printf (_("Server answer: %s"), output);
              close(sd);
              exit (STATE_CRITICAL);
       }
       else {
              strip (output);
              if (verbose)
                     printf ("%s\n", output);
              ssh_proto = output + 4;
              ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
              ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;

              asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no);
              send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
              if (verbose)
                     printf ("%s\n", buffer);

              if (remote_version && strcmp(remote_version, ssh_server)) {
                     printf
                            (_("SSH WARNING - %s (protocol %s) version mismatch, expected '%s'\n"),
                             ssh_server, ssh_proto, remote_version);
                     close(sd);
                     exit (STATE_WARNING);
              }

              elapsed_time = (double)deltime(tv) / 1.0e6;

              printf
                     (_("SSH OK - %s (protocol %s) | %s\n"),
                      ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s",
                      FALSE, 0, FALSE, 0, TRUE, 0, TRUE, (int)socket_timeout));
              close(sd);
              exit (STATE_OK);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int validate_arguments ( void  )

Variable Documentation

const char* copyright = "2000-2007"

Definition at line 32 of file check_ssh.c.

const char* email = "nagiosplug-devel@lists.sourceforge.net"

Definition at line 33 of file check_ssh.c.

int port = -1

Definition at line 46 of file check_ssh.c.

const char* progname = "check_ssh"

Definition at line 31 of file check_ssh.c.

Definition at line 48 of file check_ssh.c.

char* server_name = NULL

Definition at line 47 of file check_ssh.c.

int verbose = FALSE

Definition at line 49 of file check_ssh.c.