From 463223790cb67421d420ba982c1f5ee6cc6f2b4a Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 16 Nov 2025 14:52:07 +0100 Subject: check_by_ssh: handle errrors of ssh (1) directly --- plugins/check_by_ssh.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'plugins/check_by_ssh.c') diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index ad385fbd..8036ffa4 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -100,10 +100,27 @@ int main(int argc, char **argv) { child_result.stderr.lines > 0 ? child_result.stderr.line[0] : "(no error output)"); + sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); + mp_add_subcheck_to_check(&overall, sc_ssh_execution); + mp_exit(overall); + } else if (child_result.cmd_error_code != 0) { + xasprintf(&sc_ssh_execution.output, "SSH connection failed: "); + + if (child_result.stderr.lines > 0) { + for (size_t i = 0; i < child_result.stderr.lines; i++) { + xasprintf(&sc_ssh_execution.output, "%s\n%s", sc_ssh_execution.output, + child_result.stderr.line[i]); + } + } else { + xasprintf(&sc_ssh_execution.output, "%s %s", sc_ssh_execution.output, + "no output on stderr"); + } + sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); mp_add_subcheck_to_check(&overall, sc_ssh_execution); mp_exit(overall); } + xasprintf(&sc_ssh_execution.output, "SSH connection succeeded"); sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_OK); mp_add_subcheck_to_check(&overall, sc_ssh_execution); -- cgit v1.2.3-74-g34f1