[monitoring-plugins] Do not print on failed network connections

Lorenz Kästle git at monitoring-plugins.org
Thu Mar 13 15:20:13 CET 2025


 Module: monitoring-plugins
 Branch: master
 Commit: 44e4e467c678d481dfc74ade1beb47e199ea67dd
 Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
   Date: Thu Mar 13 00:43:46 2025 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=44e4e467

Do not print on failed network connections

---

 plugins/netutils.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/plugins/netutils.c b/plugins/netutils.c
index ee81912a..5f118a9e 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -177,7 +177,7 @@ int np_net_connect(const char *host_name, int port, int *sd, int proto) {
 		result = getaddrinfo(host, port_str, &hints, &res);
 
 		if (result != 0) {
-			printf("%s\n", gai_strerror(result));
+			// printf("%s\n", gai_strerror(result));
 			return STATE_UNKNOWN;
 		}
 
@@ -187,7 +187,7 @@ int np_net_connect(const char *host_name, int port, int *sd, int proto) {
 			*sd = socket(r->ai_family, socktype, r->ai_protocol);
 
 			if (*sd < 0) {
-				printf("%s\n", _("Socket creation failed"));
+				// printf("%s\n", _("Socket creation failed"));
 				freeaddrinfo(r);
 				return STATE_UNKNOWN;
 			}
@@ -237,10 +237,11 @@ int np_net_connect(const char *host_name, int port, int *sd, int proto) {
 		case STATE_OK:
 		case STATE_WARNING:  /* user wants WARN or OK on refusal, or... */
 		case STATE_CRITICAL: /* user did not set econn_refuse_state, or wanted critical */
-			if (is_socket)
-				printf("connect to file socket %s: %s\n", host_name, strerror(errno));
-			else
-				printf("connect to address %s and port %d: %s\n", host_name, port, strerror(errno));
+			if (is_socket) {
+				// printf("connect to file socket %s: %s\n", host_name, strerror(errno));
+			} else {
+				// printf("connect to address %s and port %d: %s\n", host_name, port, strerror(errno));
+			}
 			return STATE_CRITICAL;
 			break;
 		default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
@@ -248,10 +249,11 @@ int np_net_connect(const char *host_name, int port, int *sd, int proto) {
 			break;
 		}
 	} else {
-		if (is_socket)
-			printf("connect to file socket %s: %s\n", host_name, strerror(errno));
-		else
-			printf("connect to address %s and port %d: %s\n", host_name, port, strerror(errno));
+		if (is_socket) {
+			// printf("connect to file socket %s: %s\n", host_name, strerror(errno));
+		} else {
+			// printf("connect to address %s and port %d: %s\n", host_name, port, strerror(errno));
+		}
 		return STATE_CRITICAL;
 	}
 }



More information about the Commits mailing list