Back to index

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

Go to the source code of this file.

Defines

#define DEFAULT_TIMEOUT   11

Functions

static const char ** process_arguments (int, char **)
int validate_arguments (char **)
void print_help (void)
void print_usage (void)
int main (int argc, char **argv)
int translate_state (char *state_text)

Variables

const char * progname = "negate"
const char * copyright = "2002-2008"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
int subst_text = FALSE
static int state [4]

Define Documentation

#define DEFAULT_TIMEOUT   11

Definition at line 36 of file negate.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 58 of file negate.c.

{
       int found = 0, result = STATE_UNKNOWN;
       char *buf, *sub;
       char **command_line;
       output chld_out, chld_err;
       int i;

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

       timeout_interval = DEFAULT_TIMEOUT;

       command_line = (char **) process_arguments (argc, argv);

       /* Set signal handling and alarm */
       if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR)
              die (STATE_UNKNOWN, _("Cannot catch SIGALRM"));

       (void) alarm ((unsigned) timeout_interval);

       /* catch when the command is quoted */
       if(command_line[1] == NULL) {
              result = cmd_run (command_line[0], &chld_out, &chld_err, 0);
       } else {
              result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
       }
       if (chld_err.lines > 0) {
              printf ("Error output from command:\n");
              for (i = 0; i < chld_err.lines; i++) {
                     printf ("%s\n", chld_err.line[i]);
              }
              exit (STATE_WARNING);
       }

       /* Return UNKNOWN or worse if no output is returned */
       if (chld_out.lines == 0)
              die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n"));

       for (i = 0; i < chld_out.lines; i++) {
              if (subst_text && result != state[result] &&
                  result >= 0 && result <= 4) {
                     /* Loop over each match found */
                     while ((sub = strstr (chld_out.line[i], state_text (result)))) {
                            /* Terminate the first part and skip over the string we'll substitute */
                            *sub = '\0';
                            sub += strlen (state_text (result));
                            /* then put everything back together */
                            asprintf (&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text (state[result]), sub);
                     }
              }
              printf ("%s\n", chld_out.line[i]);
       }

       if (result >= 0 && result <= 4) {
              exit (state[result]);
       } else {
              exit (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");
}
static const char** process_arguments ( int  argc,
char **  argv 
) [static]
int translate_state ( char *  state_text)

Definition at line 219 of file negate.c.

{
       char *temp_ptr;
       for (temp_ptr = state_text; *temp_ptr; temp_ptr++) {
              *temp_ptr = toupper(*temp_ptr);
       }
       if (!strcmp(state_text,"OK") || !strcmp(state_text,"0"))
              return STATE_OK;
       if (!strcmp(state_text,"WARNING") || !strcmp(state_text,"1"))
              return STATE_WARNING;
       if (!strcmp(state_text,"CRITICAL") || !strcmp(state_text,"2"))
              return STATE_CRITICAL;
       if (!strcmp(state_text,"UNKNOWN") || !strcmp(state_text,"3"))
              return STATE_UNKNOWN;
       return ERROR;
}
int validate_arguments ( char **  command_line)

Definition at line 208 of file negate.c.

{
       if (command_line[0] == NULL)
              usage4 (_("Could not parse arguments"));

       if (strncmp(command_line[0],"/",1) != 0 && strncmp(command_line[0],"./",2) != 0)
              usage4 (_("Require path to command"));
}

Here is the call graph for this function:


Variable Documentation

const char* copyright = "2002-2008"

Definition at line 33 of file negate.c.

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

Definition at line 34 of file negate.c.

const char* progname = "negate"

Definition at line 32 of file negate.c.

int state[4] [static]
Initial value:

Definition at line 50 of file negate.c.

Definition at line 48 of file negate.c.