diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-25 13:03:00 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-07 23:38:50 +0100 |
| commit | 6428696f31289c2777a34f4c0f761aa038da6284 (patch) | |
| tree | 00f8ef1b3eb76d5a84e6d5188eccaec66f256228 | |
| parent | 92fb0ec66218059589d0b6b0fed08735b2765d60 (diff) | |
| download | monitoring-plugins-6428696f31289c2777a34f4c0f761aa038da6284.tar.gz | |
check_ssh: exit properly if TCP connection fails
| -rw-r--r-- | plugins/check_ssh.c | 5 |
1 files changed, 4 insertions, 1 deletions
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_ | |||
| 235 | int socket; | 235 | int socket; |
| 236 | int result = my_tcp_connect(haddr, hport, &socket); | 236 | int result = my_tcp_connect(haddr, hport, &socket); |
| 237 | 237 | ||
| 238 | mp_subcheck connection_sc = mp_subcheck_init(); | ||
| 238 | if (result != STATE_OK) { | 239 | if (result != STATE_OK) { |
| 240 | connection_sc = mp_set_subcheck_state(connection_sc, STATE_CRITICAL); | ||
| 241 | xasprintf(&connection_sc.output, "Failed to establish TCP connection to Host %s and Port %d", haddr, hport); | ||
| 242 | mp_add_subcheck_to_check(overall, connection_sc); | ||
| 239 | return result; | 243 | return result; |
| 240 | } | 244 | } |
| 241 | 245 | ||
| @@ -280,7 +284,6 @@ int ssh_connect(mp_check *overall, char *haddr, int hport, char *desired_remote_ | |||
| 280 | } | 284 | } |
| 281 | } | 285 | } |
| 282 | 286 | ||
| 283 | mp_subcheck connection_sc = mp_subcheck_init(); | ||
| 284 | if (recv_ret < 0) { | 287 | if (recv_ret < 0) { |
| 285 | connection_sc = mp_set_subcheck_state(connection_sc, STATE_CRITICAL); | 288 | connection_sc = mp_set_subcheck_state(connection_sc, STATE_CRITICAL); |
| 286 | xasprintf(&connection_sc.output, "%s", "SSH CRITICAL - %s", strerror(errno)); | 289 | xasprintf(&connection_sc.output, "%s", "SSH CRITICAL - %s", strerror(errno)); |
