summaryrefslogtreecommitdiffstats
path: root/plugins/check_ntp_peer.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-11-05 12:04:30 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-11-05 12:04:30 +0100
commita9b63deedb1775271fa1335a5d3eb034d0628e91 (patch)
treee9ff510b5ec2f7af3b79f2d9bc12b5f23cb05289 /plugins/check_ntp_peer.c
parent99351f0560a5f457e499417366bdfdec0172a428 (diff)
downloadmonitoring-plugins-a9b63deedb1775271fa1335a5d3eb034d0628e91.tar.gz
check_ntp_peer: add cli param to set output format
Diffstat (limited to 'plugins/check_ntp_peer.c')
-rw-r--r--plugins/check_ntp_peer.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index 032f8ea4..f7cad630 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -478,16 +478,30 @@ ntp_request_result ntp_request(const check_ntp_peer_config config) {
478} 478}
479 479
480check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) { 480check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
481 static struct option longopts[] = { 481
482 {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, 482 enum {
483 {"verbose", no_argument, 0, 'v'}, {"use-ipv4", no_argument, 0, '4'}, 483 output_format_index = CHAR_MAX + 1,
484 {"use-ipv6", no_argument, 0, '6'}, {"quiet", no_argument, 0, 'q'}, 484 };
485 {"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, 485
486 {"swarn", required_argument, 0, 'W'}, {"scrit", required_argument, 0, 'C'}, 486 static struct option longopts[] = {{"version", no_argument, 0, 'V'},
487 {"jwarn", required_argument, 0, 'j'}, {"jcrit", required_argument, 0, 'k'}, 487 {"help", no_argument, 0, 'h'},
488 {"twarn", required_argument, 0, 'm'}, {"tcrit", required_argument, 0, 'n'}, 488 {"verbose", no_argument, 0, 'v'},
489 {"timeout", required_argument, 0, 't'}, {"hostname", required_argument, 0, 'H'}, 489 {"use-ipv4", no_argument, 0, '4'},
490 {"port", required_argument, 0, 'p'}, {0, 0, 0, 0}}; 490 {"use-ipv6", no_argument, 0, '6'},
491 {"quiet", no_argument, 0, 'q'},
492 {"warning", required_argument, 0, 'w'},
493 {"critical", required_argument, 0, 'c'},
494 {"swarn", required_argument, 0, 'W'},
495 {"scrit", required_argument, 0, 'C'},
496 {"jwarn", required_argument, 0, 'j'},
497 {"jcrit", required_argument, 0, 'k'},
498 {"twarn", required_argument, 0, 'm'},
499 {"tcrit", required_argument, 0, 'n'},
500 {"timeout", required_argument, 0, 't'},
501 {"hostname", required_argument, 0, 'H'},
502 {"port", required_argument, 0, 'p'},
503 {"output-format", required_argument, 0, output_format_index},
504 {0, 0, 0, 0}};
491 505
492 if (argc < 2) { 506 if (argc < 2) {
493 usage("\n"); 507 usage("\n");
@@ -507,6 +521,17 @@ check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
507 } 521 }
508 522
509 switch (option_char) { 523 switch (option_char) {
524 case output_format_index: {
525 parsed_output_format parser = mp_parse_output_format(optarg);
526 if (!parser.parsing_success) {
527 printf("Invalid output format: %s\n", optarg);
528 exit(STATE_UNKNOWN);
529 }
530
531 result.config.output_format_is_set = true;
532 result.config.output_format = parser.output_format;
533 break;
534 }
510 case 'h': 535 case 'h':
511 print_help(); 536 print_help();
512 exit(STATE_UNKNOWN); 537 exit(STATE_UNKNOWN);
@@ -673,6 +698,10 @@ int main(int argc, char *argv[]) {
673 698
674 const check_ntp_peer_config config = tmp_config.config; 699 const check_ntp_peer_config config = tmp_config.config;
675 700
701 if (config.output_format_is_set) {
702 mp_set_format(config.output_format);
703 }
704
676 /* initialize alarm signal handling */ 705 /* initialize alarm signal handling */
677 signal(SIGALRM, socket_timeout_alarm_handler); 706 signal(SIGALRM, socket_timeout_alarm_handler);
678 707
@@ -825,6 +854,7 @@ void print_help(void) {
825 printf(" %s\n", _("Critical threshold for number of usable time sources (\"truechimers\")")); 854 printf(" %s\n", _("Critical threshold for number of usable time sources (\"truechimers\")"));
826 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 855 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
827 printf(UT_VERBOSE); 856 printf(UT_VERBOSE);
857 printf(UT_OUTPUT_FORMAT);
828 858
829 printf("\n"); 859 printf("\n");
830 printf("%s\n", _("This plugin checks an NTP server independent of any commandline")); 860 printf("%s\n", _("This plugin checks an NTP server independent of any commandline"));