summaryrefslogtreecommitdiffstats
path: root/plugins/check_ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ping.c')
-rw-r--r--plugins/check_ping.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 074519d..260e1b6 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -14,6 +14,8 @@
14 along with this program; if not, write to the Free Software 14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 16
17 $Id$
18
17******************************************************************************/ 19******************************************************************************/
18 20
19const char *progname = "check_ping"; 21const char *progname = "check_ping";
@@ -60,8 +62,6 @@ char *warn_text;
60 62
61 63
62 64
63
64
65int 65int
66main (int argc, char **argv) 66main (int argc, char **argv)
67{ 67{
@@ -79,7 +79,7 @@ main (int argc, char **argv)
79 addresses[0] = NULL; 79 addresses[0] = NULL;
80 80
81 if (process_arguments (argc, argv) == ERROR) 81 if (process_arguments (argc, argv) == ERROR)
82 usage (_("Could not parse arguments")); 82 usage (_("check_ping: could not parse arguments\n"));
83 83
84 /* Set signal handling and alarm */ 84 /* Set signal handling and alarm */
85 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { 85 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) {
@@ -159,9 +159,6 @@ main (int argc, char **argv)
159 159
160 160
161 161
162
163
164
165/* process command-line arguments */ 162/* process command-line arguments */
166int 163int
167process_arguments (int argc, char **argv) 164process_arguments (int argc, char **argv)
@@ -198,8 +195,9 @@ process_arguments (int argc, char **argv)
198 195
199 switch (c) { 196 switch (c) {
200 case '?': /* usage */ 197 case '?': /* usage */
201 usage3 (_("Unknown argument"), optopt); 198 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
202 break; 199 print_usage ();
200 exit (STATE_UNKNOWN);
203 case 'h': /* help */ 201 case 'h': /* help */
204 print_help (); 202 print_help ();
205 exit (STATE_OK); 203 exit (STATE_OK);
@@ -270,7 +268,7 @@ process_arguments (int argc, char **argv)
270 268
271 if (addresses[0] == NULL) { 269 if (addresses[0] == NULL) {
272 if (is_host (argv[c]) == FALSE) { 270 if (is_host (argv[c]) == FALSE) {
273 usage2 (_("Invalid host name/address"), argv[c]); 271 usage2 (_("Invalid hostname/address"), argv[c]);
274 } else { 272 } else {
275 addresses[0] = argv[c++]; 273 addresses[0] = argv[c++];
276 n_addresses++; 274 n_addresses++;
@@ -335,6 +333,8 @@ process_arguments (int argc, char **argv)
335 return validate_arguments (); 333 return validate_arguments ();
336} 334}
337 335
336
337
338int 338int
339get_threshold (char *arg, float *trta, int *tpl) 339get_threshold (char *arg, float *trta, int *tpl)
340{ 340{
@@ -349,6 +349,8 @@ get_threshold (char *arg, float *trta, int *tpl)
349 return STATE_UNKNOWN; 349 return STATE_UNKNOWN;
350} 350}
351 351
352
353
352int 354int
353validate_arguments () 355validate_arguments ()
354{ 356{
@@ -389,7 +391,7 @@ validate_arguments ()
389 391
390 for (i=0; i<n_addresses; i++) { 392 for (i=0; i<n_addresses; i++) {
391 if (is_host(addresses[i]) == FALSE) 393 if (is_host(addresses[i]) == FALSE)
392 usage2 (_("Invalid host name/address"), addresses[i]); 394 usage2 (_("Invalid hostname/address"), addresses[i]);
393 } 395 }
394 396
395 return OK; 397 return OK;
@@ -397,9 +399,6 @@ validate_arguments ()
397 399
398 400
399 401
400
401
402
403int 402int
404run_ping (const char *cmd, const char *addr) 403run_ping (const char *cmd, const char *addr)
405{ 404{
@@ -444,7 +443,7 @@ run_ping (const char *cmd, const char *addr)
444 443
445 /* check stderr, setting at least WARNING if there is output here */ 444 /* check stderr, setting at least WARNING if there is output here */
446 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) 445 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
447 if (! strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP")) 446 if (! strstr(buf,"WARNING - no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
448 result = max_state (STATE_WARNING, error_scan (buf, addr)); 447 result = max_state (STATE_WARNING, error_scan (buf, addr));
449 448
450 (void) fclose (child_stderr); 449 (void) fclose (child_stderr);
@@ -462,17 +461,15 @@ run_ping (const char *cmd, const char *addr)
462 461
463 462
464 463
465
466
467int 464int
468error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) 465error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
469{ 466{
470 if (strstr (buf, "Network is unreachable")) 467 if (strstr (buf, "Network is unreachable"))
471 die (STATE_CRITICAL, _("PING CRITICAL - Network unreachable (%s)"), addr); 468 die (STATE_CRITICAL, _("CRITICAL - Network unreachable (%s)"), addr);
472 else if (strstr (buf, "Destination Host Unreachable")) 469 else if (strstr (buf, "Destination Host Unreachable"))
473 die (STATE_CRITICAL, _("PING CRITICAL - Host Unreachable (%s)"), addr); 470 die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)"), addr);
474 else if (strstr (buf, "unknown host" )) 471 else if (strstr (buf, "unknown host" ))
475 die (STATE_CRITICAL, _("PING CRITICAL - Host not found (%s)"), addr); 472 die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr);
476 473
477 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) { 474 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
478 if (warn_text == NULL) 475 if (warn_text == NULL)
@@ -488,9 +485,6 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
488 485
489 486
490 487
491
492
493
494void 488void
495print_usage (void) 489print_usage (void)
496{ 490{
@@ -500,6 +494,8 @@ print_usage (void)
500 printf (_(UT_HLP_VRS), progname, progname); 494 printf (_(UT_HLP_VRS), progname, progname);
501} 495}
502 496
497
498
503void 499void
504print_help (void) 500print_help (void)
505{ 501{