diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-18 03:45:02 (GMT) |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-18 03:45:02 (GMT) |
commit | 1fb42320aa0519536b58994e8fdcf16c66dba246 (patch) | |
tree | 15fba2f0884bd226c67dac3ff8c0d8269384ceee /plugins | |
parent | 57351c2f6dafa37d797d2cbad8792cb70ba08177 (diff) | |
download | monitoring-plugins-1fb42320aa0519536b58994e8fdcf16c66dba246.tar.gz |
remove broken call_getopt stuff
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@136 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ping.c | 204 |
1 files changed, 96 insertions, 108 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 835d9c1..56c9557 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -85,6 +85,7 @@ main (int argc, char **argv) | |||
85 | 85 | ||
86 | if (process_arguments (argc, argv) == ERROR) | 86 | if (process_arguments (argc, argv) == ERROR) |
87 | usage ("Could not parse arguments"); | 87 | usage ("Could not parse arguments"); |
88 | exit; | ||
88 | 89 | ||
89 | /* does the host address of number of packets argument come first? */ | 90 | /* does the host address of number of packets argument come first? */ |
90 | #ifdef PING_PACKETS_FIRST | 91 | #ifdef PING_PACKETS_FIRST |
@@ -150,7 +151,20 @@ main (int argc, char **argv) | |||
150 | int | 151 | int |
151 | process_arguments (int argc, char **argv) | 152 | process_arguments (int argc, char **argv) |
152 | { | 153 | { |
153 | int c; | 154 | int c, i = 1; |
155 | |||
156 | #ifdef HAVE_GETOPT_H | ||
157 | int option_index = 0; | ||
158 | static struct option long_options[] = { | ||
159 | STD_LONG_OPTS, | ||
160 | {"packets", required_argument, 0, 'p'}, | ||
161 | {"nohtml", no_argument, 0, 'n'}, | ||
162 | {"link", no_argument, 0, 'L'}, | ||
163 | {0, 0, 0, 0} | ||
164 | }; | ||
165 | #endif | ||
166 | |||
167 | #define OPTCHARS "Vvht:c:w:H:p:nL" | ||
154 | 168 | ||
155 | if (argc < 2) | 169 | if (argc < 2) |
156 | return ERROR; | 170 | return ERROR; |
@@ -162,138 +176,45 @@ process_arguments (int argc, char **argv) | |||
162 | strcpy (argv[c], "-n"); | 176 | strcpy (argv[c], "-n"); |
163 | } | 177 | } |
164 | 178 | ||
165 | c = 0; | ||
166 | while ((c += call_getopt (argc - c, &argv[c])) < argc) { | ||
167 | |||
168 | if (is_option (argv[c])) | ||
169 | continue; | ||
170 | |||
171 | if (server_address == NULL) { | ||
172 | if (is_host (argv[c]) == FALSE) { | ||
173 | printf ("Invalid host name/address: %s\n\n", argv[c]); | ||
174 | return ERROR; | ||
175 | } | ||
176 | server_address = argv[c]; | ||
177 | } | ||
178 | else if (wpl == UNKNOWN_PACKET_LOSS) { | ||
179 | if (is_intpercent (argv[c]) == FALSE) { | ||
180 | printf ("<wpl> (%s) must be an integer percentage\n", argv[c]); | ||
181 | return ERROR; | ||
182 | } | ||
183 | wpl = atoi (argv[c]); | ||
184 | } | ||
185 | else if (cpl == UNKNOWN_PACKET_LOSS) { | ||
186 | if (is_intpercent (argv[c]) == FALSE) { | ||
187 | printf ("<cpl> (%s) must be an integer percentage\n", argv[c]); | ||
188 | return ERROR; | ||
189 | } | ||
190 | cpl = atoi (argv[c]); | ||
191 | } | ||
192 | else if (wrta == UNKNOWN_TRIP_TIME) { | ||
193 | if (is_negative (argv[c])) { | ||
194 | printf ("<wrta> (%s) must be a non-negative number\n", argv[c]); | ||
195 | return ERROR; | ||
196 | } | ||
197 | wrta = atof (argv[c]); | ||
198 | } | ||
199 | else if (crta == UNKNOWN_TRIP_TIME) { | ||
200 | if (is_negative (argv[c])) { | ||
201 | printf ("<crta> (%s) must be a non-negative number\n", argv[c]); | ||
202 | return ERROR; | ||
203 | } | ||
204 | crta = atof (argv[c]); | ||
205 | } | ||
206 | else if (max_packets == -1) { | ||
207 | if (is_intnonneg (argv[c])) { | ||
208 | max_packets = atoi (argv[c]); | ||
209 | } | ||
210 | else { | ||
211 | printf ("<max_packets> (%s) must be a non-negative number\n", | ||
212 | argv[c]); | ||
213 | return ERROR; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | } | ||
218 | |||
219 | return validate_arguments (); | ||
220 | } | ||
221 | |||
222 | int | ||
223 | call_getopt (int argc, char **argv) | ||
224 | { | ||
225 | int c, i = 0; | ||
226 | |||
227 | #ifdef HAVE_GETOPT_H | ||
228 | int option_index = 0; | ||
229 | static struct option long_options[] = { | ||
230 | {"help", no_argument, 0, 'h'}, | ||
231 | {"version", no_argument, 0, 'V'}, | ||
232 | {"verbose", no_argument, 0, 'v'}, | ||
233 | {"nohtml", no_argument, 0, 'n'}, | ||
234 | {"link", no_argument, 0, 'L'}, | ||
235 | {"timeout", required_argument, 0, 't'}, | ||
236 | {"critical", required_argument, 0, 'c'}, | ||
237 | {"warning", required_argument, 0, 'w'}, | ||
238 | {"hostname", required_argument, 0, 'H'}, | ||
239 | {"packets", required_argument, 0, 'p'}, | ||
240 | {0, 0, 0, 0} | ||
241 | }; | ||
242 | #endif | ||
243 | |||
244 | while (1) { | 179 | while (1) { |
245 | #ifdef HAVE_GETOPT_H | 180 | #ifdef HAVE_GETOPT_H |
246 | c = | 181 | c = getopt_long (argc, argv, OPTCHARS, long_options, &option_index); |
247 | getopt_long (argc, argv, "+hVvt:c:w:H:p:nL", long_options, | ||
248 | &option_index); | ||
249 | #else | 182 | #else |
250 | c = getopt (argc, argv, "+hVvt:c:w:H:p:nL"); | 183 | c = getopt (argc, argv, OPTCHARS); |
251 | #endif | 184 | #endif |
252 | 185 | if (c == -1 || c == EOF) | |
253 | i++; | ||
254 | |||
255 | if (c == -1 || c == EOF || c == 1) | ||
256 | break; | 186 | break; |
257 | 187 | ||
258 | switch (c) { | 188 | switch (c) { |
259 | case 't': | 189 | case '?': /* usage */ |
260 | case 'c': | ||
261 | case 'w': | ||
262 | case 'H': | ||
263 | case 'p': | ||
264 | i++; | ||
265 | } | ||
266 | |||
267 | switch (c) { | ||
268 | case '?': /* print short usage statement if args not parsable */ | ||
269 | usage2 ("Unknown argument", optarg); | 190 | usage2 ("Unknown argument", optarg); |
270 | case 'h': /* help */ | 191 | case 'h': /* help */ |
271 | print_help (); | 192 | print_help (); |
272 | exit (STATE_OK); | 193 | exit (STATE_OK); |
273 | case 'V': /* version */ | 194 | case 'V': /* version */ |
274 | print_revision (PROGNAME, REVISION); | 195 | print_revision (PROGNAME, REVISION); |
275 | exit (STATE_OK); | 196 | exit (STATE_OK); |
276 | case 't': /* timeout period */ | 197 | case 't': /* timeout period */ |
277 | timeout_interval = atoi (optarg); | 198 | timeout_interval = atoi (optarg); |
278 | break; | 199 | break; |
279 | case 'v': /* verbose mode */ | 200 | case 'v': /* verbose mode */ |
280 | verbose = TRUE; | 201 | verbose = TRUE; |
281 | break; | 202 | break; |
282 | case 'H': /* hostname */ | 203 | case 'H': /* hostname */ |
283 | if (is_host (optarg) == FALSE) | 204 | if (is_host (optarg) == FALSE) |
284 | usage2 ("Invalid host name/address", optarg); | 205 | usage2 ("Invalid host name/address", optarg); |
285 | server_address = optarg; | 206 | server_address = optarg; |
286 | break; | 207 | break; |
287 | case 'p': /* number of packets to send */ | 208 | case 'p': /* number of packets to send */ |
288 | if (is_intnonneg (optarg)) | 209 | if (is_intnonneg (optarg)) |
289 | max_packets = atoi (optarg); | 210 | max_packets = atoi (optarg); |
290 | else | 211 | else |
291 | usage2 ("<max_packets> (%s) must be a non-negative number\n", optarg); | 212 | usage2 ("<max_packets> (%s) must be a non-negative number\n", optarg); |
292 | break; | 213 | break; |
293 | case 'n': /* no HTML */ | 214 | case 'n': /* no HTML */ |
294 | display_html = FALSE; | 215 | display_html = FALSE; |
295 | break; | 216 | break; |
296 | case 'L': /* show HTML */ | 217 | case 'L': /* show HTML */ |
297 | display_html = TRUE; | 218 | display_html = TRUE; |
298 | break; | 219 | break; |
299 | case 'c': | 220 | case 'c': |
@@ -305,7 +226,75 @@ call_getopt (int argc, char **argv) | |||
305 | } | 226 | } |
306 | } | 227 | } |
307 | 228 | ||
308 | return i; | 229 | c = optind; |
230 | if (c == argc) | ||
231 | return validate_arguments (); | ||
232 | |||
233 | if (server_address == NULL) { | ||
234 | if (is_host (argv[c]) == FALSE) { | ||
235 | printf ("Invalid host name/address: %s\n\n", argv[c]); | ||
236 | return ERROR; | ||
237 | } else { | ||
238 | server_address = argv[c++]; | ||
239 | if (c == argc) | ||
240 | return validate_arguments (); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | if (wpl == UNKNOWN_PACKET_LOSS) { | ||
245 | if (is_intpercent (argv[c]) == FALSE) { | ||
246 | printf ("<wpl> (%s) must be an integer percentage\n", argv[c]); | ||
247 | return ERROR; | ||
248 | } else { | ||
249 | wpl = atoi (argv[c++]); | ||
250 | if (c == argc) | ||
251 | return validate_arguments (); | ||
252 | } | ||
253 | } | ||
254 | |||
255 | if (cpl == UNKNOWN_PACKET_LOSS) { | ||
256 | if (is_intpercent (argv[c]) == FALSE) { | ||
257 | printf ("<cpl> (%s) must be an integer percentage\n", argv[c]); | ||
258 | return ERROR; | ||
259 | } else { | ||
260 | cpl = atoi (argv[c++]); | ||
261 | if (c == argc) | ||
262 | return validate_arguments (); | ||
263 | } | ||
264 | } | ||
265 | |||
266 | if (wrta == UNKNOWN_TRIP_TIME) { | ||
267 | if (is_negative (argv[c])) { | ||
268 | printf ("<wrta> (%s) must be a non-negative number\n", argv[c]); | ||
269 | return ERROR; | ||
270 | } else { | ||
271 | wrta = atof (argv[c++]); | ||
272 | if (c == argc) | ||
273 | return validate_arguments (); | ||
274 | } | ||
275 | } | ||
276 | |||
277 | if (crta == UNKNOWN_TRIP_TIME) { | ||
278 | if (is_negative (argv[c])) { | ||
279 | printf ("<crta> (%s) must be a non-negative number\n", argv[c]); | ||
280 | return ERROR; | ||
281 | } else { | ||
282 | crta = atof (argv[c++]); | ||
283 | if (c == argc) | ||
284 | return validate_arguments (); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | if (max_packets == -1) { | ||
289 | if (is_intnonneg (argv[c])) { | ||
290 | max_packets = atoi (argv[c++]); | ||
291 | } else { | ||
292 | printf ("<max_packets> (%s) must be a non-negative number\n", argv[c]); | ||
293 | return ERROR; | ||
294 | } | ||
295 | } | ||
296 | |||
297 | return validate_arguments (); | ||
309 | } | 298 | } |
310 | 299 | ||
311 | int | 300 | int |
@@ -319,7 +308,6 @@ get_threshold (char *arg, float *trta, int *tpl) | |||
319 | return OK; | 308 | return OK; |
320 | else | 309 | else |
321 | usage2 ("%s: Warning threshold must be integer or percentage!\n\n", arg); | 310 | usage2 ("%s: Warning threshold must be integer or percentage!\n\n", arg); |
322 | |||
323 | } | 311 | } |
324 | 312 | ||
325 | int | 313 | int |