Back to index

nagios-plugins  1.4.16
check_ipxping.c
Go to the documentation of this file.
00001 /******************************************************************************************
00002  *
00003  * CHECK_IPXPING.C
00004  *
00005  * Program: IPX ping plugin for Nagios
00006  * License: GPL
00007  * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
00008  *
00009  * Last Modified: 09-24-1999
00010  *
00011  * Command line: CHECK_IPXPING <dest_network> <dest_address> <wrtt> <crtt>
00012  *
00013  * Description:
00014  *
00015  * This plugin will use the /usr/bin/ipxping command to ping the specified host using the
00016  * IPX protocol.  Note: Linux users must have IPX support compiled into the kernerl and
00017  * must have IPX configured correctly in order for this plugin to work.
00018  * If the round trip time value is above the <wrtt> level, a STATE_WARNING is
00019  * returned.  If it exceeds the <crtt> level, a STATE_CRITICAL is returned.
00020  *
00021  *
00022  *
00023  * IMPORTANT!!
00024  *
00025  * This plugin will only work with the ipxping command that has been ported to Linux.
00026  * The version for Sun takes different command line arguments and differs in its output.
00027  *
00028  *****************************************************************************************/
00029 
00030 #include "config.h"
00031 #include "common.h"
00032 #include "netutils.h"
00033 #include "popen.h"
00034 
00035 /* this should be moved out to the configure script! */
00036 #define IPXPING_COMMAND     "/tmp/ipxping/ipxping"
00037 
00038 /* these should be moved to the common header file */
00039 #define MAX_IPXNET_ADDRESS_LENGTH  12
00040 #define MAX_IPXHOST_ADDRESS_LENGTH 18
00041 
00042 int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
00043 char dest_network[MAX_IPXNET_ADDRESS_LENGTH];
00044 char dest_address[MAX_IPXHOST_ADDRESS_LENGTH];
00045 int wrtt;
00046 int crtt;
00047 
00048 int process_arguments(int,char **);
00049 
00050 FILE * spopen(const char *);
00051 int spclose(FILE *);
00052 
00053 int main(int argc, char **argv){
00054        char command_line[MAX_INPUT_BUFFER];
00055        int rtt;
00056        int bytes_returned;
00057        int result=STATE_OK;
00058        FILE *fp;
00059        char input_buffer[MAX_INPUT_BUFFER];
00060        char *substr;
00061        int current_line;
00062 
00063        if(process_arguments(argc,argv)!=OK){
00064               printf("Incorrect arguments supplied\n");
00065               printf("\n");
00066               printf("IPX ping plugin for Nagios\n");
00067               printf("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n");
00068               printf("Last Modified: 09-24-1999\n");
00069               printf("License: GPL\n");
00070               printf("\n");
00071               printf("Usage: %s <dest_network> <dest_address> <wrtt> <crtt> [-to to_sec]\n",argv[0]);
00072               printf("\n");
00073               printf("Options:\n");
00074               printf(" <dest_network> = IPX network that the remote host lies on.  (Hex Format - 00:00:00:00)\n");
00075               printf(" <dest_address> = MAC address of the remote host.  (Hex Format - 00:00:00:00:00:00)\n");
00076               printf(" <wrtt>         = Round trip time in milliseconds necessary to result in a WARNING state\n");
00077               printf(" <crtt>         = Round trip time in milliseconds necessary to result in a CRITICAL state\n");
00078               printf(" [to_sec]    = Seconds before we should timeout waiting for ping result.  Default = %d sec\n",DEFAULT_SOCKET_TIMEOUT);
00079               printf("\n");
00080               printf("Notes:\n");
00081               printf("This plugin will use the /usr/bin/ipxping command to ping the specified host using\n");
00082               printf("the IPX protocol.  IPX support must be compiled into the kernel and your host must\n");
00083               printf("be correctly configured to use IPX before this plugin will work! An RPM package of\n");
00084               printf("the ipxping binary can be found at...\n");
00085               printf("http://www.rpmfind.net/linux/RPM/contrib/libc5/i386/ipxping-0.0-2.i386.shtml\n");
00086               printf("\n");
00087               return STATE_UNKNOWN;
00088                }
00089   
00090        /* create the command line to use... */
00091        sprintf(command_line,"%s %s %s",IPXPING_COMMAND,dest_network,dest_address);
00092 
00093        /* initialize alarm signal handling */
00094        signal(SIGALRM,socket_timeout_alarm_handler);
00095 
00096        /* set socket timeout */
00097        alarm(socket_timeout);
00098 
00099        /* run the command */
00100        fp = spopen(command_line);
00101        if(fp==NULL){
00102               printf("Unable to open pipe: %s",command_line);
00103               return STATE_UNKNOWN;
00104                }
00105 
00106        current_line=0;
00107        while(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){
00108 
00109               current_line++;
00110 
00111               /* skip the first line of the output */
00112               if(current_line==1)
00113                      continue;
00114 
00115               /* we didn't get the "is alive" */
00116               if(current_line==2 && !strstr(input_buffer,"is alive"))
00117                      result=STATE_CRITICAL;
00118 
00119               /* get the round trip time */
00120               if(current_line==3){
00121                      substr=strtok(input_buffer,":");
00122                      substr=strtok(NULL,"\n");
00123                      rtt=atoi(substr);
00124                       }
00125 
00126               /* get the number of bytes returned */
00127               if(current_line==4 && strstr(input_buffer,"bytes returned")){
00128                      bytes_returned=atoi(input_buffer);
00129                       }
00130                }
00131 
00132        /* close the pipe */
00133        spclose(fp);
00134 
00135        /* reset the alarm */
00136        alarm(0);
00137 
00138        if(current_line==1 || result==STATE_CRITICAL)
00139               printf("IPX Ping problem - No response from host\n");
00140        else{
00141 
00142               if(rtt>crtt)
00143                      result=STATE_CRITICAL;
00144               else if(rtt>wrtt)
00145                      result=STATE_WARNING;
00146 
00147               printf("IPX Ping %s - RTT = %d ms, %d bytes returned from %s %s\n",(result==STATE_OK)?"ok":"problem",rtt,bytes_returned,dest_network,dest_address);
00148                }
00149        
00150 
00151        return result;
00152         }
00153 
00154 
00155 
00156 /* process all arguments passed on the command line */
00157 int process_arguments(int argc, char **argv){
00158        int x;
00159 
00160        /* no options were supplied */
00161        if(argc<5)
00162               return ERROR;
00163 
00164        /* get the destination network address */
00165        strncpy(dest_network,argv[1],sizeof(dest_network)-1);
00166        dest_network[sizeof(dest_network)-1]='\x0';
00167 
00168        /* get the destination host address */
00169        strncpy(dest_address,argv[2],sizeof(dest_address)-1);
00170        dest_address[sizeof(dest_address)-1]='\x0';
00171 
00172        /* get the round trip time variables */
00173        wrtt=atoi(argv[3]);
00174        crtt=atoi(argv[4]);
00175 
00176        /* process remaining arguments */
00177        for(x=6;x<=argc;x++){
00178 
00179               /* we got the timeout to use */
00180               if(!strcmp(argv[x-1],"-to")){
00181                      if(x<argc){
00182                             socket_timeout=atoi(argv[x]);
00183                             if(socket_timeout<=0)
00184                                    return ERROR;
00185                             x++;
00186                              }
00187                      else
00188                             return ERROR;
00189                       }
00190 
00191               /* else we got something else... */
00192               else
00193                      return ERROR;
00194                }
00195 
00196        return OK;
00197         }
00198 
00199 
00200 
00201