summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2789d11)
raw | patch | inline | side by side (parent: 2789d11)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Mon, 3 Mar 2003 03:49:40 +0000 (03:49 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Mon, 3 Mar 2003 03:49:40 +0000 (03:49 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@362 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_ping.c | patch | blob | history |
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index c75ad587d84a450c4f275567188db563d945fd18..480f631e373439d9aa6c0ac1764c8dad077f30b8 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
{
char *command_line = NULL;
int result = STATE_UNKNOWN;
+ int this_result = STATE_UNKNOWN;
int i;
addresses = malloc (max_addr);
printf ("%s ==> ", command_line);
/* run the command */
- run_ping (command_line, addresses[i]);
+ this_result = run_ping (command_line, addresses[i]);
if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) {
printf ("%s\n", command_line);
}
if (pl >= cpl || rta >= crta || rta < 0)
- result = STATE_CRITICAL;
+ this_result = STATE_CRITICAL;
else if (pl >= wpl || rta >= wrta)
- result = STATE_WARNING;
- else if (pl < wpl && rta < wrta && pl >= 0 && rta >= 0)
- /* cannot use the max function because STATE_UNKNOWN is now 3 gt STATE_OK
- result = max (result, STATE_OK); */
- if( !( (result == STATE_WARNING) || (result == STATE_CRITICAL) ) ) {
- result = STATE_OK;
- }
+ this_result = STATE_WARNING;
+ else if (pl >= 0 && rta >= 0)
+ this_result = max_state (STATE_OK, this_result);
+ if (n_addresses > 1 && this_result != STATE_UNKNOWN)
+ terminate (STATE_OK, "%s is alive\n", addresses[i]);
+
if (display_html == TRUE)
printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]);
if (pl == 100)
- printf ("PING %s - %sPacket loss = %d%%", state_text (result), warn_text,
+ printf ("PING %s - %sPacket loss = %d%%", state_text (this_result), warn_text,
pl);
else
printf ("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms",
- state_text (result), warn_text, pl, rta);
+ state_text (this_result), warn_text, pl, rta);
if (display_html == TRUE)
printf ("</A>");
printf ("\n");
if (verbose)
printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl);
+
+ result = max_state (result, this_result);
+
}
return result;
process_arguments (int argc, char **argv)
{
int c = 1;
+ char *ptr;
#ifdef HAVE_GETOPT_H
int option_index = 0;
};
#endif
-#define OPTCHARS "Vvht:c:w:H:p:nL"
+#define OPTCHARS "VvhnLt:c:w:H:p:"
if (argc < 2)
return ERROR;
verbose = TRUE;
break;
case 'H': /* hostname */
- if (is_host (optarg) == FALSE)
- usage2 ("Invalid host name/address", optarg);
- n_addresses++;
- if (n_addresses > max_addr) {
- max_addr *= 2;
- addresses = realloc (addresses, max_addr);
- if (addresses == NULL)
- terminate (STATE_UNKNOWN, "Could not realloc() addresses\n");
+ ptr=optarg;
+ while (1) {
+ n_addresses++;
+ if (n_addresses > max_addr) {
+ max_addr *= 2;
+ addresses = realloc (addresses, max_addr);
+ if (addresses == NULL)
+ terminate (STATE_UNKNOWN, "Could not realloc() addresses\n");
+ }
+ addresses[n_addresses-1] = ptr;
+ if (ptr = index (ptr, ',')) {
+ strcpy (ptr, "");
+ ptr += sizeof(char);
+ } else {
+ break;
+ }
}
- addresses[n_addresses-1] = optarg;
break;
case 'p': /* number of packets to send */
if (is_intnonneg (optarg))
validate_arguments ()
{
float max_seconds;
+ int i;
if (wrta == UNKNOWN_TRIP_TIME) {
printf ("<wrta> was not set\n");
if (max_seconds > timeout_interval)
timeout_interval = (int)max_seconds;
+ for (i=0; i<n_addresses; i++) {
+ if (is_host(addresses[i]) == FALSE)
+ usage2 ("Invalid host name/address", addresses[i]);
+ }
+
return OK;
}
\f