ExportXMLWordPrintable

    • Type: Problem report
    • Resolution: Unresolved
    • Priority: Trivial
    • None
    • Affects Version/s: 6.0.49, 7.0.32, 7.4.16, 8.2.0alpha1
    • Component/s: Agent2 (G)
    • None
    • Environment:
      Zabbix agent 2 7.0.32 (tested, packages from repo.zabbix.com on Ubuntu 24.04). The same code is in
      release/6.0, release/7.0, release/7.4 and master. Zabbix agent (C, zabbix_agentd) is not affected.

      Steps to reproduce

      1. Add to the agent 2 configuration (or an included file):

      Alias=legacy.bond.interface[*]:new.bond.interface[*]
      Alias=legacy.disk.health[*]:new.disk.health[*]
      UserParameter=new.disk.health[*],echo OK $1
      

      2. Test both keys:

      zabbix_agent2 -t 'new.disk.health[8]'
      zabbix_agent2 -t 'legacy.disk.health[8]'
      

      Expected result: both return OK 8; legacy.disk.health[8] is resolved through its alias to
      new.disk.health[8].

      Actual result: new.disk.health[8] returns OK 8, but legacy.disk.health[8] returns
      ZBX_NOTSUPPORTED: Unknown metric legacy.disk.health.

      With the two Alias lines swapped, both keys work. Zabbix agent (C) resolves the alias in either order.

      Cause

      func (m *Manager) Get() in src/go/internal/agent/alias/alias.go walks the wildcard aliases in configuration order.
      When a wildcard alias name (without `*]`) is longer than the requested key, it returns the key unchanged instead of
      trying the next alias:

      	for _, a := range m.aliases {
      		aliasLn := len(a.name)
      		if aliasLn <= 3 || a.name[aliasLn-3:] != `[*]` {
      			continue
      		}
      		if aliasLn-2 > len(orig) {
      			return orig
      		}
      		...
      

      Here legacy.bond.interface[ is 22 characters and legacy.disk.health[8] only 21, so the lookup ends at the first
      alias and never reaches legacy.disk.health[*]. The length check only protects the slice orig[:aliasLn-2] below; an
      alias that is too long simply can't match this key.

      Suggested fix: skip that alias instead of ending the lookup.

      --- a/src/go/internal/agent/alias/alias.go
      +++ b/src/go/internal/agent/alias/alias.go
      @@ func (m *Manager) Get(orig string) string {
       		if aliasLn-2 > len(orig) {
      -			return orig
      +			continue
       		}
      

      A test case for `Get()` with a longer wildcard alias before a matching shorter one would cover it.

      Workaround: order the [*] aliases by name length, shortest first.

            Assignee:
            Zabbix Support Team
            Reporter:
            Martin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: