Browse Source

Added -S und -I parameter to match fping -S and -I parameters.

-S allows to specify the source ip for ICMP pakets
-I allows to specify a interface to bind to
Steve Weinreich 13 years ago
parent
commit
c9169d1256
1 changed files with 22 additions and 1 deletions
  1. 22 1
      plugins/check_fping.c

+ 22 - 1
plugins/check_fping.c

@@ -52,6 +52,8 @@ void print_help (void);
 void print_usage (void);
 void print_usage (void);
 
 
 char *server_name = NULL;
 char *server_name = NULL;
+char *sourceip = NULL;
+char *sourceif = NULL;
 int packet_size = PACKET_SIZE;
 int packet_size = PACKET_SIZE;
 int packet_count = PACKET_COUNT;
 int packet_count = PACKET_COUNT;
 int target_timeout = 0;
 int target_timeout = 0;
@@ -95,6 +97,10 @@ main (int argc, char **argv)
     xasprintf(&option_string, "%s-t %d ", option_string, target_timeout);
     xasprintf(&option_string, "%s-t %d ", option_string, target_timeout);
   if (packet_interval)
   if (packet_interval)
     xasprintf(&option_string, "%s-p %d ", option_string, packet_interval);
     xasprintf(&option_string, "%s-p %d ", option_string, packet_interval);
+  if (sourceip)
+    xasprintf(&option_string, "%s-S %s ", option_string, sourceip);
+  if (sourceif)
+    xasprintf(&option_string, "%s-I %s ", option_string, sourceif);
 
 
   xasprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING,
   xasprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING,
             option_string, packet_size, packet_count, server);
             option_string, packet_size, packet_count, server);
@@ -232,6 +238,8 @@ process_arguments (int argc, char **argv)
   int option = 0;
   int option = 0;
   static struct option longopts[] = {
   static struct option longopts[] = {
     {"hostname", required_argument, 0, 'H'},
     {"hostname", required_argument, 0, 'H'},
+    {"sourceip", required_argument, 0, 'S'},
+    {"sourceif", required_argument, 0, 'I'},
     {"critical", required_argument, 0, 'c'},
     {"critical", required_argument, 0, 'c'},
     {"warning", required_argument, 0, 'w'},
     {"warning", required_argument, 0, 'w'},
     {"bytes", required_argument, 0, 'b'},
     {"bytes", required_argument, 0, 'b'},
@@ -258,7 +266,7 @@ process_arguments (int argc, char **argv)
   }
   }
 
 
   while (1) {
   while (1) {
-    c = getopt_long (argc, argv, "+hVvH:c:w:b:n:T:i:", longopts, &option);
+    c = getopt_long (argc, argv, "+hVvH:S:c:w:b:n:T:i:I:", longopts, &option);
 
 
     if (c == -1 || c == EOF || c == 1)
     if (c == -1 || c == EOF || c == 1)
       break;
       break;
@@ -281,6 +289,15 @@ process_arguments (int argc, char **argv)
       }
       }
       server_name = strscpy (server_name, optarg);
       server_name = strscpy (server_name, optarg);
       break;
       break;
+    case 'S':                 /* sourceip */
+      if (is_host (optarg) == FALSE) {
+        usage2 (_("Invalid hostname/address"), optarg);
+      }
+      sourceip = strscpy (sourceip, optarg);
+      break;
+    case 'I':                 /* sourceip */
+      sourceif = strscpy (sourceif, optarg);
+      break;
     case 'c':
     case 'c':
       get_threshold (optarg, rv);
       get_threshold (optarg, rv);
       if (rv[RTA]) {
       if (rv[RTA]) {
@@ -416,6 +433,10 @@ print_help (void)
   printf ("    %s (default: fping's default for -t)\n", _("Target timeout (ms)"),PACKET_COUNT);
   printf ("    %s (default: fping's default for -t)\n", _("Target timeout (ms)"),PACKET_COUNT);
   printf (" %s\n", "-i, --interval=INTEGER");
   printf (" %s\n", "-i, --interval=INTEGER");
   printf ("    %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets"),PACKET_COUNT);
   printf ("    %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets"),PACKET_COUNT);
+  printf (" %s\n", "-S, --sourceip=HOST");
+  printf ("    %s\n", _("name or IP Address of sourceip"));
+  printf (" %s\n", "-I, --sourceif=IF");
+  printf ("    %s\n", _("source interface name"));
   printf (UT_VERBOSE);
   printf (UT_VERBOSE);
   printf ("\n");
   printf ("\n");
   printf (" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));
   printf (" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));