summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavide Madrisan <davide.madrisan@gmail.com>2014-05-07 22:14:45 +0200
committerJan Wagner <waja@cyconet.org>2014-07-29 11:08:44 +0200
commite85fcbd5711999af88ed887c0c17a26ab29f2b28 (patch)
treebd6765faf926780f75795f8870db4d41f03a059a
parent2e8d440e73ac2b1875db5ecaf6df510fdcf6eb7a (diff)
downloadmonitoring-plugins-e85fcbd.tar.gz
This patch will add the IP and port, or socket name, to the error message and
thus simplify the problem debugging: no need to check for this information in the Nagios configuration. This function is only used by 'check_tcp.c'. Without the patch: $ ./plugins/check_tcp -H 127.0.0.1 -p 21 Connection refused $ ./plugins/check_tcp -H /var/spool/nagios/cmd/nagios.cmd Permission denied With the patch: $ ./plugins/check_tcp -H 127.0.0.1 -p 21 connect to address 127.0.0.1 and port 21: Connection refused $ ./plugins/check_tcp -H /var/spool/nagios/cmd/nagios.cmd connect to socket /var/spool/nagios/cmd/nagios.cmd: Permission denied Thanks to Davide Madrisan. --- Closes #1277
-rw-r--r--plugins/netutils.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 00440465..48042188 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -167,11 +167,13 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
167 char port_str[6], host[MAX_HOST_ADDRESS_LENGTH]; 167 char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
168 size_t len; 168 size_t len;
169 int socktype, result; 169 int socktype, result;
170 bool is_socket;
170 171
171 socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM; 172 socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
173 bool is_socket = (host_name[0] == '/');
172 174
173 /* as long as it doesn't start with a '/', it's assumed a host or ip */ 175 /* as long as it doesn't start with a '/', it's assumed a host or ip */
174 if(host_name[0] != '/'){ 176 if (!is_socket){
175 memset (&hints, 0, sizeof (hints)); 177 memset (&hints, 0, sizeof (hints));
176 hints.ai_family = address_family; 178 hints.ai_family = address_family;
177 hints.ai_protocol = proto; 179 hints.ai_protocol = proto;
@@ -253,7 +255,11 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
253 return econn_refuse_state; 255 return econn_refuse_state;
254 break; 256 break;
255 case STATE_CRITICAL: /* user did not set econn_refuse_state */ 257 case STATE_CRITICAL: /* user did not set econn_refuse_state */
256 printf ("%s\n", strerror(errno)); 258 if (is_socket)
259 printf("connect to socket %s: %s\n", host_name, strerror(errno));
260 else
261 printf("connect to address %s and port %d: %s\n",
262 host_name, port, strerror(errno));
257 return econn_refuse_state; 263 return econn_refuse_state;
258 break; 264 break;
259 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */ 265 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
@@ -262,7 +268,11 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
262 } 268 }
263 } 269 }
264 else { 270 else {
265 printf ("%s\n", strerror(errno)); 271 if (is_socket)
272 printf("connect to socket %s: %s\n", host_name, strerror(errno));
273 else
274 printf("connect to address %s and port %d: %s\n",
275 host_name, port, strerror(errno));
266 return STATE_CRITICAL; 276 return STATE_CRITICAL;
267 } 277 }
268} 278}