summaryrefslogtreecommitdiffstats
path: root/contrib/check_ipxping.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_ipxping.c')
-rw-r--r--contrib/check_ipxping.c200
1 files changed, 200 insertions, 0 deletions
diff --git a/contrib/check_ipxping.c b/contrib/check_ipxping.c
new file mode 100644
index 0000000..1ba10fe
--- /dev/null
+++ b/contrib/check_ipxping.c
@@ -0,0 +1,200 @@
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
30#include "../common/config.h"
31#include "../common/common.h"
32#include "netutils.h"
33
34/* this should be moved out to the configure script! */
35#define IPXPING_COMMAND "/tmp/ipxping/ipxping"
36
37/* these should be moved to the common header file */
38#define MAX_IPXNET_ADDRESS_LENGTH 12
39#define MAX_IPXHOST_ADDRESS_LENGTH 18
40
41int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
42char dest_network[MAX_IPXNET_ADDRESS_LENGTH];
43char dest_address[MAX_IPXHOST_ADDRESS_LENGTH];
44int wrtt;
45int crtt;
46
47int process_arguments(int,char **);
48
49FILE * spopen(const char *);
50int spclose(FILE *);
51
52int main(int argc, char **argv){
53 char command_line[MAX_INPUT_BUFFER];
54 int rtt;
55 int bytes_returned;
56 int result=STATE_OK;
57 FILE *fp;
58 char input_buffer[MAX_INPUT_BUFFER];
59 char *substr;
60 int current_line;
61
62 if(process_arguments(argc,argv)!=OK){
63 printf("Incorrect arguments supplied\n");
64 printf("\n");
65 printf("IPX ping plugin for Nagios\n");
66 printf("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n");
67 printf("Last Modified: 09-24-1999\n");
68 printf("License: GPL\n");
69 printf("\n");
70 printf("Usage: %s <dest_network> <dest_address> <wrtt> <crtt> [-to to_sec]\n",argv[0]);
71 printf("\n");
72 printf("Options:\n");
73 printf(" <dest_network> = IPX network that the remote host lies on. (Hex Format - 00:00:00:00)\n");
74 printf(" <dest_address> = MAC address of the remote host. (Hex Format - 00:00:00:00:00:00)\n");
75 printf(" <wrtt> = Round trip time in milliseconds necessary to result in a WARNING state\n");
76 printf(" <crtt> = Round trip time in milliseconds necessary to result in a CRITICAL state\n");
77 printf(" [to_sec] = Seconds before we should timeout waiting for ping result. Default = %d sec\n",DEFAULT_SOCKET_TIMEOUT);
78 printf("\n");
79 printf("Notes:\n");
80 printf("This plugin will use the /usr/bin/ipxping command to ping the specified host using\n");
81 printf("the IPX protocol. IPX support must be compiled into the kernel and your host must\n");
82 printf("be correctly configured to use IPX before this plugin will work! An RPM package of\n");
83 printf("the ipxping binary can be found at...\n");
84 printf("http://www.rpmfind.net/linux/RPM/contrib/libc5/i386/ipxping-0.0-2.i386.shtml\n");
85 printf("\n");
86 return STATE_UNKNOWN;
87 }
88
89 /* create the command line to use... */
90 sprintf(command_line,"%s %s %s",IPXPING_COMMAND,dest_network,dest_address);
91
92 /* initialize alarm signal handling */
93 signal(SIGALRM,socket_timeout_alarm_handler);
94
95 /* set socket timeout */
96 alarm(socket_timeout);
97
98 /* run the command */
99 fp = spopen(command_line);
100 if(fp==NULL){
101 printf("Unable to open pipe: %s",command_line);
102 return STATE_UNKNOWN;
103 }
104
105 current_line=0;
106 while(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){
107
108 current_line++;
109
110 /* skip the first line of the output */
111 if(current_line==1)
112 continue;
113
114 /* we didn't get the "is alive" */
115 if(current_line==2 && !strstr(input_buffer,"is alive"))
116 result=STATE_CRITICAL;
117
118 /* get the round trip time */
119 if(current_line==3){
120 substr=strtok(input_buffer,":");
121 substr=strtok(NULL,"\n");
122 rtt=atoi(substr);
123 }
124
125 /* get the number of bytes returned */
126 if(current_line==4 && strstr(input_buffer,"bytes returned")){
127 bytes_returned=atoi(input_buffer);
128 }
129 }
130
131 /* close the pipe */
132 spclose(fp);
133
134 /* reset the alarm */
135 alarm(0);
136
137 if(current_line==1 || result==STATE_CRITICAL)
138 printf("IPX Ping problem - No response from host\n");
139 else{
140
141 if(rtt>crtt)
142 result=STATE_CRITICAL;
143 else if(rtt>wrtt)
144 result=STATE_WARNING;
145
146 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);
147 }
148
149
150 return result;
151 }
152
153
154
155/* process all arguments passed on the command line */
156int process_arguments(int argc, char **argv){
157 int x;
158
159 /* no options were supplied */
160 if(argc<5)
161 return ERROR;
162
163 /* get the destination network address */
164 strncpy(dest_network,argv[1],sizeof(dest_network)-1);
165 dest_network[sizeof(dest_network)-1]='\x0';
166
167 /* get the destination host address */
168 strncpy(dest_address,argv[2],sizeof(dest_address)-1);
169 dest_address[sizeof(dest_address)-1]='\x0';
170
171 /* get the round trip time variables */
172 wrtt=atoi(argv[3]);
173 crtt=atoi(argv[4]);
174
175 /* process remaining arguments */
176 for(x=6;x<=argc;x++){
177
178 /* we got the timeout to use */
179 if(!strcmp(argv[x-1],"-to")){
180 if(x<argc){
181 socket_timeout=atoi(argv[x]);
182 if(socket_timeout<=0)
183 return ERROR;
184 x++;
185 }
186 else
187 return ERROR;
188 }
189
190 /* else we got something else... */
191 else
192 return ERROR;
193 }
194
195 return OK;
196 }
197
198
199
200