[ZBX-13071] Zabbix agent ignores non-standard port in ServerActive Created: 2017 Nov 21  Updated: 2017 Nov 21  Resolved: 2017 Nov 21

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent (G)
Affects Version/s: None
Fix Version/s: None

Type: Problem report Priority: Major
Reporter: Andy Feller Assignee: Unassigned
Resolution: Won't fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu Trusty



 Description   

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; 
}


 Comments   
Comment by Andy Feller [ 2017 Nov 21 ]

Issue apparently stemmed from automation triggering service start before custom configuration put into place. Please ignore me .

Generated at Sun May 11 07:51:20 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.