From 6428696f31289c2777a34f4c0f761aa038da6284 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 25 Feb 2025 13:03:00 +0100 Subject: check_ssh: exit properly if TCP connection fails --- plugins/check_ssh.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'plugins/check_ssh.c') diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index 3d6a0710..d06af3e7 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c @@ -235,7 +235,11 @@ int ssh_connect(mp_check *overall, char *haddr, int hport, char *desired_remote_ int socket; int result = my_tcp_connect(haddr, hport, &socket); + mp_subcheck connection_sc = mp_subcheck_init(); if (result != STATE_OK) { + connection_sc = mp_set_subcheck_state(connection_sc, STATE_CRITICAL); + xasprintf(&connection_sc.output, "Failed to establish TCP connection to Host %s and Port %d", haddr, hport); + mp_add_subcheck_to_check(overall, connection_sc); return result; } @@ -280,7 +284,6 @@ int ssh_connect(mp_check *overall, char *haddr, int hport, char *desired_remote_ } } - mp_subcheck connection_sc = mp_subcheck_init(); if (recv_ret < 0) { connection_sc = mp_set_subcheck_state(connection_sc, STATE_CRITICAL); xasprintf(&connection_sc.output, "%s", "SSH CRITICAL - %s", strerror(errno)); -- cgit v1.2.3-74-g34f1