diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-06-12 13:45:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-12 13:45:21 +0200 |
commit | 916d3a52a0f01f05bbf42008fa5dddcee6ad7522 (patch) | |
tree | e2b5a0c853b64074e8734dbe3b5de5b2c45fc8ed | |
parent | af88e3ced3c49169ed57fa4b4eaf6b4d8bb39ba7 (diff) | |
parent | a669b2531d3b01aeb5b3e39c28bf2e6816fb14af (diff) | |
download | monitoring-plugins-refs/heads/master.tar.gz |
Add fping 5.2 and 5.3 options to check_fping
-rw-r--r-- | configure.ac | 39 | ||||
-rw-r--r-- | plugins/check_fping.c | 85 | ||||
-rw-r--r-- | plugins/check_fping.d/config.h | 24 |
3 files changed, 136 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac index bd3de196..bec50cb4 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1519,15 +1519,48 @@ then | |||
1519 | fi | 1519 | fi |
1520 | 1520 | ||
1521 | AC_PATH_PROG(PATH_TO_FPING,fping) | 1521 | AC_PATH_PROG(PATH_TO_FPING,fping) |
1522 | AC_PATH_PROG(PATH_TO_FPING6,fping6) | ||
1523 | 1522 | ||
1524 | AC_ARG_WITH(fping_command, | 1523 | AC_ARG_WITH(fping_command, |
1525 | ACX_HELP_STRING([--with-fping-command=PATH], | 1524 | ACX_HELP_STRING([--with-fping-command=PATH], |
1526 | [Path to fping command]), PATH_TO_FPING=$withval) | 1525 | [Path to fping command]), PATH_TO_FPING=$withval) |
1527 | if test -n "$PATH_TO_FPING" | 1526 | if test -n "$PATH_TO_FPING"; then |
1528 | then | ||
1529 | AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping]) | 1527 | AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping]) |
1530 | EXTRAS="$EXTRAS check_fping\$(EXEEXT)" | 1528 | EXTRAS="$EXTRAS check_fping\$(EXEEXT)" |
1529 | |||
1530 | if test -z "$($PATH_TO_FPING --version)" ; then | ||
1531 | AC_MSG_NOTICE([failed to get version of fping]) | ||
1532 | else | ||
1533 | FPING_MAJOR_VERSION="$($PATH_TO_FPING --version | sed 's/.*fping: Version //' | sed 's/\..*//')" | ||
1534 | FPING_MINOR_VERSION="$($PATH_TO_FPING --version | sed 's/.*fping: Version //' | sed 's/.*\.//')" | ||
1535 | |||
1536 | if test $FPING_MAJOR_VERSION -eq 5 ; then | ||
1537 | if test $FPING_MINOR_VERSION -ge 3 ; then | ||
1538 | AC_DEFINE(FPING_VERSION_5_3_OR_HIGHER, "true", [fping is of version 5.3 or higher]) | ||
1539 | AC_MSG_NOTICE([fping is of version 5.3 or higher]) | ||
1540 | AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher]) | ||
1541 | AC_MSG_NOTICE([fping is of version 5.2 or higher]) | ||
1542 | elif test $FPING_MINOR_VERSION -ge 2 ; then | ||
1543 | AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher]) | ||
1544 | AC_MSG_NOTICE([fping is of version 5.2 or higher]) | ||
1545 | else | ||
1546 | AC_MSG_NOTICE([fping is of a version lower then 5.2]) | ||
1547 | fi | ||
1548 | |||
1549 | elif $FPING_MAJOR_VERSION > 5 ; then | ||
1550 | AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher]) | ||
1551 | AC_MSG_NOTICE([fping is of version 5.2 or higher]) | ||
1552 | AC_DEFINE(FPING_VERSION_5_3_OR_HIGHER, "true", [fping is of version 5.2 or higher]) | ||
1553 | AC_MSG_NOTICE([fping is of version 5.3 or higher]) | ||
1554 | fi | ||
1555 | |||
1556 | if test "`fping --version | sed 's/.*fping: Version //'`" = "5.2" ; then | ||
1557 | AC_DEFINE(FPING_VERSION, "5.2", [the version of fping available]) | ||
1558 | AC_MSG_NOTICE([fping version: 5.2]) | ||
1559 | elif test "`fping --version | sed 's/.*fping: Version //'`" = "5.3"; then | ||
1560 | AC_DEFINE(FPING_VERSION, "5.3", [the version of fping available]) | ||
1561 | AC_MSG_NOTICE([fping version: 5.3]) | ||
1562 | fi | ||
1563 | fi | ||
1531 | else | 1564 | else |
1532 | AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin]) | 1565 | AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin]) |
1533 | fi | 1566 | fi |
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index e05056b2..8018e06d 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 packet 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,38 @@ 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 */ |
277 | check_fping_config_wrapper process_arguments(int argc, char **argv) { | 295 | check_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 | #ifdef FPING_VERSION_5_2_OR_HIGHER | ||
319 | // only available with fping version >= 5.2 | ||
320 | {"fwmark", required_argument, NULL, FWMARK_OPT}, | ||
321 | # ifdef FPING_VERSION_5_3_OR_HIGHER | ||
322 | // only available with fping version >= 5.3 | ||
323 | {"icmp-timestamp", no_argument, NULL, ICMP_TIMESTAMP_OPT}, | ||
324 | {"check-source", no_argument, NULL, CHECK_SOURCE_OPT}, | ||
325 | # endif | ||
326 | #endif | ||
327 | {0, 0, 0, 0}}; | ||
285 | 328 | ||
286 | char *rv[2]; | 329 | char *rv[2]; |
287 | rv[PL] = NULL; | 330 | rv[PL] = NULL; |
@@ -306,7 +349,7 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { | |||
306 | argc--; | 349 | argc--; |
307 | } | 350 | } |
308 | 351 | ||
309 | while (1) { | 352 | while (true) { |
310 | int option_index = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); | 353 | int option_index = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); |
311 | 354 | ||
312 | if (option_index == -1 || option_index == EOF || option_index == 1) { | 355 | if (option_index == -1 || option_index == EOF || option_index == 1) { |
@@ -409,6 +452,20 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { | |||
409 | case 'M': | 452 | case 'M': |
410 | result.config.dontfrag = true; | 453 | result.config.dontfrag = true; |
411 | break; | 454 | break; |
455 | case FWMARK_OPT: | ||
456 | if (is_intpos(optarg)) { | ||
457 | result.config.fwmark = (unsigned int)atol(optarg); | ||
458 | result.config.fwmark_set = true; | ||
459 | } else { | ||
460 | usage(_("fwmark must be a positive integer")); | ||
461 | } | ||
462 | break; | ||
463 | case ICMP_TIMESTAMP_OPT: | ||
464 | result.config.icmp_timestamp = true; | ||
465 | break; | ||
466 | case CHECK_SOURCE_OPT: | ||
467 | result.config.check_source = true; | ||
468 | break; | ||
412 | } | 469 | } |
413 | } | 470 | } |
414 | 471 | ||
@@ -496,6 +553,16 @@ void print_help(void) { | |||
496 | printf(" %s\n", _("set the Don't Fragment flag")); | 553 | printf(" %s\n", _("set the Don't Fragment flag")); |
497 | printf(" %s\n", "-R, --random"); | 554 | printf(" %s\n", "-R, --random"); |
498 | printf(" %s\n", _("random packet data (to foil link data compression)")); | 555 | printf(" %s\n", _("random packet data (to foil link data compression)")); |
556 | #ifdef FPING_VERSION_5_2_OR_HIGHER | ||
557 | printf(" %s\n", "--fwmark=INTEGER"); | ||
558 | printf(" %s\n", _("set the routing mark to INTEGER (fping option)")); | ||
559 | # ifdef FPING_VERSION_5_3_OR_HIGHER | ||
560 | printf(" %s\n", "--icmp-timestamp"); | ||
561 | printf(" %s\n", _("use ICMP Timestamp instead of ICMP Echo (fping option)")); | ||
562 | printf(" %s\n", "--check-source"); | ||
563 | printf(" %s\n", _("discard replies not from target address (fping option)")); | ||
564 | # endif | ||
565 | #endif | ||
499 | printf(UT_VERBOSE); | 566 | printf(UT_VERBOSE); |
500 | printf("\n"); | 567 | printf("\n"); |
501 | printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); | 568 | printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); |
diff --git a/plugins/check_fping.d/config.h b/plugins/check_fping.d/config.h index a0697bf3..d95e9ded 100644 --- a/plugins/check_fping.d/config.h +++ b/plugins/check_fping.d/config.h | |||
@@ -29,6 +29,21 @@ typedef struct { | |||
29 | bool cpl_p; | 29 | bool cpl_p; |
30 | int wpl; | 30 | int wpl; |
31 | bool wpl_p; | 31 | bool wpl_p; |
32 | |||
33 | // only available with fping version >= 5.2 | ||
34 | // for a given uint _fwmark_ fping sets _fwmark_ as a firewall mark | ||
35 | // in the packets | ||
36 | unsigned int fwmark; | ||
37 | bool fwmark_set; | ||
38 | |||
39 | |||
40 | // only available with fping version >= 5.3 | ||
41 | // Setting icmp_timestamp tells fping to use ICMP Timestamp (ICMP type 13) instead | ||
42 | // of ICMP Echo | ||
43 | bool icmp_timestamp; | ||
44 | |||
45 | // Setting check_source lets fping discard replies which are not from the target address | ||
46 | bool check_source; | ||
32 | } check_fping_config; | 47 | } check_fping_config; |
33 | 48 | ||
34 | check_fping_config check_fping_config_init() { | 49 | check_fping_config check_fping_config_init() { |
@@ -53,6 +68,15 @@ check_fping_config check_fping_config_init() { | |||
53 | .cpl_p = false, | 68 | .cpl_p = false, |
54 | .wpl = 0, | 69 | .wpl = 0, |
55 | .wpl_p = false, | 70 | .wpl_p = false, |
71 | |||
72 | // only available with fping version >= 5.2 | ||
73 | .fwmark = 0, | ||
74 | .fwmark_set = false, // just to be deterministic | ||
75 | |||
76 | // only available with fping version >= 5.3 | ||
77 | .icmp_timestamp = false, | ||
78 | .check_source = false, | ||
79 | |||
56 | }; | 80 | }; |
57 | return tmp; | 81 | return tmp; |
58 | } | 82 | } |