Back to index

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

Go to the source code of this file.

Defines

#define NP_MAXARGS   1024

Functions

int process_arguments (int, char **)
int validate_arguments (void)
void comm_append (const char *)
void print_help (void)
void print_usage (void)
int main (int argc, char **argv)

Variables

const char * progname = "check_by_ssh"
const char * copyright = "2000-2008"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
unsigned int commands = 0
unsigned int services = 0
int skip_stdout = 0
int skip_stderr = 0
char * remotecmd = NULL
char ** commargv = NULL
int commargc = 0
char * hostname = NULL
char * outputfile = NULL
char * host_shortname = NULL
char ** service
int passive = FALSE
int verbose = FALSE

Define Documentation

#define NP_MAXARGS   1024

Definition at line 39 of file check_by_ssh.c.


Function Documentation

void comm_append ( const char *  str)

Definition at line 350 of file check_by_ssh.c.

{

       if (++commargc > NP_MAXARGS)
              die(STATE_UNKNOWN, _("%s: Argument limit of %d exceeded\n"), progname, NP_MAXARGS);

       if ((commargv = (char **)realloc(commargv, (commargc+1) * sizeof(char *))) == NULL)
              die(STATE_UNKNOWN, _("Can not (re)allocate 'commargv' buffer\n"));

       commargv[commargc-1] = strdup(str);
       commargv[commargc] = NULL;

}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 63 of file check_by_ssh.c.

{

       char *status_text;
       int cresult;
       int result = STATE_UNKNOWN;
       int i;
       time_t local_time;
       FILE *fp = NULL;
       output chld_out, chld_err;

       remotecmd = "";
       comm_append(SSH_COMMAND);

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

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

       /* process arguments */
       if (process_arguments (argc, argv) == ERROR)
              usage_va(_("Could not parse arguments"));

       /* Set signal handling and alarm timeout */
       if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
              usage_va(_("Cannot catch SIGALRM"));
       }
       alarm (timeout_interval);

       /* run the command */
       if (verbose) {
              printf ("Command: %s\n", commargv[0]);
              for (i=1; i<commargc; i++)
                     printf ("Argument %i: %s\n", i, commargv[i]);
       }

       result = cmd_run_array (commargv, &chld_out, &chld_err, 0);

       if (skip_stdout == -1) /* --skip-stdout specified without argument */
              skip_stdout = chld_out.lines;
       if (skip_stderr == -1) /* --skip-stderr specified without argument */
              skip_stderr = chld_err.lines;

       /* UNKNOWN or worse if (non-skipped) output found on stderr */
       if(chld_err.lines > skip_stderr) {
              printf (_("Remote command execution failed: %s\n"),
                      chld_err.line[skip_stderr]);
              return max_state_alt(result, STATE_UNKNOWN);
       }

       /* this is simple if we're not supposed to be passive.
        * Wrap up quickly and keep the tricks below */
       if(!passive) {
              if (chld_out.lines > skip_stdout)
                     for (i = skip_stdout; i < chld_out.lines; i++)
                            puts (chld_out.line[i]);
              else
                     printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"),
                             state_text(result), remotecmd, result);
              return result;       /* return error status from remote command */
       }


       /*
        * Passive mode
        */

       /* process output */
       if (!(fp = fopen (outputfile, "a"))) {
              printf (_("SSH WARNING: could not open %s\n"), outputfile);
              exit (STATE_UNKNOWN);
       }

       local_time = time (NULL);
       commands = 0;
       for(i = skip_stdout; i < chld_out.lines; i++) {
              status_text = chld_out.line[i++];
              if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
                     die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);

              if (service[commands] && status_text
                     && sscanf (chld_out.line[i], "STATUS CODE: %d", &cresult) == 1)
              {
                     fprintf (fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
                              (int) local_time, host_shortname, service[commands++],
                              cresult, status_text);
              }
       }
       
       /* Multiple commands and passive checking should always return OK */
       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 validate_arguments ( void  )

Variable Documentation

unsigned int commands = 0

Definition at line 48 of file check_by_ssh.c.

int commargc = 0

Definition at line 54 of file check_by_ssh.c.

char** commargv = NULL

Definition at line 53 of file check_by_ssh.c.

const char* copyright = "2000-2008"

Definition at line 30 of file check_by_ssh.c.

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

Definition at line 31 of file check_by_ssh.c.

Definition at line 57 of file check_by_ssh.c.

char* hostname = NULL

Definition at line 55 of file check_by_ssh.c.

char* outputfile = NULL

Definition at line 56 of file check_by_ssh.c.

int passive = FALSE

Definition at line 59 of file check_by_ssh.c.

const char* progname = "check_by_ssh"

Definition at line 29 of file check_by_ssh.c.

char* remotecmd = NULL

Definition at line 52 of file check_by_ssh.c.

char** service

Definition at line 58 of file check_by_ssh.c.

unsigned int services = 0

Definition at line 49 of file check_by_ssh.c.

int skip_stderr = 0

Definition at line 51 of file check_by_ssh.c.

int skip_stdout = 0

Definition at line 50 of file check_by_ssh.c.

int verbose = FALSE

Definition at line 60 of file check_by_ssh.c.