mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-04-22 06:36:55 -04:00
check_by_ssh: do not incorrectly assume that ssh (1) succeeded
This commit is contained in:
parent
5ced56b268
commit
62242ddcf5
1 changed files with 2 additions and 21 deletions
|
|
@ -94,37 +94,18 @@ int main(int argc, char **argv) {
|
|||
mp_check overall = mp_check_init();
|
||||
|
||||
/* SSH returns 255 if connection attempt fails; include the first line of error output */
|
||||
mp_subcheck sc_ssh_execution = mp_subcheck_init();
|
||||
// we can sadly not detect other SSH errors
|
||||
if (child_result.cmd_error_code == 255 && config.unknown_timeout) {
|
||||
mp_subcheck sc_ssh_execution = mp_subcheck_init();
|
||||
xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s",
|
||||
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);
|
||||
|
||||
if (verbose) {
|
||||
for (size_t i = 0; i < child_result.stdout.lines; i++) {
|
||||
printf("stdout: %s\n", child_result.stdout.line[i]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue