Ad Widget

Collapse

AutoRegistration - DNS instead of IP for agent interface

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mike smith
    Junior Member
    • Jun 2012
    • 18

    #1

    AutoRegistration - DNS instead of IP for agent interface

    i can't seem to find anything recent related to agents auto-registering with the server using the dns name instead of the ip address for the agent interface.

    In add_discovered_host() eventid:17426
    query [txnlev:1] [select proxy_hostid,host,listen_ip,listen_dns,listen_port from autoreg_host where autoreg_hostid=14]
    query [txnlev:1] [select null from hosts where host='host.xxx.com' and status=3]
    query [txnlev:1] [select hostid,proxy_hostid from hosts where host='host.xxx.com' and flags<>2 and status in (0,1) order by hostid limit 1]
    In DBget_nextid() tablename:'hosts'
    query [txnlev:1] [select nextid from ids where nodeid=0 and table_name='hosts' and field_name='hostid']
    query [txnlev:1] [update ids set nextid=nextid+1 where nodeid=0 and table_name='hosts' and field_name='hostid']
    query [txnlev:1] [select nextid from ids where nodeid=0 and table_name='hosts' and field_name='hostid']
    End of DBget_nextid():10123 table:'hosts' recid:'hostid'
    query [txnlev:1] [insert into hosts (hostid,proxy_hostid,host,name) values (10123,null,'host.xxx.com','host.xxx.com')]
    In DBadd_interface()
    query [txnlev:1] [select interfaceid,useip,ip,dns,port,main from interface where hostid=10123 and type=1]
    In DBget_nextid() tablename:'interface'
    query [txnlev:1] [select nextid from ids where nodeid=0 and table_name='interface' and field_name='interfaceid']
    query [txnlev:1] [update ids set nextid=nextid+1 where nodeid=0 and table_name='interface' and field_name='interfaceid']
    query [txnlev:1] [select nextid from ids where nodeid=0 and table_name='interface' and field_name='interfaceid']
    End of DBget_nextid():20 table:'interface' recid:'interfaceid'
    query [txnlev:1] [insert into interface (interfaceid,hostid,main,type,useip,ip,dns,port) values (20,10123,1,1,1,'192.168.246.148','',10050)]

    it seems as though the dns name is known by zabbix_server, but for some reason it doesn't use it.

    i'm using the following from the amazon linux repo, it's the latest version.

    zabbix_agentd --version
    Zabbix Agent (daemon) v2.2.1 (revision 40808) (09 December 2013)

    zabbix_server --version
    Zabbix server v2.2.1 (revision 40808) (09 December 2013)

    has this been fixed/changed in a newer version?


    EDIT - just found this - https://www.zabbix.com/documentation...g_of_dns_names

    5.5.4 Automatic filling of DNS names

    For network discovery and active agent autoregistration, host DNS entry is now populated by doing a reverse lookup from Zabbix server or Zabbix proxy, if discovery is performed by a proxy.

    EDIT 2 - providing a working reverse dns entry for the ip address does indeed populate the dns name into the agent interface. however, the connect to option is still set to IP instead of DNS. does anyone know how to force that to use DNS?
    Last edited by mike smith; 24-04-2015, 17:08.
  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #2
    I've done something similar by setting up a notification in the auto registration action that uses a script. I have that script sleep 5 seconds (I don't know if that's necessary), then I use the API to update the new host. In my case, I'm turning on automatic host inventory, but switching from ip to dns on the interface shouldn't be much different.

    Comment

    • mike smith
      Junior Member
      • Jun 2012
      • 18

      #3
      it seems like this would be unnecessary. looking at the source, src/libs/zbxdbhigh/host.c, i see some checks about us IP or use DNS, but my c is really, really rusty, and i don't quite follow what's its checking to determine whether to set IP or DNS. maybe someone else can help my understanding of the code?

      hey alexander! any insight?

      /************************************************** ****************************
      * *
      * Function: DBadd_interface *
      * *
      * Purpose: add new interface to specified host *
      * *
      * Parameters: hostid - [IN] host identificator from database *
      * type - [IN] new interface type *
      * useip - [IN] how to connect to the host 0/1 - DNS/IP *
      * ip - [IN] IP address *
      * dns - [IN] DNS address *
      * port - [IN] port *
      * *
      * Return value: upon successful completion return interface identificator *
      * *
      * Author: Alexander Vladishev *
      * *
      * Comments: *
      * *
      ************************************************** ****************************/
      zbx_uint64_t DBadd_interface(zbx_uint64_t hostid, unsigned char type,
      unsigned char useip, const char *ip, const char *dns, unsigned short port)
      {
      const char *__function_name = "DBadd_interface";

      DB_RESULT result;
      DB_ROW row;
      char *ip_esc, *dns_esc, *tmp = NULL;
      zbx_uint64_t interfaceid = 0;
      unsigned char main_ = 1, db_main, db_useip;
      unsigned short db_port;
      const char *db_ip, *db_dns;

      zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

      result = DBselect(
      "select interfaceid,useip,ip,dns,port,main"
      " from interface"
      " where hostid=" ZBX_FS_UI64
      " and type=%d",
      hostid, (int)type);

      while (NULL != (row = DBfetch(result)))
      {
      db_useip = (unsigned char)atoi(row[1]);
      db_ip = row[2];
      db_dns = row[3];
      db_main = (unsigned char)atoi(row[5]);
      if (1 == db_main)
      main_ = 0;

      if (db_useip != useip)
      continue;

      if (useip && 0 != strcmp(db_ip, ip))
      continue;

      if (!useip && 0 != strcmp(db_dns, dns))
      continue;

      zbx_free(tmp);
      tmp = strdup(row[4]);
      substitute_simple_macros(NULL, NULL, NULL, NULL, &hostid, NULL, NULL, &tmp, MACRO_TYPE_COMMON, NULL, 0);
      if (FAIL == is_ushort(tmp, &db_port) || db_port != port)
      continue;

      ZBX_STR2UINT64(interfaceid, row[0]);
      break;
      }
      DBfree_result(result);

      zbx_free(tmp);

      if (0 != interfaceid)
      goto out;

      ip_esc = DBdyn_escape_string_len(ip, INTERFACE_IP_LEN);
      dns_esc = DBdyn_escape_string_len(dns, INTERFACE_DNS_LEN);

      interfaceid = DBget_maxid("interface");

      DBexecute("insert into interface"
      " (interfaceid,hostid,main,type,useip,ip,dns,port)"
      " values"
      " (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d,%d,%d,'%s','%s',%d)",
      interfaceid, hostid, (int)main_, (int)type, (int)useip, ip_esc, dns_esc, (int)port);

      zbx_free(dns_esc);
      zbx_free(ip_esc);
      out:
      zabbix_log(LOG_LEVEL_DEBUG, "End of %s():" ZBX_FS_UI64, __function_name, interfaceid);

      return interfaceid;
      }

      Comment

      • mike smith
        Junior Member
        • Jun 2012
        • 18

        #4
        i'd love to see you code if you don't mind sharing!

        Comment

        • rb1980
          Junior Member
          • May 2013
          • 7

          #5
          easy solution

          Take a look at:

          Comment

          Working...