diff options
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_icmp.c | 52 | ||||
-rw-r--r-- | plugins-root/check_icmp.d/check_icmp_helpers.c | 2 | ||||
-rw-r--r-- | plugins-root/check_icmp.d/config.h | 6 |
3 files changed, 57 insertions, 3 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 0c69d31c..bad73cc4 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -319,12 +319,41 @@ check_icmp_config_wrapper process_arguments(int argc, char **argv) { | |||
319 | 319 | ||
320 | sa_family_t enforced_ai_family = AF_UNSPEC; | 320 | sa_family_t enforced_ai_family = AF_UNSPEC; |
321 | 321 | ||
322 | enum { | ||
323 | output_format_index = CHAR_MAX + 1, | ||
324 | }; | ||
325 | |||
326 | struct option longopts[] = { | ||
327 | {"version", no_argument, 0, 'V'}, | ||
328 | {"help", no_argument, 0, 'h'}, | ||
329 | {"verbose", no_argument, 0, 'v'}, | ||
330 | {"Host", required_argument, 0, 'H'}, | ||
331 | {"ipv4-only", no_argument, 0, '4'}, | ||
332 | {"ipv6-only", no_argument, 0, '6'}, | ||
333 | {"warning", required_argument, 0, 'w'}, | ||
334 | {"critical", required_argument, 0, 'c'}, | ||
335 | {"rta-mode-thresholds", required_argument, 0, 'R'}, | ||
336 | {"packet-loss-mode-thresholds", required_argument, 0, 'P'}, | ||
337 | {"jitter-mode-thresholds", required_argument, 0, 'J'}, | ||
338 | {"mos-mode-thresholds", required_argument, 0, 'M'}, | ||
339 | {"score-mode-thresholds", required_argument, 0, 'S'}, | ||
340 | {"out-of-order-packets", no_argument, 0, 'O'}, | ||
341 | {"number-of-packets", required_argument, 0, 'n'}, | ||
342 | {"number-of-packets", required_argument, 0, 'p'}, | ||
343 | {"packet-interval", required_argument, 0, 'i'}, | ||
344 | {"target-interval", required_argument, 0, 'I'}, | ||
345 | {"outgoing-ttl", required_argument, 0, 'l'}, | ||
346 | {"packet_payload_size", required_argument, 0, 'b'}, | ||
347 | {"output-format", required_argument, 0, output_format_index}, | ||
348 | {}, | ||
349 | }; | ||
350 | |||
322 | // Parse protocol arguments first | 351 | // Parse protocol arguments first |
323 | // and count hosts here | 352 | // and count hosts here |
324 | char *opts_str = "vhVw:c:n:p:t:H:s:i:b:I:l:m:P:R:J:S:M:O64"; | 353 | char *opts_str = "vhVw:c:n:p:t:H:s:i:b:I:l:m:P:R:J:S:M:O64"; |
325 | for (int i = 1; i < argc; i++) { | 354 | for (int i = 1; i < argc; i++) { |
326 | long int arg; | 355 | long int arg; |
327 | while ((arg = getopt(argc, argv, opts_str)) != EOF) { | 356 | while ((arg = getopt_long(argc, argv, opts_str, longopts, NULL)) != EOF) { |
328 | switch (arg) { | 357 | switch (arg) { |
329 | case '4': | 358 | case '4': |
330 | if (enforced_ai_family != AF_UNSPEC) { | 359 | if (enforced_ai_family != AF_UNSPEC) { |
@@ -374,7 +403,7 @@ check_icmp_config_wrapper process_arguments(int argc, char **argv) { | |||
374 | /* parse the arguments */ | 403 | /* parse the arguments */ |
375 | for (int i = 1; i < argc; i++) { | 404 | for (int i = 1; i < argc; i++) { |
376 | long int arg; | 405 | long int arg; |
377 | while ((arg = getopt(argc, argv, opts_str)) != EOF) { | 406 | while ((arg = getopt_long(argc, argv, opts_str, longopts, NULL)) != EOF) { |
378 | switch (arg) { | 407 | switch (arg) { |
379 | case 'b': { | 408 | case 'b': { |
380 | long size = strtol(optarg, NULL, 0); | 409 | long size = strtol(optarg, NULL, 0); |
@@ -536,6 +565,18 @@ check_icmp_config_wrapper process_arguments(int argc, char **argv) { | |||
536 | case 'O': /* out of order mode */ | 565 | case 'O': /* out of order mode */ |
537 | result.config.modes.order_mode = true; | 566 | result.config.modes.order_mode = true; |
538 | break; | 567 | break; |
568 | case output_format_index: { | ||
569 | parsed_output_format parser = mp_parse_output_format(optarg); | ||
570 | if (!parser.parsing_success) { | ||
571 | // TODO List all available formats here, maybe add anothoer usage function | ||
572 | printf("Invalid output format: %s\n", optarg); | ||
573 | exit(STATE_UNKNOWN); | ||
574 | } | ||
575 | |||
576 | result.config.output_format_is_set = true; | ||
577 | result.config.output_format = parser.output_format; | ||
578 | break; | ||
579 | } | ||
539 | } | 580 | } |
540 | } | 581 | } |
541 | } | 582 | } |
@@ -803,6 +844,10 @@ int main(int argc, char **argv) { | |||
803 | 844 | ||
804 | const check_icmp_config config = tmp_config.config; | 845 | const check_icmp_config config = tmp_config.config; |
805 | 846 | ||
847 | if (config.output_format_is_set) { | ||
848 | mp_set_format(config.output_format); | ||
849 | } | ||
850 | |||
806 | // int icmp_proto = IPPROTO_ICMP; | 851 | // int icmp_proto = IPPROTO_ICMP; |
807 | // add_target might change address_family | 852 | // add_target might change address_family |
808 | // switch (address_family) { | 853 | // switch (address_family) { |
@@ -2104,6 +2149,9 @@ void print_help(void) { | |||
2104 | DEFAULT_PING_DATA_SIZE, ICMP_MINLEN); | 2149 | DEFAULT_PING_DATA_SIZE, ICMP_MINLEN); |
2105 | printf(" %s\n", "-v"); | 2150 | printf(" %s\n", "-v"); |
2106 | printf(" %s\n", _("Verbosity, can be given multiple times (for debugging)")); | 2151 | printf(" %s\n", _("Verbosity, can be given multiple times (for debugging)")); |
2152 | |||
2153 | printf(UT_OUTPUT_FORMAT); | ||
2154 | |||
2107 | printf("\n"); | 2155 | printf("\n"); |
2108 | printf("%s\n", _("Notes:")); | 2156 | printf("%s\n", _("Notes:")); |
2109 | printf(" %s\n", _("If none of R,P,J,M,S or O is specified, default behavior is -R -P")); | 2157 | printf(" %s\n", _("If none of R,P,J,M,S or O is specified, default behavior is -R -P")); |
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.c b/plugins-root/check_icmp.d/check_icmp_helpers.c index ec786305..9acc96fd 100644 --- a/plugins-root/check_icmp.d/check_icmp_helpers.c +++ b/plugins-root/check_icmp.d/check_icmp_helpers.c | |||
@@ -52,6 +52,8 @@ check_icmp_config check_icmp_config_init() { | |||
52 | 52 | ||
53 | .number_of_hosts = 0, | 53 | .number_of_hosts = 0, |
54 | .hosts = NULL, | 54 | .hosts = NULL, |
55 | |||
56 | .output_format_is_set = false, | ||
55 | }; | 57 | }; |
56 | return tmp; | 58 | return tmp; |
57 | } | 59 | } |
diff --git a/plugins-root/check_icmp.d/config.h b/plugins-root/check_icmp.d/config.h index fc9dd5a6..8092e343 100644 --- a/plugins-root/check_icmp.d/config.h +++ b/plugins-root/check_icmp.d/config.h | |||
@@ -12,11 +12,12 @@ | |||
12 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
13 | #include <stdint.h> | 13 | #include <stdint.h> |
14 | #include "./check_icmp_helpers.h" | 14 | #include "./check_icmp_helpers.h" |
15 | #include "output.h" | ||
15 | 16 | ||
16 | /* threshold structure. all values are maximum allowed, exclusive */ | 17 | /* threshold structure. all values are maximum allowed, exclusive */ |
17 | typedef struct { | 18 | typedef struct { |
18 | unsigned char pl; /* max allowed packet loss in percent */ | 19 | unsigned char pl; /* max allowed packet loss in percent */ |
19 | time_t rta; /* roundtrip time average, microseconds */ | 20 | time_t rta; /* roundtrip time average, microseconds */ |
20 | double jitter; /* jitter time average, microseconds */ | 21 | double jitter; /* jitter time average, microseconds */ |
21 | double mos; /* MOS */ | 22 | double mos; /* MOS */ |
22 | double score; /* Score */ | 23 | double score; /* Score */ |
@@ -77,6 +78,9 @@ typedef struct { | |||
77 | 78 | ||
78 | unsigned short number_of_hosts; | 79 | unsigned short number_of_hosts; |
79 | check_icmp_target_container *hosts; | 80 | check_icmp_target_container *hosts; |
81 | |||
82 | mp_output_format output_format; | ||
83 | bool output_format_is_set; | ||
80 | } check_icmp_config; | 84 | } check_icmp_config; |
81 | 85 | ||
82 | check_icmp_config check_icmp_config_init(); | 86 | check_icmp_config check_icmp_config_init(); |