Back to index

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

Go to the source code of this file.

Defines

#define DEFAULT_COMMUNITY   "public"
#define HPJD_LINE_STATUS   ".1.3.6.1.4.1.11.2.3.9.1.1.2.1"
#define HPJD_PAPER_STATUS   ".1.3.6.1.4.1.11.2.3.9.1.1.2.2"
#define HPJD_INTERVENTION_REQUIRED   ".1.3.6.1.4.1.11.2.3.9.1.1.2.3"
#define HPJD_GD_PERIPHERAL_ERROR   ".1.3.6.1.4.1.11.2.3.9.1.1.2.6"
#define HPJD_GD_PAPER_OUT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.8"
#define HPJD_GD_PAPER_JAM   ".1.3.6.1.4.1.11.2.3.9.1.1.2.9"
#define HPJD_GD_TONER_LOW   ".1.3.6.1.4.1.11.2.3.9.1.1.2.10"
#define HPJD_GD_PAGE_PUNT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.11"
#define HPJD_GD_MEMORY_OUT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.12"
#define HPJD_GD_DOOR_OPEN   ".1.3.6.1.4.1.11.2.3.9.1.1.2.17"
#define HPJD_GD_PAPER_OUTPUT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.19"
#define HPJD_GD_STATUS_DISPLAY   ".1.3.6.1.4.1.11.2.3.9.1.1.3"
#define ONLINE   0
#define OFFLINE   1

Functions

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

Variables

const char * progname = "check_hpjd"
const char * copyright = "2000-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
const char * option_summary = "-H host [-C community]\n"
char * community = NULL
char * address = NULL

Define Documentation

#define DEFAULT_COMMUNITY   "public"

Definition at line 41 of file check_hpjd.c.

#define HPJD_GD_DOOR_OPEN   ".1.3.6.1.4.1.11.2.3.9.1.1.2.17"

Definition at line 55 of file check_hpjd.c.

#define HPJD_GD_MEMORY_OUT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.12"

Definition at line 54 of file check_hpjd.c.

#define HPJD_GD_PAGE_PUNT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.11"

Definition at line 53 of file check_hpjd.c.

#define HPJD_GD_PAPER_JAM   ".1.3.6.1.4.1.11.2.3.9.1.1.2.9"

Definition at line 51 of file check_hpjd.c.

#define HPJD_GD_PAPER_OUT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.8"

Definition at line 50 of file check_hpjd.c.

#define HPJD_GD_PAPER_OUTPUT   ".1.3.6.1.4.1.11.2.3.9.1.1.2.19"

Definition at line 56 of file check_hpjd.c.

#define HPJD_GD_PERIPHERAL_ERROR   ".1.3.6.1.4.1.11.2.3.9.1.1.2.6"

Definition at line 49 of file check_hpjd.c.

#define HPJD_GD_STATUS_DISPLAY   ".1.3.6.1.4.1.11.2.3.9.1.1.3"

Definition at line 57 of file check_hpjd.c.

#define HPJD_GD_TONER_LOW   ".1.3.6.1.4.1.11.2.3.9.1.1.2.10"

Definition at line 52 of file check_hpjd.c.

#define HPJD_INTERVENTION_REQUIRED   ".1.3.6.1.4.1.11.2.3.9.1.1.2.3"

Definition at line 48 of file check_hpjd.c.

#define HPJD_LINE_STATUS   ".1.3.6.1.4.1.11.2.3.9.1.1.2.1"

Definition at line 46 of file check_hpjd.c.

#define HPJD_PAPER_STATUS   ".1.3.6.1.4.1.11.2.3.9.1.1.2.2"

Definition at line 47 of file check_hpjd.c.

#define OFFLINE   1

Definition at line 60 of file check_hpjd.c.

#define ONLINE   0

Definition at line 59 of file check_hpjd.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 71 of file check_hpjd.c.

