check_ipxping.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /******************************************************************************************
  2. *
  3. * CHECK_IPXPING.C
  4. *
  5. * Program: IPX ping plugin for Nagios
  6. * License: GPL
  7. * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
  8. *
  9. * Last Modified: 09-24-1999
  10. *
  11. * Command line: CHECK_IPXPING <dest_network> <dest_address> <wrtt> <crtt>
  12. *
  13. * Description:
  14. *
  15. * This plugin will use the /usr/bin/ipxping command to ping the specified host using the
  16. * IPX protocol. Note: Linux users must have IPX support compiled into the kernerl and
  17. * must have IPX configured correctly in order for this plugin to work.
  18. * If the round trip time value is above the <wrtt> level, a STATE_WARNING is
  19. * returned. If it exceeds the <crtt> level, a STATE_CRITICAL is returned.
  20. *
  21. *
  22. *
  23. * IMPORTANT!!
  24. *
  25. * This plugin will only work with the ipxping command that has been ported to Linux.
  26. * The version for Sun takes different command line arguments and differs in its output.
  27. *
  28. *****************************************************************************************/
  29. #include "config.h"
  30. #include "common.h"
  31. #include "netutils.h"
  32. #include "popen.h"
  33. /* this should be moved out to the configure script! */
  34. #define IPXPING_COMMAND "/tmp/ipxping/ipxping"
  35. /* these should be moved to the common header file */
  36. #define MAX_IPXNET_ADDRESS_LENGTH 12
  37. #define MAX_IPXHOST_ADDRESS_LENGTH 18
  38. int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
  39. char dest_network[MAX_IPXNET_ADDRESS_LENGTH];
  40. char dest_address[MAX_IPXHOST_ADDRESS_LENGTH];
  41. int wrtt;
  42. int crtt;
  43. int process_arguments(int,char **);
  44. FILE * spopen(const char *);
  45. int spclose(FILE *);
  46. int main(int argc, char **argv){
  47. char command_line[MAX_INPUT_BUFFER];
  48. int rtt;
  49. int bytes_returned;
  50. int result=STATE_OK;
  51. FILE *fp;
  52. char input_buffer[MAX_INPUT_BUFFER];
  53. char *substr;
  54. int current_line;
  55. if(process_arguments(argc,argv)!=OK){
  56. printf("Incorrect arguments supplied\n");
  57. printf("\n");
  58. printf("IPX ping plugin for Nagios\n");
  59. printf("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n");
  60. printf("Last Modified: 09-24-1999\n");
  61. printf("License: GPL\n");
  62. printf("\n");
  63. printf("Usage: %s <dest_network> <dest_address> <wrtt> <crtt> [-to to_sec]\n",argv[0]);
  64. printf("\n");
  65. printf("Options:\n");
  66. printf(" <dest_network> = IPX network that the remote host lies on. (Hex Format - 00:00:00:00)\n");
  67. printf(" <dest_address> = MAC address of the remote host. (Hex Format - 00:00:00:00:00:00)\n");
  68. printf(" <wrtt> = Round trip time in milliseconds necessary to result in a WARNING state\n");
  69. printf(" <crtt> = Round trip time in milliseconds necessary to result in a CRITICAL state\n");
  70. printf(" [to_sec] = Seconds before we should timeout waiting for ping result. Default = %d sec\n",DEFAULT_SOCKET_TIMEOUT);
  71. printf("\n");
  72. printf("Notes:\n");
  73. printf("This plugin will use the /usr/bin/ipxping command to ping the specified host using\n");
  74. printf("the IPX protocol. IPX support must be compiled into the kernel and your host must\n");
  75. printf("be correctly configured to use IPX before this plugin will work! An RPM package of\n");
  76. printf("the ipxping binary can be found at...\n");
  77. printf("http://www.rpmfind.net/linux/RPM/contrib/libc5/i386/ipxping-0.0-2.i386.shtml\n");
  78. printf("\n");
  79. return STATE_UNKNOWN;
  80. }
  81. /* create the command line to use... */
  82. sprintf(command_line,"%s %s %s",IPXPING_COMMAND,dest_network,dest_address);
  83. /* initialize alarm signal handling */
  84. signal(SIGALRM,socket_timeout_alarm_handler);
  85. /* set socket timeout */
  86. alarm(socket_timeout);
  87. /* run the command */
  88. fp = spopen(command_line);
  89. if(fp==NULL){
  90. printf("Unable to open pipe: %s",command_line);
  91. return STATE_UNKNOWN;
  92. }
  93. current_line=0;
  94. while(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){
  95. current_line++;
  96. /* skip the first line of the output */
  97. if(current_line==1)
  98. continue;
  99. /* we didn't get the "is alive" */
  100. if(current_line==2 && !strstr(input_buffer,"is alive"))
  101. result=STATE_CRITICAL;
  102. /* get the round trip time */
  103. if(current_line==3){
  104. substr=strtok(input_buffer,":");
  105. substr=strtok(NULL,"\n");
  106. rtt=atoi(substr);
  107. }
  108. /* get the number of bytes returned */
  109. if(current_line==4 && strstr(input_buffer,"bytes returned")){
  110. bytes_returned=atoi(input_buffer);
  111. }
  112. }
  113. /* close the pipe */
  114. spclose(fp);
  115. /* reset the alarm */
  116. alarm(0);
  117. if(current_line==1 || result==STATE_CRITICAL)
  118. printf("IPX Ping problem - No response from host\n");
  119. else{
  120. if(rtt>crtt)
  121. result=STATE_CRITICAL;
  122. else if(rtt>wrtt)
  123. result=STATE_WARNING;
  124. 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);
  125. }
  126. return result;
  127. }
  128. /* process all arguments passed on the command line */
  129. int process_arguments(int argc, char **argv){
  130. int x;
  131. /* no options were supplied */
  132. if(argc<5)
  133. return ERROR;
  134. /* get the destination network address */
  135. strncpy(dest_network,argv[1],sizeof(dest_network)-1);
  136. dest_network[sizeof(dest_network)-1]='\x0';
  137. /* get the destination host address */
  138. strncpy(dest_address,argv[2],sizeof(dest_address)-1);
  139. dest_address[sizeof(dest_address)-1]='\x0';
  140. /* get the round trip time variables */
  141. wrtt=atoi(argv[3]);
  142. crtt=atoi(argv[4]);
  143. /* process remaining arguments */
  144. for(x=6;x<=argc;x++){
  145. /* we got the timeout to use */
  146. if(!strcmp(argv[x-1],"-to")){
  147. if(x<argc){
  148. socket_timeout=atoi(argv[x]);
  149. if(socket_timeout<=0)
  150. return ERROR;
  151. x++;
  152. }
  153. else
  154. return ERROR;
  155. }
  156. /* else we got something else... */
  157. else
  158. return ERROR;
  159. }
  160. return OK;
  161. }