From 71e0d5e0732225e95affbacd1a08f2a8513d2802 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 5 Nov 2025 12:19:20 +0100 Subject: check_ntp_time: add cli option for output format --- plugins/check_ntp_time.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'plugins/check_ntp_time.c') diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 7c3fc24d..602b6010 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c @@ -505,6 +505,11 @@ static offset_request_wrapper offset_request(const char *host, const char *port, } static check_ntp_time_config_wrapper process_arguments(int argc, char **argv) { + + enum { + output_format_index = CHAR_MAX + 1, + }; + static struct option longopts[] = {{"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, @@ -517,6 +522,7 @@ static check_ntp_time_config_wrapper process_arguments(int argc, char **argv) { {"timeout", required_argument, 0, 't'}, {"hostname", required_argument, 0, 'H'}, {"port", required_argument, 0, 'p'}, + {"output-format", required_argument, 0, output_format_index}, {0, 0, 0, 0}}; if (argc < 2) { @@ -536,6 +542,17 @@ static check_ntp_time_config_wrapper process_arguments(int argc, char **argv) { } switch (option_char) { + case output_format_index: { + parsed_output_format parser = mp_parse_output_format(optarg); + if (!parser.parsing_success) { + printf("Invalid output format: %s\n", optarg); + exit(STATE_UNKNOWN); + } + + result.config.output_format_is_set = true; + result.config.output_format = parser.output_format; + break; + } case 'h': print_help(); exit(STATE_UNKNOWN); @@ -623,6 +640,10 @@ int main(int argc, char *argv[]) { const check_ntp_time_config config = tmp_config.config; + if (config.output_format_is_set) { + mp_set_format(config.output_format); + } + /* initialize alarm signal handling */ signal(SIGALRM, socket_timeout_alarm_handler); @@ -687,6 +708,7 @@ void print_help(void) { printf(" %s\n", _("Expected offset of the ntp server relative to local server (seconds)")); printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); printf(UT_VERBOSE); + printf(UT_OUTPUT_FORMAT); printf("\n"); printf("%s\n", _("This plugin checks the clock offset between the local host and a")); -- cgit v1.2.3-74-g34f1