Patch to check_ntp_time.c and netutils.c to not resolve hostname if given as an IP address
Frank Fegert <[email protected]>
| Newsgroups | gmane.network.nagios.plugins.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello all,
i'd like to propose the attached patch against the current nagios-plugins-1.4.16
sources. Although it's a bit hacky, i tried to accomplish the following with this
patch:
- Add help output wrt the "-4" and "-6" command line options.
- Move "is_host()" check to after the evaluation of the "-4" and "-6" command
line options. Otherwise, when built with "USE_IPV6", the address_family for
the call to resolve_host_or_addr stays at the default AF_UNSPEC instead of
being set to AF_INET or AF_INET6.
- Add check logic to determine if the argument passed to the "-H" command line
option is already a valid IPv4 or IPv6 address. In this case no name lookup
with getaddrinfo should be necessary.
I recently ran into an issue related to this: The check_ntp_time calls were
configured against the IP adresses of two NTP servers, e.g.:
check_ntp_time -H 192.168.1.1 -w ... -c ...
check_ntp_time -H 192.168.2.1 -w ... -c ...
The IP addresses were deliberately used to be independent of DNS glitches.
Still, when the companies DNS/AD went half braindead, check_ntp_time started
complaining about NTP connection issues, steering everyone a bit in the wrong
direction. In this particular case it was a good thing, because it would've
been a much longer time before someone would've figured out a only partially
working DNS/AD ;-)
See here for an explaination of the "ifdef _AIX":
http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.commtechref%2Fdoc%2Fcommtrf2%2Finet_pton.htm
http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.commtechref%2Fdoc%2Fcommtrf2%2Finet_pton6_zone.htm
Any comments are very welcome!
Thanks & best regards,
Frank Fegert
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________________
Nagios Plugin Development Mailing List Nagiosplug-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
::: Please include plugins version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
nagios-plugins.patch
(text/x-diff, 1.7 KB)
--- plugins/check_ntp_time.c.orig 2012-12-23 15:41:55.000000000 +0100
+++ plugins/check_ntp_time.c 2012-12-23 15:47:30.000000000 +0100
@@ -488,8 +488,6 @@
ocrit = optarg;
break;
case 'H':
- if(is_host(optarg) == FALSE)
- usage2(_("Invalid hostname/address"), optarg);
server_address = strdup(optarg);
break;
case 'p':
@@ -518,6 +516,8 @@
if(server_address == NULL){
usage4(_("Hostname was not supplied"));
}
+ if(is_host(server_address) == FALSE)
+ usage2(_("Invalid hostname/address"), server_address);
return 0;
}
@@ -610,6 +610,7 @@
printf (" %s\n", "-c, --critical=THRESHOLD");
printf (" %s\n", _("Offset to result in critical status (seconds)"));
printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
+ printf (UT_IPv46);
printf (UT_VERBOSE);
printf("\n");
--- plugins/netutils.c.orig 2012-12-23 14:09:54.000000000 +0100
+++ plugins/netutils.c 2012-12-23 16:15:14.000000000 +0100
@@ -353,6 +353,29 @@
struct addrinfo *res;
int retval;
+ #ifdef _AIX
+ if (family == AF_INET) {
+ char dst[INET_ADDRSTRLEN];
+ retval = inet_pton(family, address, dst);
+ if (retval == 1)
+ return TRUE;
+ #ifdef USE_IPV6
+ } else if (family == AF_INET6) {
+ struct sockaddr_in6 dst;
+ retval = inet_pton6_zone(address, &dst);
+ if (retval == 1)
+ return TRUE;
+ #endif /* USE_IPV6 */
+ } else {
+ printf ("%s\n", _("Unknown adress family"));
+ }
+ #else
+ char dst[INET_ADDRSTRLEN];
+ retval = inet_pton(family, address, dst);
+ if (retval == 1)
+ return TRUE;
+ #endif /* _AIX */
+
memset (&hints, 0, sizeof (hints));
hints.ai_family = family;
retval = getaddrinfo (address, NULL, &hints, &res);