[monitoring-plugins] check_by_ssh: handle errrors of ssh (1) directly

Lorenz Kästle git at monitoring-plugins.org
Sun Nov 16 15:50:12 CET 2025


 Module: monitoring-plugins
 Branch: master
 Commit: 463223790cb67421d420ba982c1f5ee6cc6f2b4a
 Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
   Date: Sun Nov 16 14:52:07 2025 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=46322379

check_by_ssh: handle errrors of ssh (1) directly

---

 plugins/check_by_ssh.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

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



More information about the Commits mailing list