[ZBX-4725] Discovery rule "external check" does not work if item parameter is a macro Created: 2012 Mar 02  Updated: 2017 May 30  Resolved: 2012 Mar 14

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Proxy (P), Server (S)
Affects Version/s: 2.0.0rc1
Fix Version/s: 2.0.0rc1

Type: Incident report Priority: Major
Reporter: Simon Kowallik Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: discovery, lld, macros
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When creating a discovery rule inside a template with type "external check" and using a macro like

{HOST.IP} as a parameter to pass to the specified script in the key, zabbix fails to match the returned JSON.
Example:
key is: script.name[{HOST.IP}

,param1,param2]

Template is assigned to host with IP 198.18.0.123.

zabbix_server.log (Debug:4) says:

11507:20120302:191438.614 In substitute_key_macros() data:'script.name[

{HOST.IP},param1,param2]'
11504:20120302:191438.614 End of get_values():0
11507:20120302:191438.614 In substitute_simple_macros() data:'{HOST.IP}

'

11507:20120302:191438.614 End substitute_simple_macros() data:'198.18.0.123'
11504:20120302:191438.614 In DCconfig_get_poller_nextcheck() poller_type:0
11507:20120302:191438.614 End of substitute_key_macros():SUCCEED data:'script.name[198.18.0.123,param1,param2]'
11504:20120302:191438.614 End of DCconfig_get_poller_nextcheck():1330712079
11507:20120302:191438.614 In get_value() key:'script.name[

{HOST.IP},param1,param2]'
11504:20120302:191438.614 sleeping for 1 seconds
11507:20120302:191438.614 In get_value_external() key:'script.name[{HOST.IP}

,param1,param2]'
11505:20120302:191438.615 get_snmp() snmp_synch_response():0
11507:20120302:191438.615 In zbx_popen() command:'/opt/zabbix/share/zabbix/externalscripts/script.name "198.18.0.123" "param1" "param2"'

11507:20120302:191438.705 query [txnlev:1] [begin;]
11507:20120302:191438.705 query [txnlev:1] [update items set lastclock=1330712078,lastns=704097134,error='Cannot find the "script.name[

{HOST.IP},param1,param2]" key in received JSON object' where itemid=22508]
11507:20120302:191438.705 query [txnlev:1] [commit;]
11507:20120302:191438.708 End of DBlld_process_discovery_rule()

Zabbix expects the script to return a JSON object with object name "script.name[{HOST.IP}

,param1,param2]" where the script would return "script.name[198.18.0.123,param1,param2]".

That makes macros unusable as a parameter to the script. The script would never know what macro was supplied, just the value of the macro.

I believe this is a bug.

  1. zabbix_server -V
    Zabbix server v1.9.10 (revision 25576) (01 February 2012)
    Compilation time: Feb 24 2012 10:47:31

Kind regards,
simon



 Comments   
Comment by Oleksii Zagorskyi [ 2012 Mar 04 ]

Yes, the macro

{HOST.IP<1-9>}

should be supported for "Item key's parameters"
http://www.zabbix.com/documentation/2.0/manual/appendix/macros/supported_by_location

Comment by Simon Kowallik [ 2012 Mar 04 ]

Dear Oleksiy,

{HOST.IP<1-9>} is supported. That's not the point.

The point is, that when using a macro the script will receive the macro value. In case of {HOST.IP<1-9>}

it will be an IP address.
Therefore the script will return the IP in the JSON object.

Zabbix currently expects the script to return the configured key exactly like this: 'script.name[

{HOST.IP}

,param1,param2]'
That is a problem, as the script will not have any information about the used macro as it receives an IP address and not the macro itself.

The script returns the IP instead of the macro, like this: 'script.name[198.18.0.123,param1,param2]'

Zabbix should deal with that.

br

Comment by richlv [ 2012 Mar 04 ]

could you please clarify where exactly are you using the string "script.name[

{HOST.IP}

,param1,param2]" ?

Comment by Simon Kowallik [ 2012 Mar 04 ]

In the key field, as documented.
http://imageshack.us/photo/my-images/24/zabbixlld.png/

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
More details:

Zabbix will call the script like:
/opt/zabbix/share/zabbix/externalscripts/script.name "198.18.0.123" "param1" "param2"

Log > 11507:20120302:191438.615 In zbx_popen() command:'/opt/zabbix/share/zabbix/externalscripts/script.name "198.18.0.123" "param1" "param2"'

