Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-13071

Zabbix agent ignores non-standard port in ServerActive

XMLWordPrintable

    • Icon: Problem report Problem report
    • Resolution: Won't fix
    • Icon: Major Major
    • None
    • None
    • Agent (G)
    • None
    • Ubuntu Trusty

      Steps to reproduce:

      1. Configure non-standard port for Zabbix agent ServerActive parameter
        ### Option: ServerActive
        #       List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
        #       If port is not specified, default port is used.
        #       IPv6 addresses must be enclosed in square brackets if port for that host is specified.
        #       If port is not specified, square brackets for IPv6 addresses are optional.
        #       If this parameter is not specified, active checks are disabled.
        #       Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
        #
        # Mandatory: no
        # Default:
        # ServerActive=
        ServerActive=127.0.0.1:6666
        
      2. Restart zabbix-agent service
      3. Confirm error in /var/log/zabbix/zabbix_agentd.log
        148137:20171121:134157.366 Starting Zabbix Agent [Zabbix server]. Zabbix 2.2.9 (revision 52686).
        148137:20171121:134157.366 using configuration file: /etc/zabbix/zabbix_agentd.conf
        148138:20171121:134157.367 agent #0 started [collector]
        148139:20171121:134157.367 agent #1 started [listener #1]
        148140:20171121:134157.368 agent #2 started [listener #2]
        148141:20171121:134157.368 agent #3 started [listener #3]
        148142:20171121:134157.369 agent #4 started [active checks #1]
        148142:20171121:134157.369 active check configuration update from [127.0.0.1:10051] started to fail (cannot connect to [[127.0.0.1]:10051]: [111] Connection refused)
        

      Digging into the Zabbix agent code the issue appears to be in parse_serveractive_element function as it fails to override the port, which was initialized with the default port:

      /******************************************************************************
       *                                                                            *
       * Function: parse_serveractive_element                                       *
       *                                                                            *
       * Purpose: parse a ServerActive element like "IP<:port>" or "[IPv6]<:port>"  *
       *                                                                            *
       ******************************************************************************/
      int parse_serveractive_element(char *str, char **host, unsigned short *port, unsigned short port_default)
      {
      #ifdef HAVE_IPV6
        char  *r1 = NULL;
      #endif
        char  *r2 = NULL;
        int res = FAIL;
      
        *port = port_default;
      
      #ifdef HAVE_IPV6
        if ('[' == *str)
        {
          str++;
      
          if (NULL == (r1 = strchr(str, ']')))
            goto fail;
      
          if (':' != r1[1] && '\0' != r1[1])
            goto fail;
      
          if (':' == r1[1] && SUCCEED != is_ushort(r1 + 2, port))
            goto fail;
      
          *r1 = '\0';
      
          if (SUCCEED != is_ip6(str))
            goto fail;
      
          *host = zbx_strdup(*host, str);
        }
        else if (SUCCEED == is_ip6(str))
        {
          *host = zbx_strdup(*host, str);
        }
        else 
        {
      #endif
          if (NULL != (r2 = strchr(str, ':')))
          {    
            if (SUCCEED != is_ushort(r2 + 1, port))
              goto fail;
      
            *r2 = '\0';
          }    
      
          *host = zbx_strdup(NULL, str);
      #ifdef HAVE_IPV6
        }
      #endif
      
        res = SUCCEED;
      fail:
      #ifdef HAVE_IPV6
        if (NULL != r1)
          *r1 = ']'; 
      #endif
        if (NULL != r2)
          *r2 = ':'; 
      
        return res; 
      }
      

            Unassigned Unassigned
            andyfeller Andy Feller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: