From c57381d789fb246602966fccfcb80131a7fb0461 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 6 Apr 2026 11:55:27 +0200 Subject: Revert check_disk performance data back to used space (#2243) * Implement simple output shortcut for ranges If ranges start with zero (e.g. 0:10), the zero and the colon can be left out. This patch implements this by default, since some systems (icinga2) do not fully implement the whole range format and this reduces errors in the common case of just an upper border. * switch check_disk perfdata back to used space --- lib/perfdata.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/perfdata.c b/lib/perfdata.c index f4eaf843..e3710ec7 100644 --- a/lib/perfdata.c +++ b/lib/perfdata.c @@ -251,7 +251,16 @@ char *mp_range_to_string(const mp_range input) { if (input.start_infinity) { asprintf(&result, "%s~:", result); } else { - asprintf(&result, "%s%s:", result, pd_value_to_string(input.start)); + // check for zeroes, so we can use the short form + if ((input.start.type == PD_TYPE_NONE) || + ((input.start.type == PD_TYPE_INT) && (input.start.pd_int == 0)) || + ((input.start.type == PD_TYPE_UINT) && (input.start.pd_uint == 0)) || + ((input.start.type == PD_TYPE_DOUBLE) && (input.start.pd_double == 0))){ + // nothing to do here + } else { + // Start value is an actual value + asprintf(&result, "%s%s:", result, pd_value_to_string(input.start)); + } } if (!input.end_infinity) { -- cgit v1.2.3-74-g34f1 From 9980e788509af3203725cdcd15f517ad1ed503fb Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 6 Apr 2026 12:17:43 +0200 Subject: Add option to override output for check in lib for check_by_ssh (#2230) The new output functionality was discussed in the context of check_by_ssh, where it mostly adds more stuff which was seen as not inherently usefull as a succesful check_by_ssh check might as well be transparent. --- lib/output.c | 7 +++++++ lib/output.h | 4 ++++ plugins/check_by_ssh.c | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/output.c b/lib/output.c index bfd43195..54d505d9 100644 --- a/lib/output.c +++ b/lib/output.c @@ -61,6 +61,8 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) { mp_check mp_check_init(void) { mp_check check = { .evaluation_function = &mp_eval_check_default, + .default_output_override = NULL, + .default_output_override_content = NULL, }; return check; } @@ -283,6 +285,11 @@ char *mp_fmt_output(mp_check check) { switch (output_format) { case MP_FORMAT_MULTI_LINE: { + if (check.default_output_override != NULL) { + result = check.default_output_override(check.default_output_override_content); + break; + } + if (check.summary == NULL) { check.summary = get_subcheck_summary(check); } diff --git a/lib/output.h b/lib/output.h index c63c8e3f..f5011268 100644 --- a/lib/output.h +++ b/lib/output.h @@ -70,6 +70,10 @@ struct mp_check { // the evaluation_functions computes the state of check mp_state_enum (*evaluation_function)(mp_check); + + // override for the default output format + char *(*default_output_override)(void *); + void *default_output_override_content; }; mp_check mp_check_init(void); diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 7ffa0ded..4d0c8e7d 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -41,6 +41,8 @@ const char *email = "devel@monitoring-plugins.org"; # define NP_MAXARGS 1024 #endif +char *check_by_ssh_output_override(void *remote_output) { return ((char *)remote_output); } + typedef struct { int errorcode; check_by_ssh_config config; @@ -155,10 +157,21 @@ int main(int argc, char **argv) { xasprintf(&sc_active_check.output, "command stdout:"); if (child_result.out.lines > skip_stdout) { + + char *remote_command_output = NULL; for (size_t i = skip_stdout; i < child_result.out.lines; i++) { - xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output, - child_result.out.line[i]); + if (i == skip_stdout) { + // first iteration + xasprintf(&remote_command_output, "%s", child_result.out.line[i]); + } else { + xasprintf(&remote_command_output, "%s\n%s", remote_command_output, + child_result.out.line[i]); + } } + + sc_active_check.output = remote_command_output; + overall.default_output_override_content = remote_command_output; + overall.default_output_override = check_by_ssh_output_override; } else { xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", config.remotecmd, child_result.cmd_error_code); -- cgit v1.2.3-74-g34f1