diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index f6531a5416e31aee0c9d923863c4646566fee3a6..ac203f523d3a646cd8e2dd11f54f098857cd0426 100644 (file)
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
#include "popen.h"
#include "utils.h"
-#define PROGNAME "check_fping"
+const char *progname = "check_fping";
#define PACKET_COUNT 1
#define PACKET_SIZE 56
#define UNKNOWN_PACKET_LOSS 200 /* 200% */
server = strscpy (server, server_name);
/* compose the command */
- command_line = ssprintf
- (command_line, "%s -b %d -c %d %s",
- PATH_TO_FPING, packet_size, packet_count, server);
+ asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
+ packet_size, packet_count, server);
if (verbose)
printf ("%s\n", command_line);
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
if (verbose)
printf ("%s", input_buffer);
- status = max (status, textscan (input_buffer));
+ status = max_state (status, textscan (input_buffer));
}
/* If we get anything on STDERR, at least set warning */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
- status = max (status, STATE_WARNING);
+ status = max_state (status, STATE_WARNING);
if (verbose)
printf ("%s", input_buffer);
- status = max (status, textscan (input_buffer));
+ status = max_state (status, textscan (input_buffer));
}
(void) fclose (child_stderr);
/* close the pipe */
if (spclose (child_process))
- status = max (status, STATE_WARNING);
+ /* need to use max_state not max */
+ status = max_state (status, STATE_WARNING);
printf ("FPING %s - %s\n", state_text (status), server_name);
terminate (status, "FPING %s - %s (loss=%f%%, rta=%f ms)\n",
state_text (status), server_name, loss, rta);
+ }
+ else if(strstr (buf, "xmt/rcv/%loss") ) {
+ /* no min/max/avg if host was unreachable in fping v2.2.b1 */
+ losstr = strstr (buf, "=");
+ losstr = 1 + strstr (losstr, "/");
+ losstr = 1 + strstr (losstr, "/");
+ loss = strtod (losstr, NULL);
+ if (loss == 100)
+ status = STATE_CRITICAL;
+ else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl)
+ status = STATE_CRITICAL;
+ else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl)
+ status = STATE_WARNING;
+ else
+ status = STATE_OK;
+
+ terminate (status, "FPING %s - %s (loss=%f%% )\n",
+ state_text (status), server_name, loss );
+
}
else {
- status = max (status, STATE_WARNING);
+ status = max_state (status, STATE_WARNING);
}
return status;
int c;
char *rv[2];
-#ifdef HAVE_GETOPT_H
int option_index = 0;
static struct option long_options[] = {
{"hostname", required_argument, 0, 'H'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
-#endif
rv[PL] = NULL;
rv[RTA] = NULL;
}
while (1) {
-#ifdef HAVE_GETOPT_H
- c =
- getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index);
-#else
- c = getopt (argc, argv, "+hVvH:c:w:b:n:");
-#endif
+ c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index);
if (c == -1 || c == EOF || c == 1)
break;
switch (c) {
case '?': /* print short usage statement if args not parsable */
- printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
+ printf ("%s: Unknown argument: %s\n\n", progname, optarg);
print_usage ();
exit (STATE_UNKNOWN);
case 'h': /* help */
print_help ();
exit (STATE_OK);
case 'V': /* version */
- print_revision (my_basename (argv[0]), "$Revision$");
+ print_revision (progname, "$Revision$");
exit (STATE_OK);
case 'v': /* verbose mode */
verbose = TRUE;
arg1[strcspn (arg1, ",:")] = 0;
if (strstr (arg1, "%") && strstr (arg2, "%"))
terminate (STATE_UNKNOWN,
- "%s: Only one threshold may be packet loss (%s)\n", PROGNAME,
+ "%s: Only one threshold may be packet loss (%s)\n", progname,
arg);
if (!strstr (arg1, "%") && !strstr (arg2, "%"))
terminate (STATE_UNKNOWN,
"%s: Only one threshold must be packet loss (%s)\n",
- PROGNAME, arg);
+ progname, arg);
}
if (arg2 && strstr (arg2, "%")) {
void
print_usage (void)
{
- printf ("Usage: %s <host_address>\n", PROGNAME);
+ printf ("Usage: %s <host_address>\n", progname);
}
print_help (void)
{
- print_revision (PROGNAME, "$Revision$");
+ print_revision (progname, "$Revision$");
printf
("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n"