[hobbit] Pulldata problems

Henrik Stoerner henrik at hswn.dk
Mon Aug 14 22:13:21 CEST 2006


On Mon, Aug 14, 2006 at 05:46:10PM +0200, Francesco Duranti wrote:

> I'm start using msgcache and pulldata, I've all of my  hosts in the
> bb-hosts file with 0.0.0.0 ip address so that I can define the ip in the
> /etc/hosts and use it for every application that need it.
> 
> I've 2 hosts with pulldata defined as:
> 0.0.0.0 itromwb13 # pulldata
> 
> and when hobbitfetch try to get the data it will try to use 0.0.0.0:1984
> instead of resolving and using the hostname. 

It works as designed, but it might not be the best way to do it. The
attached patch will make hobbitfetch determine the IP-address from the
hostname, if the IP in bb-hosts is 0.0.0.0.

It also takes care of your other requests for "pulldata=:2084" style
syntax.


Regards,
Henrik

-------------- next part --------------
--- hobbitd/hobbitfetch.c	2006/07/22 11:23:56	1.13
+++ hobbitd/hobbitfetch.c	2006/08/14 20:10:05
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <arpa/nameser.h>
 #include <netdb.h>
 #include <ctype.h>
 #include <signal.h>
@@ -619,14 +620,36 @@
 					ip = strdup(bbh_item(hostwalk, BBH_IP));
 				}
 				else {
+					/* There is an explicit IP setting in the pulldata tag */
 					char *p;
 
 					ip++; /* Skip the '=' */
 					ip = strdup(ip);
 					p = strchr(ip, ':');
 					if (p) { *p = '\0'; port = atoi(p+1); }
+
+					if (*ip == '\0') {
+						/* No IP given, just a port number */
+						xfree(ip);
+						ip = strdup(bbh_item(hostwalk, BBH_IP));
+					}
+				}
+
+				if (strcmp(ip, "0.0.0.0") == 0) {
+					struct hostent *hent;
+
+					xfree(ip); ip = NULL;
+					hent = gethostbyname(clientwalk->hostname);
+					if (hent) {
+						struct in_addr addr;
+
+						memcpy(&addr, *(hent->h_addr_list), sizeof(addr));
+						ip = strdup(inet_ntoa(addr));
+					}
 				}
 
+				if (!ip) continue;
+
 				/* 
 				 * Build the "pullclient" request, which includes the latest
 				 * clientdata config we got from the server. Keep the clientdata


More information about the Xymon mailing list