diff options
| -rw-r--r-- | lib/output.c | 7 | ||||
| -rw-r--r-- | lib/output.h | 4 | ||||
| -rw-r--r-- | 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) { | |||
| 61 | mp_check mp_check_init(void) { | 61 | mp_check mp_check_init(void) { |
| 62 | mp_check check = { | 62 | mp_check check = { |
| 63 | .evaluation_function = &mp_eval_check_default, | 63 | .evaluation_function = &mp_eval_check_default, |
| 64 | .default_output_override = NULL, | ||
| 65 | .default_output_override_content = NULL, | ||
| 64 | }; | 66 | }; |
| 65 | return check; | 67 | return check; |
| 66 | } | 68 | } |
| @@ -283,6 +285,11 @@ char *mp_fmt_output(mp_check check) { | |||
| 283 | 285 | ||
| 284 | switch (output_format) { | 286 | switch (output_format) { |
| 285 | case MP_FORMAT_MULTI_LINE: { | 287 | case MP_FORMAT_MULTI_LINE: { |
| 288 | if (check.default_output_override != NULL) { | ||
| 289 | result = check.default_output_override(check.default_output_override_content); | ||
| 290 | break; | ||
| 291 | } | ||
| 292 | |||
| 286 | if (check.summary == NULL) { | 293 | if (check.summary == NULL) { |
| 287 | check.summary = get_subcheck_summary(check); | 294 | check.summary = get_subcheck_summary(check); |
| 288 | } | 295 | } |
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 { | |||
| 70 | 70 | ||
| 71 | // the evaluation_functions computes the state of check | 71 | // the evaluation_functions computes the state of check |
| 72 | mp_state_enum (*evaluation_function)(mp_check); | 72 | mp_state_enum (*evaluation_function)(mp_check); |
| 73 | |||
| 74 | // override for the default output format | ||
| 75 | char *(*default_output_override)(void *); | ||
| 76 | void *default_output_override_content; | ||
| 73 | }; | 77 | }; |
| 74 | 78 | ||
| 75 | mp_check mp_check_init(void); | 79 | 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"; | |||
| 41 | # define NP_MAXARGS 1024 | 41 | # define NP_MAXARGS 1024 |
| 42 | #endif | 42 | #endif |
| 43 | 43 | ||
| 44 | char *check_by_ssh_output_override(void *remote_output) { return ((char *)remote_output); } | ||
| 45 | |||
| 44 | typedef struct { | 46 | typedef struct { |
| 45 | int errorcode; | 47 | int errorcode; |
| 46 | check_by_ssh_config config; | 48 | check_by_ssh_config config; |
| @@ -155,10 +157,21 @@ int main(int argc, char **argv) { | |||
| 155 | xasprintf(&sc_active_check.output, "command stdout:"); | 157 | xasprintf(&sc_active_check.output, "command stdout:"); |
| 156 | 158 | ||
| 157 | if (child_result.out.lines > skip_stdout) { | 159 | if (child_result.out.lines > skip_stdout) { |
| 160 | |||
| 161 | char *remote_command_output = NULL; | ||
| 158 | for (size_t i = skip_stdout; i < child_result.out.lines; i++) { | 162 | for (size_t i = skip_stdout; i < child_result.out.lines; i++) { |
| 159 | xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output, | 163 | if (i == skip_stdout) { |
| 160 | child_result.out.line[i]); | 164 | // first iteration |
| 165 | xasprintf(&remote_command_output, "%s", child_result.out.line[i]); | ||
| 166 | } else { | ||
| 167 | xasprintf(&remote_command_output, "%s\n%s", remote_command_output, | ||
| 168 | child_result.out.line[i]); | ||
| 169 | } | ||
| 161 | } | 170 | } |
| 171 | |||
| 172 | sc_active_check.output = remote_command_output; | ||
| 173 | overall.default_output_override_content = remote_command_output; | ||
| 174 | overall.default_output_override = check_by_ssh_output_override; | ||
| 162 | } else { | 175 | } else { |
| 163 | xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", | 176 | xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", |
| 164 | config.remotecmd, child_result.cmd_error_code); | 177 | config.remotecmd, child_result.cmd_error_code); |
