summaryrefslogtreecommitdiffstats
path: root/plugins/check_fping.c
diff options
context:
space:
mode:
authorLorenz Kästle <lorenz.kaestle@netways.de>2025-06-12 11:13:59 +0200
committerLorenz Kästle <lorenz.kaestle@netways.de>2025-06-12 11:13:59 +0200
commit7247fc656a1f475159b7879cc3c3b798e03c1a33 (patch)
tree0dbcc41f97111b9713b8478409e8dc9dec7a0f37 /plugins/check_fping.c
parent88683af1da8baae6b252795ab5d85a48e9cd3e63 (diff)
downloadmonitoring-plugins-7247fc656a1f475159b7879cc3c3b798e03c1a33.tar.gz
Implement new fping options for fping 5.2 and 5.3
fping 5.2 and 5.3 add some new useful command line options which this commit add to check_fping. These are: * --fwmark - sets a firewall mark in the packages to make them identifiable (fping 5.2) * --icmp-timestamp - fping uses ICMP timestamp instead of ICMP Echo (fping 5.2) * --check-source - fping discards replies which originate not from the target address (fping 5.2) The fping release notes describe theses options ( https://github.com/schweikert/fping/releases ) in a little bit more detail. Currently the help display for those options is only shown when fping was available in the appropriate version during compilation.
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r--plugins/check_fping.c80
1 files changed, 72 insertions, 8 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index e05056b2..4d328a01 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -117,8 +117,26 @@ int main(int argc, char **argv) {
117 xasprintf(&option_string, "%s-R ", option_string); 117 xasprintf(&option_string, "%s-R ", option_string);
118 } 118 }
119 119
120 if (config.fwmark_set) {
121 xasprintf(&option_string, "%s--fwmark %u ", option_string, config.fwmark);
122 }
123
124 if (config.icmp_timestamp) {
125 xasprintf(&option_string, "%s--icmp-timestamp ", option_string);
126 }
127
128 if (config.check_source) {
129 xasprintf(&option_string, "%s--check-source ", option_string);
130 }
131
120 char *command_line = NULL; 132 char *command_line = NULL;
121 xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); 133
134 if (config.icmp_timestamp) {
135 // no paket size settable for ICMP timestamp
136 xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, server);
137 } else {
138 xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server);
139 }
122 140
123 if (verbose) { 141 if (verbose) {
124 printf("%s\n", command_line); 142 printf("%s\n", command_line);
@@ -275,13 +293,35 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c
275 293
276/* process command-line arguments */ 294/* process command-line arguments */
277check_fping_config_wrapper process_arguments(int argc, char **argv) { 295check_fping_config_wrapper process_arguments(int argc, char **argv) {
278 static struct option longopts[] = { 296 enum {
279 {"hostname", required_argument, 0, 'H'}, {"sourceip", required_argument, 0, 'S'}, {"sourceif", required_argument, 0, 'I'}, 297 FWMARK_OPT = CHAR_MAX + 1,
280 {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, {"alive", no_argument, 0, 'a'}, 298 ICMP_TIMESTAMP_OPT,
281 {"bytes", required_argument, 0, 'b'}, {"number", required_argument, 0, 'n'}, {"target-timeout", required_argument, 0, 'T'}, 299 CHECK_SOURCE_OPT,
282 {"interval", required_argument, 0, 'i'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, 300 };
283 {"help", no_argument, 0, 'h'}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, 301 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
284 {"dontfrag", no_argument, 0, 'M'}, {"random", no_argument, 0, 'R'}, {0, 0, 0, 0}}; 302 {"sourceip", required_argument, 0, 'S'},
303 {"sourceif", required_argument, 0, 'I'},
304 {"critical", required_argument, 0, 'c'},
305 {"warning", required_argument, 0, 'w'},
306 {"alive", no_argument, 0, 'a'},
307 {"bytes", required_argument, 0, 'b'},
308 {"number", required_argument, 0, 'n'},
309 {"target-timeout", required_argument, 0, 'T'},
310 {"interval", required_argument, 0, 'i'},
311 {"verbose", no_argument, 0, 'v'},
312 {"version", no_argument, 0, 'V'},
313 {"help", no_argument, 0, 'h'},
314 {"use-ipv4", no_argument, 0, '4'},
315 {"use-ipv6", no_argument, 0, '6'},
316 {"dontfrag", no_argument, 0, 'M'},
317 {"random", no_argument, 0, 'R'},
318 // only available with fping version >= 5.3
319 {"fwmark", required_argument, NULL, FWMARK_OPT},
320 // only available with fping version >= 5.3
321 {"icmp-timestamp", no_argument, NULL, ICMP_TIMESTAMP_OPT},
322 {"check-source", no_argument, NULL, CHECK_SOURCE_OPT},
323
324 {0, 0, 0, 0}};
285 325
286 char *rv[2]; 326 char *rv[2];
287 rv[PL] = NULL; 327 rv[PL] = NULL;
@@ -409,6 +449,20 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) {
409 case 'M': 449 case 'M':
410 result.config.dontfrag = true; 450 result.config.dontfrag = true;
411 break; 451 break;
452 case FWMARK_OPT:
453 if (is_intpos(optarg)) {
454 result.config.fwmark = (unsigned int)atol(optarg);
455 result.config.fwmark_set = true;
456 } else {
457 usage(_("fwmark must be a positive integer"));
458 }
459 break;
460 case ICMP_TIMESTAMP_OPT:
461 result.config.icmp_timestamp = true;
462 break;
463 case CHECK_SOURCE_OPT:
464 result.config.check_source = true;
465 break;
412 } 466 }
413 } 467 }
414 468
@@ -496,6 +550,16 @@ void print_help(void) {
496 printf(" %s\n", _("set the Don't Fragment flag")); 550 printf(" %s\n", _("set the Don't Fragment flag"));
497 printf(" %s\n", "-R, --random"); 551 printf(" %s\n", "-R, --random");
498 printf(" %s\n", _("random packet data (to foil link data compression)")); 552 printf(" %s\n", _("random packet data (to foil link data compression)"));
553#ifdef FPING_VERSION_5_2_OR_HIGHER
554 printf(" %s\n", "--fwmark=INTEGER");
555 printf(" %s\n", _("set the routing mark to INTEGER (fping option)"));
556# ifdef FPING_VERSION_5_3_OR_HIGHER
557 printf(" %s\n", "--icmp-timestamp");
558 printf(" %s\n", _("use ICMP Timestamp instead of ICMP Echo (fping option)"));
559 printf(" %s\n", "--check-source");
560 printf(" %s\n", _("discard replies not from target address (fping option)"));
561# endif
562#endif
499 printf(UT_VERBOSE); 563 printf(UT_VERBOSE);
500 printf("\n"); 564 printf("\n");
501 printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); 565 printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));