[Nagiosplug-devel] check_ping problem

Karl DeBisschop karl at debisschop.net
Fri Jul 23 05:26:25 CEST 2004


Robert Nelson said:
>> A reasonable question is whether this is a problem in the
>> nagios plugin
>> or in your local resolver library.  If you just type a
>>   ping tap-5300h.2wachovia.nc.windchannel.com
>> to a shell prompt, do you get normal output or a resolver error?  If
>> the bare ping command works, you may have to tweak the check_ping to
>> use it instead of some ping program that comes with the
>> nagios plugins.
>> (My nagios box is down at the moment so I can't check exactly where
>> nagios gets its ping; I do remember that it configured it wrong and I
>> had to fix that).
>
> Pings and nslookups themselves resolve fine without difficulty, which is
> why I was so surprised :) I'm using nagios-plugins-1.3.1 and here's what
> I found - goes beyond check_ping, in fact:
>
>
> The offending code in check_ping.c is (starting on line 200):
>
> =====
>                 case 'H':       /* hostname */
>                         if (is_host (optarg) == FALSE)
>                                 usage2 ("Invalid host name/address",
> optarg);
>                         server_address = optarg;
>                         break;
> =====
>
> The is_host seems to be defined in utils.c on line 167:
>
> =====
> int
> is_host (char *address)
> {
>         if (is_dotted_quad (address) || is_hostname (address))
>                 return (TRUE);
>         return (FALSE);
> }
> =====
>
> That then leads to utils.c on line 215:
>
> =====
> int
> is_hostname (char *s1)
> {
>         if (!s1 || strlen (s1) > 255) {
>                 return FALSE;
>         }
>         /* if s1 contains anything but ALPHA, NUM, dash, or period*/
>         if (strcspn (s1,
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") !=
> 0) {
>                 return FALSE;
>         }
>         /* or if s1 begins with dash or period */
>         if (strspn (s1, "-.") == 1) {
>                 return FALSE;
>         }
>   /* '..' and '.-' are not legal either */
>         while ((s1 = index (s1, '.'))) {
>                 s1++;
>                 if (strspn (s1, "0123456789-.") == 1) {
>                         return FALSE;
>                 }
>         }
>         return TRUE;
> }
> =====
>
> I know enough about code to be dangerous but not offer anything helpful.
> But I'm going to try anyway ;) If I remove the last if test, it will
> probably start accepting the domain 2wachovia...However, I'm not sure
> why a check for '..' and '.-' use a regex that will match '.0' through
> '.9' as well. What else would this affect, if I "fixed" that if
> statement and recompiled? And how long can I reasonably expect for any
> such fix to happen and be merged with the source?

You can go ahead and make the change - this regex correspnds to the old
definition of an arpa hostname - which is stricter than the present
defintion.

Fixing the code in CVS is on the TODO list.

--
Karl






More information about the Devel mailing list