Ad Widget

Collapse

Auto registration connect to IP of agent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • symfrog
    Junior Member
    • Oct 2009
    • 12

    #1

    Auto registration connect to IP of agent

    Hi

    We have got auto registration to work for our zabbix agents. However, when they are registered they are set to connect to DNS and the IP is 127.0.0.1 on the zabbix server. Screenshot of host config is attached.

    Is there a way during auto registration to tell the server to connect to agent using IP instead of dns name (as is possible when manually adding a host)? I would prefer not to have to update dns/hosts on server for each agent added. Also why is the IP 127.0.0.1 and how can the server be told to use the agent's IP?
    Attached Files
  • j_zuilkowski
    Junior Member
    • Dec 2009
    • 2

    #2
    I was wondering about this as well, so I went on an expedition through the code.

    What I found was that it seems the auto register stuff only checks known hostnames, then generates a new hostid for unknowns, then stuffs it into a table. It does not stuff any address into any table that I could find, so the table picks up the default '127.0.0.1'

    This is lame, but I don't have the time to code up anything for stuffing the ip in as well as hostname.

    -Jon.

    Comment

    • karichel
      Junior Member
      • Jun 2010
      • 2

      #3
      Auto registration issue with IP

      I am also having the same issue, any one got around it?

      -AK

      Comment

      • mattsmith
        Member
        Zabbix Certified Specialist
        • Aug 2010
        • 33

        #4
        Did this ever get resolved? we would like to use this feature for our cloud servers.

        Comment

        • mattsmith
          Member
          Zabbix Certified Specialist
          • Aug 2010
          • 33

          #5
          Hi All,

          Sorry to bump an old thread, are any of the senior members able to help?

          Regards
          Matt

          Comment

          • walterheck
            Senior Member
            • Jul 2009
            • 153

            #6
            I have no specific knowledge on this topic, but I guess your best chance at getting this fixed is logging an issue in the support system. Then link back to it here, so others that want the same can vote on your issue, which will make it be implemented faster
            Free and Open Source Zabbix Templates Repository | Hosted Zabbix @ Tribily (http://tribily.com)

            Comment

            • dagun
              Member
              • Sep 2009
              • 71

              #7
              Who could give me a explaination?

              Thanks, give me a help.

              Comment

              • dagun
                Member
                • Sep 2009
                • 71

                #8
                I have look the source code.

                zabbix_server/operations.c

                static zbx_uint64_t add_discovered_host(DB_EVENT *event)
                {
                const char *__function_name = "add_discovered_host";
                DB_RESULT result;
                DB_RESULT result2;
                DB_ROW row;
                DB_ROW row2;
                zbx_uint64_t hostid = 0, proxy_hostid, host_proxy_hostid;
                char host[MAX_STRING_LEN], *host_esc, *ip_esc, *host_unique, *host_unique_esc;
                int port;
                zbx_uint64_t groupid;

                zabbix_log(LOG_LEVEL_DEBUG, "In %s(eventid:" ZBX_FS_UI64 ")",
                __function_name, event->eventid);

                result = DBselect(
                "select discovery_groupid"
                " from config"
                " where 1=1"
                DB_NODE,
                DBnode_local("configid"));

                if (NULL != (row = DBfetch(result)))
                {
                ZBX_STR2UINT64(groupid, row[0]);
                }
                else
                {
                zabbix_log(LOG_LEVEL_WARNING, "Can't add discovered host:"
                " Group for discovered hosts is not defined");
                return 0;
                }
                DBfree_result(result);

                switch (event->object) {
                case EVENT_OBJECT_DHOST:
                result = DBselect(
                "select dr.proxy_hostid,ds.ip"
                " from drules dr,dchecks dc,dservices ds"
                " where dc.druleid=dr.druleid"
                " and ds.dcheckid=dc.dcheckid"
                " and ds.dhostid=" ZBX_FS_UI64
                " order by ds.dserviceid",
                event->objectid);
                break;
                case EVENT_OBJECT_DSERVICE:
                result = DBselect(
                "select dr.proxy_hostid,ds.ip"
                " from drules dr,dchecks dc,dservices ds,dservices ds1"
                " where dc.druleid=dr.druleid"
                " and ds.dcheckid=dc.dcheckid"
                " and ds1.dhostid=ds.dhostid"
                " and ds1.dserviceid=" ZBX_FS_UI64
                " order by ds.dserviceid",
                event->objectid);
                break;
                case EVENT_OBJECT_ZABBIX_ACTIVE:
                result = DBselect("select proxy_hostid,host from autoreg_host"
                " where autoreg_hostid=" ZBX_FS_UI64,
                event->objectid);
                break;
                default:
                return 0;
                }

                if (NULL != (row = DBfetch(result)))
                {
                ZBX_STR2UINT64(proxy_hostid, row[0]);

                if (EVENT_OBJECT_ZABBIX_ACTIVE == event->object)
                {
                host_esc = DBdyn_escape_string_len(row[1], HOST_HOST_LEN);

                result2 = DBselect(
                "select hostid,proxy_hostid"
                " from hosts"
                " where host='%s'"
                DB_NODE,
                host_esc,
                DBnode_local("hostid"));

                if (NULL == (row2 = DBfetch(result2)))
                {
                hostid = DBget_maxid("hosts", "hostid");

                DBexecute("insert into hosts (hostid,proxy_hostid,host,useip,dns)"
                " values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",'%s',0,'%s')",
                hostid,
                proxy_hostid,
                host_esc,
                host_esc);

                }
                else
                {
                ZBX_STR2UINT64(hostid, row2[0]);
                ZBX_STR2UINT64(host_proxy_hostid, row2[1]);

                if (host_proxy_hostid != proxy_hostid)
                {
                DBexecute("update hosts"
                " set proxy_hostid=" ZBX_FS_UI64
                " where hostid=" ZBX_FS_UI64,
                proxy_hostid,
                hostid);
                }
                }
                DBfree_result(result2);

                zbx_free(host_esc);
                }
                else /* EVENT_OBJECT_DHOST, EVENT_OBJECT_DSERVICE */
                {
                alarm(CONFIG_TIMEOUT);
                zbx_gethost_by_ip(row[1], host, sizeof(host));
                alarm(0);

                host_esc = DBdyn_escape_string_len(host, HOST_HOST_LEN);
                ip_esc = DBdyn_escape_string_len(row[1], HOST_IP_LEN);

                port = get_discovered_agent_port(event);

                result2 = DBselect(
                "select hostid,dns,port,proxy_hostid"
                " from hosts"
                " where ip='%s'"
                DB_NODE,
                ip_esc,
                DBnode_local("hostid"));

                if (NULL == (row2 = DBfetch(result2)))
                {
                hostid = DBget_maxid("hosts", "hostid");

                /* for host uniqueness purposes */
                if ('\0' != *host)
                {
                /* by host name */
                make_hostname(host); /* replace not-allowed symbols */
                host_unique = DBget_unique_hostname_by_sample(host);
                }
                else
                {
                /* by ip */
                make_hostname(row[1]); /* replace not-allowed symbols */
                host_unique = DBget_unique_hostname_by_sample(row[1]);
                }

                host_unique_esc = DBdyn_escape_string(host_unique);

                DBexecute("insert into hosts (hostid,proxy_hostid,host,useip,ip,dns,port)"
                " values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",'%s',1,'%s','%s',%d)",
                hostid,
                proxy_hostid,
                /*(*host != '\0' ? host_esc : ip_esc),*/ /* Use host name if exists, IP otherwise */
                host_unique_esc,
                ip_esc,
                host_esc,
                port);

                zbx_free(host_unique);
                zbx_free(host_unique_esc);
                }
                else
                {
                ZBX_STR2UINT64(hostid, row2[0]);
                ZBX_STR2UINT64(host_proxy_hostid, row2[3]);

                if (0 != strcmp(host, row2[1]) || host_proxy_hostid != proxy_hostid)
                {
                DBexecute("update hosts"
                " set dns='%s',proxy_hostid=" ZBX_FS_UI64
                " where hostid=" ZBX_FS_UI64,
                host_esc, proxy_hostid,
                hostid);
                }
                }
                DBfree_result(result2);

                zbx_free(host_esc);
                zbx_free(ip_esc);
                }
                }
                DBfree_result(result);

                if (0 != hostid)
                add_discovered_host_group(hostid, groupid);

                zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);

                return hostid;
                }


                The zabbix programer had set it 0. so it is use dns name.

                Comment

                Working...