Naturally the script would return this JSON object:
{
"script.name[198.18.0.123,param1,param2]": [
{
"

{#MYINDEX1}": "1",
"{#MYVALUE}": "1000"
},
{
"{#MYINDEX1}

": "2",
"

{#MYVALUE}": "2000"
},
{
"{#MYINDEX1}": "3",
"{#MYVALUE}

": "3000"
}
]
}
Zabbix will not accept that object because it tries to match it to the key value, which is: 'script.name[

{HOST.IP},param1,param2]' (without single quotes)

Log > 11507:20120302:191438.705 query [txnlev:1] [update items set lastclock=1330712078,lastns=704097134,error='Cannot find the "script.name[{HOST.IP}

,param1,param2]" key in received JSON object' where itemid=22508]

When the script returns the macro name in the JSON object it works.
But how does the script determine which macro was used?
-> Zabbix has to accept the VALUE OF THE USED MACRO, not the MACRO NAME in the JSON object.

Working JSON object, returned by the script.
{
"script.name[

{HOST.IP}

,param1,param2]": [
{
"

{#MYINDEX1}": "1",
"{#MYVALUE}": "1000"
},
{
"{#MYINDEX1}

": "2",
"

{#MYVALUE}": "2000"
},
{
"{#MYINDEX1}": "3",
"{#MYVALUE}

": "3000"
}
]
}

Comment by richlv [ 2012 Mar 04 ]

hmm. why use the macro at all then ?

also, it's better to attach images directly to the issue, that way they are more permanent (and imageshack is terrible, i can never get the full size image there )

Comment by Simon Kowallik [ 2012 Mar 04 ]

Well I use the macro because I define this discovery rule inside a Template. And I would like to assign that Template to a lot of devices.

Attaching an Image does not work for me. Java Clipboard Copy&Paste is not very nice. Sorry.

Comment by richlv [ 2012 Mar 04 ]

at the top of this issue, there should be "more actions -> attach files"
but my question was - why use the macro at all ? if this is a discovery rule, it would usually work the same in all hosts. if you have to customise something, wouldn't it be in auto-created item keys instead ?

Comment by Simon Kowallik [ 2012 Mar 04 ]

The script needs an IP address or Hostname to connect to. That's why it needs a macro, or IP, or Host.
It will not be executed by a Zabbix Agent.

See: https://github.com/simonkowallik/Zabbix-Addons

Comment by richlv [ 2012 Mar 04 ]

ah, right, sorry - missed the fact that it's an external check.
right, this scenario might not work that well currently.

Comment by Alexander Vladishev [ 2012 Mar 06 ]

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

Fixed documentation:
http://www.zabbix.com/documentation/2.0/manual/discovery/low_level_discovery?&#discovery_item_json_format

Now, a JSON object should contain not an item key but "data".

For example:

old JSON object
{"net.if.discovery":[{"

{#IFNAME}":"lo"}, {"{#IFNAME}

":"eth0"}, {"

{#IFNAME}":"eth1"}]}

new:
{"data":[{"{#IFNAME}

":"lo"}, {"

{#IFNAME}":"eth0"}, {"{#IFNAME}

":"eth1"}]}

Comment by Oleksii Zagorskyi [ 2012 Mar 06 ]

Sasha, regarding this changes, will trunk agents 1.9.x-1.9.9 (agents compiled before this change) work with latest revisions of zabbix server ?
Or trunk agents should be updated (recompiled) too?

<Sasha> Yes, all agents should be recompiled too. LLD checks won't work with the old 1.9.9 agent and the new 1.9.10 server.

Comment by dimir [ 2012 Mar 13 ]

Fix components.

Comment by dimir [ 2012 Mar 13 ]

Brilliant, works like a charm.

Comment by Alexander Vladishev [ 2012 Mar 13 ]

Fixed in the version pre-2.0.0rc1, r26035.

Comment by dimir [ 2012 Mar 14 ]

Reopening to fix title.

Comment by dimir [ 2012 Mar 14 ]

Fix title

Comment by dimir [ 2012 Mar 14 ]

Close issue

Comment by Oleksii Zagorskyi [ 2012 Mar 15 ]

Just a note for my latest comment:

If use zabbix agent versions 1.9.1-1.9.9 (beta versions) with zabbix server version 2.0.x then LLD will not work and every discovery rule will have this error description:
Cannot find the "data" array in the received JSON object

Comment by Kenneth Palmertree [ 2014 Jul 14 ]

This looks like it broke again in 2.2.4. Was working in 2.2.3. External scripts using macros in lld keys get json errors back.

Comment by Oleksii Zagorskyi [ 2014 Jul 14 ]

Kenneth, if it is then you would need to create another ZBX report.

Generated at Fri Apr 19 16:56:53 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.