--- src/zabbix_server/operations.c~ 2008-01-06 10:45:55.000000000 -0800 +++ src/zabbix_server/operations.c 2008-01-06 11:03:09.000000000 -0800 @@ -440,6 +440,49 @@ /****************************************************************************** * * + * Function: find uname value for hostname if system.uname service exists * + * * + * Purpose: work around broken reverse DNS and/or multihoming * + * * + * Parameters: dhostid - discovered host id * + * host - output buffer for hostname * + * hostlen - size of output buffer in bytes * + * * + * Return value: none * + * * + * Author: Lamont Granquist * + * * + * Comments: assumes uname return is single-space delimited with the second * + * value equal to the hostname * + * * + ******************************************************************************/ +void try_gethost_from_uname(zbx_uint64_t dhostid, char *host, size_t hostlen) +{ + DB_RESULT result; + DB_ROW row; + char *uname; + char *hostname; + char *cp; + + host[0] = '\0'; + result = DBselect("select value from dhosts join dservices on dhosts.dhostid = dservices.dhostid where dservices.key_='system.uname' and dservices.dhostid=" ZBX_FS_UI64, + dhostid); + row = DBfetch(result); + if(row && DBis_null(row[0]) != SUCCEED) + { + uname = row[0]; + hostname = strchr(uname, ' '); + if (!hostname) return; + hostname++; + cp = strchr(hostname, ' '); + if (!cp) return; + *cp = '\0'; + zbx_strlcpy(host, hostname, hostlen); + } +} + +/****************************************************************************** + * * * Function: add host if not added already * * * * Purpose: add discovered host * @@ -473,9 +516,14 @@ { ip=row[0]; - alarm(CONFIG_TIMEOUT); - zbx_gethost_by_ip(ip, host, sizeof(host)); - alarm(0); + try_gethost_from_uname(dhostid, host, sizeof(host)); + + if (host[0] == '\0') + { + alarm(CONFIG_TIMEOUT); + zbx_gethost_by_ip(ip, host, sizeof(host)); + alarm(0); + } DBescape_string(host, host_esc, sizeof(host_esc));