{
       char command_line[1024];
       int result = STATE_UNKNOWN;
       int line;
       char input_buffer[MAX_INPUT_BUFFER];
       char query_string[512];
       char *errmsg;
       char *temp_buffer;
       int line_status = ONLINE;
       int paper_status = 0;
       int intervention_required = 0;
       int peripheral_error = 0;
       int paper_jam = 0;
       int paper_out = 0;
       int toner_low = 0;
       int page_punt = 0;
       int memory_out = 0;
       int door_open = 0;
       int paper_output = 0;
       char display_message[MAX_INPUT_BUFFER];

       errmsg = malloc(MAX_INPUT_BUFFER);

       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"));

       /* removed ' 2>1' at end of command 10/27/1999 - EG */
       /* create the query string */
       sprintf
              (query_string,
               "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0",
               HPJD_LINE_STATUS,
               HPJD_PAPER_STATUS,
               HPJD_INTERVENTION_REQUIRED,
               HPJD_GD_PERIPHERAL_ERROR,
               HPJD_GD_PAPER_JAM,
               HPJD_GD_PAPER_OUT,
               HPJD_GD_TONER_LOW,
               HPJD_GD_PAGE_PUNT,
               HPJD_GD_MEMORY_OUT,
               HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY);

       /* get the command to run */
       sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s %s", PATH_TO_SNMPGET, community,
                                                               address, query_string);

       /* run the command */
       child_process = spopen (command_line);
       if (child_process == NULL) {
              printf (_("Could not open pipe: %s\n"), command_line);
              return STATE_UNKNOWN;
       }

       child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
       if (child_stderr == NULL) {
              printf (_("Could not open stderr for %s\n"), command_line);
       }

       result = STATE_OK;

       line = 0;
       while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {

              /* strip the newline character from the end of the input */
              if (input_buffer[strlen (input_buffer) - 1] == '\n')
                     input_buffer[strlen (input_buffer) - 1] = 0;

              line++;

              temp_buffer = strtok (input_buffer, "=");
              temp_buffer = strtok (NULL, "=");

              if (temp_buffer == NULL && line < 13) {

                            result = STATE_UNKNOWN;
                            strcpy (errmsg, input_buffer);

              } else {

                     switch (line) {

                     case 1:                                                                      /* 1st line should contain the line status */
                            line_status = atoi (temp_buffer);
                            break;
                     case 2:                                                                      /* 2nd line should contain the paper status */
                            paper_status = atoi (temp_buffer);
                            break;
                     case 3:                                                                      /* 3rd line should be intervention required */
                            intervention_required = atoi (temp_buffer);
                            break;
                     case 4:                                                                      /* 4th line should be peripheral error */
                            peripheral_error = atoi (temp_buffer);
                            break;
                     case 5:                                                                      /* 5th line should contain the paper jam status */
                            paper_jam = atoi (temp_buffer);
                            break;
                     case 6:                                                                      /* 6th line should contain the paper out status */
                            paper_out = atoi (temp_buffer);
                            break;
                     case 7:                                                                      /* 7th line should contain the toner low status */
                            toner_low = atoi (temp_buffer);
                            break;
                     case 8:                                                                      /* did data come too slow for engine */
                            page_punt = atoi (temp_buffer);
                            break;
                     case 9:                                                                      /* did we run out of memory */
                            memory_out = atoi (temp_buffer);
                            break;
                     case 10:                                                                     /* is there a door open */
                            door_open = atoi (temp_buffer);
                            break;
                     case 11:                                                                     /* is output tray full */
                            paper_output = atoi (temp_buffer);
                            break;
                     case 12:                                                                     /* display panel message */
                            strcpy (display_message, temp_buffer + 1);
                            break;
                     default:                                                                     /* fold multiline message */
                            strncat (display_message, input_buffer,
                                          sizeof (display_message) - strlen (display_message) - 1);
                     }

              }

              /* break out of the read loop if we encounter an error */
              if (result != STATE_OK)
                     break;
       }

       /* WARNING if output found on stderr */
       if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
              result = max_state (result, STATE_WARNING);
              /* remove CRLF */
              if (input_buffer[strlen (input_buffer) - 1] == '\n')
                     input_buffer[strlen (input_buffer) - 1] = 0;
              sprintf (errmsg, "%s", input_buffer );

       }

       /* close stderr */
       (void) fclose (child_stderr);

       /* close the pipe */
       if (spclose (child_process))
              result = max_state (result, STATE_WARNING);

       /* if there wasn't any output, display an error */
       if (line == 0) {

              /* might not be the problem, but most likely is. */
              result = STATE_UNKNOWN ;
              asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address );

       }

       /* if we had no read errors, check the printer status results... */
       if (result == STATE_OK) {

              if (paper_jam) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Paper Jam"));
              }
              else if (paper_out) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Out of Paper"));
              }
              else if (line_status == OFFLINE) {
                     if (strcmp (errmsg, "POWERSAVE ON") != 0) {
                            result = STATE_WARNING;
                            strcpy (errmsg, _("Printer Offline"));
                     }
              }
              else if (peripheral_error) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Peripheral Error"));
              }
              else if (intervention_required) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Intervention Required"));
              }
              else if (toner_low) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Toner Low"));
              }
              else if (memory_out) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Insufficient Memory"));
              }
              else if (door_open) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("A Door is Open"));
              }
              else if (paper_output) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Output Tray is Full"));
              }
              else if (page_punt) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Data too Slow for Engine"));
              }
              else if (paper_status) {
                     result = STATE_WARNING;
                     strcpy (errmsg, _("Unknown Paper Error"));
              }
       }

       if (result == STATE_OK)
              printf (_("Printer ok - (%s)\n"), display_message);

       else if (result == STATE_UNKNOWN) {

              printf ("%s\n", errmsg);

              /* if printer could not be reached, escalate to critical */
              if (strstr (errmsg, "Timeout"))
                     result = STATE_CRITICAL;
       }

       else if (result == STATE_WARNING)
              printf ("%s (%s)\n", errmsg, display_message);

       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

char* address = NULL

Definition at line 68 of file check_hpjd.c.

char* community = NULL

Definition at line 67 of file check_hpjd.c.

const char* copyright = "2000-2007"

Definition at line 33 of file check_hpjd.c.

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

Definition at line 34 of file check_hpjd.c.

const char* option_summary = "-H host [-C community]\n"

Definition at line 44 of file check_hpjd.c.

const char* progname = "check_hpjd"

Definition at line 32 of file check_hpjd.c.