[ZBX-11481] In some cases the server or proxy does not resolve macros in host interfaces Created: 2016 Nov 14  Updated: 2017 Jun 25  Resolved: 2017 Feb 04

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Proxy (P), Server (S)
Affects Version/s: 2.2.15, 3.0.5, 3.2.1, 3.4.0alpha1
Fix Version/s: 2.2.17rc1, 3.0.8rc1, 3.2.4rc1, 3.4.0alpha1

Type: Incident report Priority: Critical
Reporter: Alexander Vladishev Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: cache, macros
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Configuration:

host name:         127.0.0.1
host visible name: dns

Zabbix agent main interface:
IP:  {HOST.HOST}
DNS: {HOST.NAME}

1st case:

Action message:
{ITEM.NAME} : {ITEM.KEY}

Item name:
item {$M} $1 $2 $3 $4 $5 $6 $7

Item key:
item[{$M}, {HOST.CONN}, {HOST.IP}, {HOST.DNS}, {HOST.HOST}, {HOSTNAME}, {HOST.NAME}]

Generated message:
item host-macro host-macro {HOST.HOST} {HOST.HOST} {HOST.NAME} 127.0.0.1 127.0.0.1 dns : item[host-macro, {HOST.HOST}, {HOST.HOST}, {HOST.NAME}, 127.0.0.1, 127.0.0.1, dns]

Expected:
item host-macro host-macro 127.0.0.1 127.0.0.1 dns 127.0.0.1 127.0.0.1 dns : item[host-macro, 127.0.0.1, 127.0.0.1, dns, 127.0.0.1, 127.0.0.1, dns]

2nd case

Poller can't process items with such interface:
Get value from agent failed: gethostbyname() failed for '{HOST.HOST}': [1] Unknown host


 Comments   
Comment by Sergejs Paskevics [ 2016 Nov 23 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-11481

Comment by Andris Zeila [ 2016 Nov 23 ]

(1) Interface related host macros (HOST_IP, HOST_CONN, HOST_DNS, HOST_PORT) are resolved by using default agent interface rather than the corresponding item interface. This seems to be an old bug, but it should be fixed before (together) with host interface macro resolving.

DBget_item_value() function already contains a partial logic for proper interface macro resolving when processing item name/key macros, although it does not seem quite right. It should be fixed and expanded to support also host ip, dns, conn, port macros. The interface used to resolve the host macros must be chosen by following rules:
1. get interface assigned to the corresponding item or the default Zabbix agent interface if item has no interface
2. resolve HOST_IP, HOST_DNS, HOST_CONN macros in interace ip, dns fields for all interfaces except the main Zabbix agent interface
3. resolve HOST_HOST, HOST_NAME and user macros in interface ip, dns fields for all interfaces

s.paskevics Please check my changes in r64144. I think now it works correctly. RESOLVED

wiper Since it was decided to use configuration cache rather than database it would be better to close this and open new subissues regarding new implementation.
WONTFIX

Comment by Andris Zeila [ 2016 Dec 02 ]

(2) For 2.2 branch we should better keep the original processing for all non interface related macros. Practically that would mean to rewrite DBget_interface_value() funciton to use configuration cache instead of database.

s.paskevics RESOLVED in r64575.

wiper Coding style - in later branches internal configuration cache functions are prefixed with dc_ - dc_get_interface_by_type, dc_get_interface_by_itemid, dc_get_interface_by_type
REOPENED

s.paskevics RESOLVED in r64653.

wiper CLOSED

Comment by Andris Zeila [ 2016 Dec 21 ]

(3) DCsync_interfaces() will not remove deleted interfaces from cache. We should iterate the config->interfaces and check if the interface was updated like it was done before.

s.paskevics RESOLVED in r64653.

wiper CLOSED

Comment by Andris Zeila [ 2016 Dec 23 ]

(4) There are few issues with interface macro processing:

  • resolving MACRO_TYPE_ITEM_KEY and MACRO_TYPE_PARAMS_FIELD macro types - get_interface_value() will lock configuration cache even if the necessary values were available in DC_ITEM structure (for items with known interfaces)
  • resolving MACRO_TYPE_SCRIPT and MACRO_TYPE_HTTPTEST_FIELD macro types will return INTERFACE_TYPE_AGENT type interface while before main interface was returned based on interface type priority list.
  • In DBget_item_value() the ZBX_REQUEST_ITEM_NAME and ZBX_REQUEST_ITEM_KEY requests will lock configuration cache twice
  • In DBget_item_value() we can get interface related data from configuration cache without making database query

s.paskevics RESOLVED in r64803.

wiper The first point was not fixed

resolving MACRO_TYPE_ITEM_KEY and MACRO_TYPE_PARAMS_FIELD macro types - get_interface_value() will lock configuration cache even if the necessary values were available in DC_ITEM structure (for items with known interfaces)

REOPENED

s.paskevics RESOLVED in r64881.

wiper CLOSED

Comment by Andris Zeila [ 2016 Dec 23 ]

(5) In DCsync_interfaces() the existing interface check is done by iterating interfaces vector, which is not optimal. It would be better to store interface identifiers in uint64 vector, sort it and then use bsearch when checking for existing interfaces.

s.paskevics RESOLVED in r64803.

wiper This could be improved more. We are iterating interfaces hashset twice and both times checking if interface should be removed. The second check is redundant, as the deleted interfaces would be already removed.

My suggestion would be to move macro resolving code in separate function and implement separate interaces hashset iterations for main agent and the rest of interface types.
REOPENED

s.paskevics RESOLVED in r64881.

wiper CLOSED

Comment by Andris Zeila [ 2017 Jan 04 ]

Successfully tested, please review changes in r64887

Comment by Sergejs Paskevics [ 2017 Jan 05 ]

Fixed in:

  • pre-2.2.17rc1 r64891,
  • pre-3.0.8rc1 r64897,
  • pre-3.2.4rc1 r64901,
  • pre-3.3.0 (trunk) r64903.
Comment by Sergejs Paskevics [ 2017 Jan 24 ]

(6) (CID 155642) Calling DCconfig_get_interface without checking return value:

DCconfig_get_items_by_itemids(&dc_item, &itemid, &errcode, 1,  ZBX_FLAG_ITEM_FIELDS_DEFAULT);
if (INTERFACE_TYPE_UNKNOWN == dc_item.interface.type)
	DCconfig_get_interface(&dc_item.interface, dc_item.host.hostid, 0);

REOPENED

s.paskevics RESOLVED in development branch svn://svn.zabbix.com/branches/dev/ZBX-11481

wiper DCconfig_get_interface() is still called without checking it's return value.
REOPENED

s.paskevics RESOLVED in r65314.

wiper looks okay, please review minor code improvements in r65351.

s.paskevics Looks good. CLOSED.

glebs.ivanovskis Coverity is happy too, defect is eliminated.

sasha I'm also happy. Thanks!

Comment by Andris Zeila [ 2017 Jan 30 ]

Successfully tested

Comment by Sergejs Paskevics [ 2017 Jan 31 ]

Fixed in:

  • pre-2.2.17rc1 r65399,
  • pre-3.0.8rc1 r65400,
  • pre-3.2.4rc1 r65401,
  • pre-3.3.0 (trunk) r65403.
Comment by richlv [ 2017 Feb 20 ]

(7) nitpicking on the changelog entry :
"fixed resolving macros for ip and dns fields..." -> "fixed resolving macros for the IP and DNS fields..."
"...that are linked to main interface..." - > "...that are linked to the main interface..."

sasha Thanks! RESOLVED in r69504.

CLOSED

Generated at Fri Apr 26 01:24:20 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.