[monitoring-plugins] check_ssh: set elapsed time properly

RincewindsHat git at monitoring-plugins.org
Thu Oct 31 16:20:13 CET 2024


 Module: monitoring-plugins
 Branch: master
 Commit: 0fd0421052fed1972ecbdfdabecba5a616eaa109
 Author: RincewindsHat <12514511+RincewindsHat at users.noreply.github.com>
   Date: Fri Sep  6 01:53:47 2024 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=0fd0421

check_ssh: set elapsed time properly

Previous to this commit, `elapsed_time` was only set after being read,
which was quite likely wrong and a bug.
This commit actually set the value before it is being read again.

---

 plugins/check_ssh.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index a3b5358..d162e42 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -222,7 +222,6 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
 	char *ssh_server = NULL;
 	static char *rev_no = VERSION;
 	struct timeval tv;
-	double elapsed_time = 0;
 
 	gettimeofday(&tv, NULL);
 
@@ -334,6 +333,7 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
 		exit (STATE_CRITICAL);
 	}
 
+	double elapsed_time = (double)deltime(tv) / 1.0e6;
 	if (remote_protocol && strcmp(remote_protocol, ssh_proto)) {
 		printf
 			(_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s' | %s\n"),
@@ -342,7 +342,6 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
 		close(sd);
 		exit (STATE_CRITICAL);
 	}
-	elapsed_time = (double)deltime(tv) / 1.0e6;
 
 	printf
 		(_("SSH OK - %s (protocol %s) | %s\n"),



More information about the Commits mailing list