diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index ab5e0cc327271d57446e703a0e9be96b7c869798..260e1b651a02921df0225d1147c7d9d26d3f6f25 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ $Id$
+
******************************************************************************/
const char *progname = "check_ping";
-
-\f
int
main (int argc, char **argv)
{
char *cmd = NULL;
+ char *rawcmd = NULL;
int result = STATE_UNKNOWN;
int this_result = STATE_UNKNOWN;
int i;
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- addresses = malloc ((size_t)max_addr);
+ addresses = malloc (sizeof(char*) * max_addr);
+ addresses[0] = NULL;
if (process_arguments (argc, argv) == ERROR)
- usage (_("Could not parse arguments"));
+ usage (_("check_ping: could not parse arguments\n"));
/* Set signal handling and alarm */
if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) {
alarm (timeout_interval);
for (i = 0 ; i < n_addresses ; i++) {
+
+#ifdef PING6_COMMAND
+ if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
+ rawcmd = strdup(PING6_COMMAND);
+ else
+ rawcmd = strdup(PING_COMMAND);
+#else
+ rawcmd = strdup(PING_COMMAND);
+#endif
/* does the host address of number of packets argument come first? */
-#ifdef PING6_COMMAND
-# ifdef PING_PACKETS_FIRST
- if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
- asprintf (&cmd, PING6_COMMAND, max_packets, addresses[i]);
- else
- asprintf (&cmd, PING_COMMAND, max_packets, addresses[i]);
-# else
- if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
- asprintf (&cmd, PING6_COMMAND, addresses[i], max_packets);
- else
- asprintf (&cmd, PING_COMMAND, addresses[i], max_packets);
-# endif
-#else /* USE_IPV6 */
-# ifdef PING_PACKETS_FIRST
- asprintf (&cmd, PING_COMMAND, max_packets, addresses[i]);
+#ifdef PING_PACKETS_FIRST
+# ifdef PING_HAS_TIMEOUT
+ asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
# else
- asprintf (&cmd, PING_COMMAND, addresses[i], max_packets);
+ asprintf (&cmd, rawcmd, max_packets, addresses[i]);
# endif
-#endif /* USE_IPV6 */
+#else
+ asprintf (&cmd, rawcmd, addresses[i], max_packets);
+#endif
if (verbose)
printf ("%s ==> ", cmd);
printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl);
result = max_state (result, this_result);
-
+ free (rawcmd);
+ free (cmd);
}
return result;
-
-
-\f
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
switch (c) {
case '?': /* usage */
- usage3 (_("Unknown argument"), optopt);
- break;
+ printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
+ print_usage ();
+ exit (STATE_UNKNOWN);
case 'h': /* help */
print_help ();
exit (STATE_OK);
n_addresses++;
if (n_addresses > max_addr) {
max_addr *= 2;
- addresses = realloc (addresses, (size_t)max_addr);
+ addresses = realloc (addresses, sizeof(char*) * max_addr);
if (addresses == NULL)
die (STATE_UNKNOWN, _("Could not realloc() addresses\n"));
}
if (addresses[0] == NULL) {
if (is_host (argv[c]) == FALSE) {
- printf (_("Invalid host name/address: %s\n\n"), argv[c]);
- return ERROR;
+ usage2 (_("Invalid hostname/address"), argv[c]);
} else {
addresses[0] = argv[c++];
+ n_addresses++;
if (c == argc)
return validate_arguments ();
}
return validate_arguments ();
}
+
+
int
get_threshold (char *arg, float *trta, int *tpl)
{
return STATE_UNKNOWN;
}
+
+
int
validate_arguments ()
{
for (i=0; i<n_addresses; i++) {
if (is_host(addresses[i]) == FALSE)
- usage2 (_("Invalid host name/address"), addresses[i]);
+ usage2 (_("Invalid hostname/address"), addresses[i]);
}
return OK;
-
-
-\f
int
run_ping (const char *cmd, const char *addr)
{
sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss",&pl)==1 ||
sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time",&pl)==1 ||
sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time", &pl)==1 ||
+ sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time", &pl)==1 ||
sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss", &pl) == 1)
continue;
/* check stderr, setting at least WARNING if there is output here */
while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
- if (! strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
+ if (! strstr(buf,"WARNING - no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
result = max_state (STATE_WARNING, error_scan (buf, addr));
(void) fclose (child_stderr);
-
-
int
error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
{
if (strstr (buf, "Network is unreachable"))
- die (STATE_CRITICAL, _("PING CRITICAL - Network unreachable (%s)"), addr);
+ die (STATE_CRITICAL, _("CRITICAL - Network unreachable (%s)"), addr);
else if (strstr (buf, "Destination Host Unreachable"))
- die (STATE_CRITICAL, _("PING CRITICAL - Host Unreachable (%s)"), addr);
+ die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)"), addr);
else if (strstr (buf, "unknown host" ))
- die (STATE_CRITICAL, _("PING CRITICAL - Host not found (%s)"), addr);
+ die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr);
if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
if (warn_text == NULL)
-
-
-\f
void
print_usage (void)
{
printf (_(UT_HLP_VRS), progname, progname);
}
+
+
void
print_help (void)
{
print_revision (progname, revision);
- printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>"));
- printf (_(COPYRIGHT), copyright, email);
+ printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>");
+ printf (COPYRIGHT, copyright, email);
printf (_("Use ping to check connection statistics for a remote host.\n\n"));