1 /******************************************************************************************
5 * Program: IPX ping plugin for Nagios
7 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
9 * Last Modified: 09-24-1999
11 * Command line: CHECK_IPXPING <dest_network> <dest_address> <wrtt> <crtt>
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.
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.
28 *****************************************************************************************/
35 /* this should be moved out to the configure script! */
36 #define IPXPING_COMMAND "/tmp/ipxping/ipxping"
38 /* these should be moved to the common header file */
39 #define MAX_IPXNET_ADDRESS_LENGTH 12
40 #define MAX_IPXHOST_ADDRESS_LENGTH 18
42 int socket_timeout
=DEFAULT_SOCKET_TIMEOUT
;
43 char dest_network
[MAX_IPXNET_ADDRESS_LENGTH
];
44 char dest_address
[MAX_IPXHOST_ADDRESS_LENGTH
];
48 int process_arguments(int,char **);
50 FILE * spopen(const char *);
53 int main(int argc
, char **argv
){
54 char command_line
[MAX_INPUT_BUFFER
];
59 char input_buffer
[MAX_INPUT_BUFFER
];
63 if(process_arguments(argc
,argv
)!=OK
){
64 printf("Incorrect arguments supplied\n");
66 printf("IPX ping plugin for Nagios\n");
67 printf("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n");
68 printf("Last Modified: 09-24-1999\n");
69 printf("License: GPL\n");
71 printf("Usage: %s <dest_network> <dest_address> <wrtt> <crtt> [-to to_sec]\n",argv
[0]);
74 printf(" <dest_network> = IPX network that the remote host lies on. (Hex Format - 00:00:00:00)\n");
75 printf(" <dest_address> = MAC address of the remote host. (Hex Format - 00:00:00:00:00:00)\n");
76 printf(" <wrtt> = Round trip time in milliseconds necessary to result in a WARNING state\n");
77 printf(" <crtt> = Round trip time in milliseconds necessary to result in a CRITICAL state\n");
78 printf(" [to_sec] = Seconds before we should timeout waiting for ping result. Default = %d sec\n",DEFAULT_SOCKET_TIMEOUT
);
81 printf("This plugin will use the /usr/bin/ipxping command to ping the specified host using\n");
82 printf("the IPX protocol. IPX support must be compiled into the kernel and your host must\n");
83 printf("be correctly configured to use IPX before this plugin will work! An RPM package of\n");
84 printf("the ipxping binary can be found at...\n");
85 printf("http://www.rpmfind.net/linux/RPM/contrib/libc5/i386/ipxping-0.0-2.i386.shtml\n");
90 /* create the command line to use... */
91 sprintf(command_line
,"%s %s %s",IPXPING_COMMAND
,dest_network
,dest_address
);
93 /* initialize alarm signal handling */
94 signal(SIGALRM
,socket_timeout_alarm_handler
);
96 /* set socket timeout */
97 alarm(socket_timeout
);
100 fp
= spopen(command_line
);
102 printf("Unable to open pipe: %s",command_line
);
103 return STATE_UNKNOWN
;
107 while(fgets(input_buffer
,MAX_INPUT_BUFFER
-1,fp
)){
111 /* skip the first line of the output */
115 /* we didn't get the "is alive" */
116 if(current_line
==2 && !strstr(input_buffer
,"is alive"))
117 result
=STATE_CRITICAL
;
119 /* get the round trip time */
121 substr
=strtok(input_buffer
,":");
122 substr
=strtok(NULL
,"\n");
126 /* get the number of bytes returned */
127 if(current_line
==4 && strstr(input_buffer
,"bytes returned")){
128 bytes_returned
=atoi(input_buffer
);
135 /* reset the alarm */
138 if(current_line
==1 || result
==STATE_CRITICAL
)
139 printf("IPX Ping problem - No response from host\n");
143 result
=STATE_CRITICAL
;
145 result
=STATE_WARNING
;
147 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
);
156 /* process all arguments passed on the command line */
157 int process_arguments(int argc
, char **argv
){
160 /* no options were supplied */
164 /* get the destination network address */
165 strncpy(dest_network
,argv
[1],sizeof(dest_network
)-1);
166 dest_network
[sizeof(dest_network
)-1]='\x0';
168 /* get the destination host address */
169 strncpy(dest_address
,argv
[2],sizeof(dest_address
)-1);
170 dest_address
[sizeof(dest_address
)-1]='\x0';
172 /* get the round trip time variables */
176 /* process remaining arguments */
177 for(x
=6;x
<=argc
;x
++){
179 /* we got the timeout to use */
180 if(!strcmp(argv
[x
-1],"-to")){
182 socket_timeout
=atoi(argv
[x
]);
183 if(socket_timeout
<=0)
191 /* else we got something else... */