diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-11-16 15:27:19 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-11-16 15:27:19 +0100 |
| commit | 62242ddcf5caa09eee79c15a94a5d861b9be95c8 (patch) | |
| tree | 079a3ad6b6b53a28d1b913a278bfa422fa30bbc2 /plugins/check_by_ssh.c | |
| parent | 5ced56b268ed9a8f06755c89615aac68618557ae (diff) | |
| download | monitoring-plugins-62242ddcf5caa09eee79c15a94a5d861b9be95c8.tar.gz | |
check_by_ssh: do not incorrectly assume that ssh (1) succeeded
Diffstat (limited to 'plugins/check_by_ssh.c')
| -rw-r--r-- | plugins/check_by_ssh.c | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 8036ffa4..ebe54b80 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
| @@ -94,8 +94,9 @@ int main(int argc, char **argv) { | |||
| 94 | mp_check overall = mp_check_init(); | 94 | mp_check overall = mp_check_init(); |
| 95 | 95 | ||
| 96 | /* SSH returns 255 if connection attempt fails; include the first line of error output */ | 96 | /* SSH returns 255 if connection attempt fails; include the first line of error output */ |
| 97 | mp_subcheck sc_ssh_execution = mp_subcheck_init(); | 97 | // we can sadly not detect other SSH errors |
| 98 | if (child_result.cmd_error_code == 255 && config.unknown_timeout) { | 98 | if (child_result.cmd_error_code == 255 && config.unknown_timeout) { |
| 99 | mp_subcheck sc_ssh_execution = mp_subcheck_init(); | ||
| 99 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s", | 100 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s", |
| 100 | child_result.stderr.lines > 0 ? child_result.stderr.line[0] | 101 | child_result.stderr.lines > 0 ? child_result.stderr.line[0] |
| 101 | : "(no error output)"); | 102 | : "(no error output)"); |
| @@ -103,28 +104,8 @@ int main(int argc, char **argv) { | |||
| 103 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); | 104 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); |
| 104 | mp_add_subcheck_to_check(&overall, sc_ssh_execution); | 105 | mp_add_subcheck_to_check(&overall, sc_ssh_execution); |
| 105 | mp_exit(overall); | 106 | mp_exit(overall); |
| 106 | } else if (child_result.cmd_error_code != 0) { | ||
| 107 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: "); | ||
| 108 | |||
| 109 | if (child_result.stderr.lines > 0) { | ||
| 110 | for (size_t i = 0; i < child_result.stderr.lines; i++) { | ||
| 111 | xasprintf(&sc_ssh_execution.output, "%s\n%s", sc_ssh_execution.output, | ||
| 112 | child_result.stderr.line[i]); | ||
| 113 | } | ||
| 114 | } else { | ||
| 115 | xasprintf(&sc_ssh_execution.output, "%s %s", sc_ssh_execution.output, | ||
| 116 | "no output on stderr"); | ||
| 117 | } | ||
| 118 | |||
| 119 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); | ||
| 120 | mp_add_subcheck_to_check(&overall, sc_ssh_execution); | ||
| 121 | mp_exit(overall); | ||
| 122 | } | 107 | } |
| 123 | 108 | ||
| 124 | xasprintf(&sc_ssh_execution.output, "SSH connection succeeded"); | ||
| 125 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_OK); | ||
| 126 | mp_add_subcheck_to_check(&overall, sc_ssh_execution); | ||
| 127 | |||
| 128 | if (verbose) { | 109 | if (verbose) { |
| 129 | for (size_t i = 0; i < child_result.stdout.lines; i++) { | 110 | for (size_t i = 0; i < child_result.stdout.lines; i++) { |
| 130 | printf("stdout: %s\n", child_result.stdout.line[i]); | 111 | printf("stdout: %s\n", child_result.stdout.line[i]); |
