[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ping.c,1.19,1.20
Karl DeBisschop
kdebisschop at users.sourceforge.net
Thu Aug 7 04:50:05 CEST 2003
- Previous message: [Nagiosplug-checkins] CVS: nagiosplug/plugins check_ping.c,1.18,1.19
- Next message: [Nagiosplug-checkins] CVS: nagiosplug/plugins check_by_ssh.c,1.13,1.14 check_disk.c,1.29,1.30 check_dns.c,1.18,1.19 check_fping.c,1.7,1.8 check_game.c,1.5,1.6 check_http.c,1.39,1.40 check_mrtg.c,1.6,1.7 check_mrtgtraf.c,1.6,1.7 check_nagios.c,1.8,1.9 check_nt.c,1.12,1.13 check_nwstat.c,1.9,1.10 check_overcr.c,1.4,1.5 check_radius.c,1.6,1.7 check_real.c,1.7,1.8 check_snmp.c,1.30,1.31 check_swap.c,1.15,1.16 check_tcp.c,1.32,1.33 check_time.c,1.6,1.7 negate.c,1.10,1.11 netutils.c,1.11,1.12 popen.c,1.4,1.5 utils.c,1.26,1.27 utils.h,1.9,1.10
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv22032
Modified Files:
check_ping.c
Log Message:
cleanup for better readability
Index: check_ping.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** check_ping.c 7 Aug 2003 09:51:58 -0000 1.19
--- check_ping.c 7 Aug 2003 11:49:47 -0000 1.20
***************
*** 27,35 ****
#include "utils.h"
! #define UNKNOWN_PACKET_LOSS 200 /* 200% */
#define UNKNOWN_TRIP_TIME -1.0 /* -1 seconds */
- #define DEFAULT_MAX_PACKETS 5 /* default no. of ICMP ECHO packets */
! #define WARN_DUPLICATES "DUPLICATES FOUND! "
int process_arguments (int, char **);
--- 27,37 ----
#include "utils.h"
! #define WARN_DUPLICATES "DUPLICATES FOUND! "
#define UNKNOWN_TRIP_TIME -1.0 /* -1 seconds */
! enum {
! UNKNOWN_PACKET_LOSS = 200, /* 200% */
! DEFAULT_MAX_PACKETS = 5 /* default no. of ICMP ECHO packets */
! };
int process_arguments (int, char **);
***************
*** 54,63 ****
int pl = UNKNOWN_PACKET_LOSS;
! char *warn_text = NULL;
int
main (int argc, char **argv)
{
! char *command_line = NULL;
int result = STATE_UNKNOWN;
int this_result = STATE_UNKNOWN;
--- 56,69 ----
int pl = UNKNOWN_PACKET_LOSS;
! char *warn_text = "";
!
!
+
+
int
main (int argc, char **argv)
{
! char *cmd = NULL;
int result = STATE_UNKNOWN;
int this_result = STATE_UNKNOWN;
***************
*** 85,114 ****
# ifdef PING_PACKETS_FIRST
if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
! asprintf (&command_line, PING6_COMMAND, max_packets, addresses[i]);
else
! asprintf (&command_line, PING_COMMAND, max_packets, addresses[i]);
# else
if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
! asprintf (&command_line, PING6_COMMAND, addresses[i], max_packets);
else
! asprintf (&command_line, PING_COMMAND, addresses[i], max_packets);
# endif
#else /* USE_IPV6 */
# ifdef PING_PACKETS_FIRST
! asprintf (&command_line, PING_COMMAND, max_packets, addresses[i]);
# else
! asprintf (&command_line, PING_COMMAND, addresses[i], max_packets);
# endif
#endif /* USE_IPV6 */
if (verbose)
! printf ("%s ==> ", command_line);
/* run the command */
! this_result = run_ping (command_line, addresses[i]);
if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) {
! printf ("%s\n", command_line);
! terminate (STATE_UNKNOWN,
_("Error: Could not interpret output from ping command\n"));
}
--- 91,120 ----
# 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]);
# else
! asprintf (&cmd, PING_COMMAND, addresses[i], max_packets);
# endif
#endif /* USE_IPV6 */
if (verbose)
! printf ("%s ==> ", cmd);
/* run the command */
! this_result = run_ping (cmd, addresses[i]);
if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) {
! printf ("%s\n", cmd);
! die (STATE_UNKNOWN,
_("Error: Could not interpret output from ping command\n"));
}
***************
*** 122,126 ****
if (n_addresses > 1 && this_result != STATE_UNKNOWN)
! terminate (STATE_OK, "%s is alive\n", addresses[i]);
if (display_html == TRUE)
--- 128,132 ----
if (n_addresses > 1 && this_result != STATE_UNKNOWN)
! die (STATE_OK, "%s is alive\n", addresses[i]);
if (display_html == TRUE)
***************
*** 145,150 ****
return result;
}
-
/* process command-line arguments */
int
--- 151,160 ----
return result;
}
+
+
+
+
+
/* process command-line arguments */
int
***************
*** 214,218 ****
addresses = realloc (addresses, max_addr);
if (addresses == NULL)
! terminate (STATE_UNKNOWN, _("Could not realloc() addresses\n"));
}
addresses[n_addresses-1] = ptr;
--- 224,228 ----
addresses = realloc (addresses, max_addr);
if (addresses == NULL)
! die (STATE_UNKNOWN, _("Could not realloc() addresses\n"));
}
addresses[n_addresses-1] = ptr;
***************
*** 308,312 ****
if (is_intnonneg (argv[c])) {
max_packets = atoi (argv[c++]);
! } else {
printf (_("<max_packets> (%s) must be a non-negative number\n"), argv[c]);
return ERROR;
--- 318,322 ----
if (is_intnonneg (argv[c])) {
max_packets = atoi (argv[c++]);
! } else {
printf (_("<max_packets> (%s) must be a non-negative number\n"), argv[c]);
return ERROR;
***************
*** 376,413 ****
return OK;
}
-
int
! run_ping (char *command_line, char *server_address)
{
char buf[MAX_INPUT_BUFFER];
int result = STATE_UNKNOWN;
! warn_text = malloc (1);
! if (warn_text == NULL)
! terminate (STATE_UNKNOWN, _("unable to malloc warn_text"));
! warn_text[0] = 0;
!
! if ((child_process = spopen (command_line)) == NULL) {
printf (_("Cannot open pipe: "));
! terminate (STATE_UNKNOWN, command_line);
}
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL)
! printf (_("Cannot open stderr for %s\n"), command_line);
while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
if (strstr (buf, _("(DUP!)"))) {
! /* cannot use the max function since STATE_UNKNOWN is max
! result = max (result, STATE_WARNING); */
! if( !(result == STATE_CRITICAL) ){
! result = STATE_WARNING;
! }
!
! warn_text = realloc (warn_text, strlen (WARN_DUPLICATES) + 1);
! if (warn_text == NULL)
! terminate (STATE_UNKNOWN, _("unable to realloc warn_text"));
! strcpy (warn_text, WARN_DUPLICATES);
}
--- 386,416 ----
return OK;
}
+
+
+
+
+
int
! run_ping (char *cmd, char *server_address)
{
char buf[MAX_INPUT_BUFFER];
int result = STATE_UNKNOWN;
! if ((child_process = spopen (cmd)) == NULL) {
printf (_("Cannot open pipe: "));
! die (STATE_UNKNOWN, cmd);
}
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL)
! printf (_("Cannot open stderr for %s\n"), cmd);
while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
if (strstr (buf, _("(DUP!)"))) {
! result = max_state (result, STATE_WARNING);
! warn_text = strdup (WARN_DUPLICATES);
! if (!warn_text)
! die (STATE_UNKNOWN, _("unable to realloc warn_text"));
}
***************
*** 435,439 ****
rta = crta;
-
/* check stderr */
while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
--- 438,441 ----
***************
*** 442,471 ****
if (strstr (buf, "Network is unreachable"))
! terminate (STATE_CRITICAL,
_("PING CRITICAL - Network unreachable (%s)"),
server_address);
else if (strstr (buf, "Destination Host Unreachable"))
! terminate (STATE_CRITICAL,
_("PING CRITICAL - Host Unreachable (%s)"),
server_address);
else if (strstr (buf, "unknown host" ))
! terminate (STATE_CRITICAL,
_("PING CRITICAL - Host not found (%s)"),
server_address);
- warn_text =
- realloc (warn_text, strlen (warn_text) + strlen (buf) + 2);
- if (warn_text == NULL)
- terminate (STATE_UNKNOWN, _("unable to realloc warn_text"));
if (strlen (warn_text) == 0)
! strcpy (warn_text, buf);
! else
! sprintf (warn_text, "%s %s", warn_text, buf);
! if (strstr (buf, "DUPLICATES FOUND")) {
! if( !(result == STATE_CRITICAL) ){
! result = STATE_WARNING;
! }
! }
else
result = STATE_CRITICAL ;
--- 444,466 ----
if (strstr (buf, "Network is unreachable"))
! die (STATE_CRITICAL,
_("PING CRITICAL - Network unreachable (%s)"),
server_address);
else if (strstr (buf, "Destination Host Unreachable"))
! die (STATE_CRITICAL,
_("PING CRITICAL - Host Unreachable (%s)"),
server_address);
else if (strstr (buf, "unknown host" ))
! die (STATE_CRITICAL,
_("PING CRITICAL - Host not found (%s)"),
server_address);
if (strlen (warn_text) == 0)
! warn_text = strdup (buf);
! else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1)
! die (STATE_UNKNOWN, _("unable to realloc warn_text"));
! if (strstr (buf, "DUPLICATES FOUND"))
! result = max_state (result, STATE_WARNING);
else
result = STATE_CRITICAL ;
***************
*** 482,485 ****
--- 477,484 ----
+
+
+
+
void
print_usage (void)
- Previous message: [Nagiosplug-checkins] CVS: nagiosplug/plugins check_ping.c,1.18,1.19
- Next message: [Nagiosplug-checkins] CVS: nagiosplug/plugins check_by_ssh.c,1.13,1.14 check_disk.c,1.29,1.30 check_dns.c,1.18,1.19 check_fping.c,1.7,1.8 check_game.c,1.5,1.6 check_http.c,1.39,1.40 check_mrtg.c,1.6,1.7 check_mrtgtraf.c,1.6,1.7 check_nagios.c,1.8,1.9 check_nt.c,1.12,1.13 check_nwstat.c,1.9,1.10 check_overcr.c,1.4,1.5 check_radius.c,1.6,1.7 check_real.c,1.7,1.8 check_snmp.c,1.30,1.31 check_swap.c,1.15,1.16 check_tcp.c,1.32,1.33 check_time.c,1.6,1.7 negate.c,1.10,1.11 netutils.c,1.11,1.12 popen.c,1.4,1.5 utils.c,1.26,1.27 utils.h,1.9,1.10
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commits
mailing list