Module: monitoring-plugins
    Branch: master
    Commit: 9980e788509af3203725cdcd15f517ad1ed503fb
    Author: Lorenz Kästle <[email protected]>
 Committer: GitHub <[email protected]>
      Date: Mon Apr  6 12:17:43 2026 +0200
       URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=9980e788

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(-)

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 = "[email protected]";
 #      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);

Reply via email to