Add option to override output for check in lib for check_by_ssh (#2230)
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Spellcheck / codespell (push) Waiting to run
Tests / Running unit and integrationt tests (push) Waiting to run
Tests / Running rpm build test on almalinux:9 (push) Waiting to run
Tests / Running rpm build test on fedora:latest (push) Waiting to run
Tests / Running rpm build test on rockylinux:8 (push) Waiting to run

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.
This commit is contained in:
Lorenz Kästle 2026-04-06 12:17:43 +02:00 committed by GitHub
parent c57381d789
commit 9980e78850
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View file

@ -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);
}

View file

@ -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);

View file

@ -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);