Ad Widget

Collapse

Calculated items: reference a key containing macros

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • draco_jem
    Junior Member
    • Mar 2019
    • 1

    #1

    Calculated items: reference a key containing macros

    Hi everyone!

    I'm using an external check to retrieve NTP data from a bunch of servers, the key for the external check is like this:

    ntp_offset.sh["-t","{HOST.CONN}","-s", "213.209.109.45"]

    the script ntp_offset.sh connects to the host specified with -t using ntpq, retrieves the data about the servers and returns the offset specified with the option -s.

    I would like to use the values from the External Check in a calculated item, but using the function

    last( "ntp_offset.sh["-t","{HOST.CONN}","-s","213.209.109.45"]" )

    gives me the following error when Zabbix executes the check

    Cannot evaluate function "last()": item "db-01:ntp_offset.sh["-t","{HOST.CONN}","-s","213.209.109.45"]" does not exist.

    I tried to replace {HOST.CONN} with the IP of the host, the fqdn of the host and the hostname of the host ....same result as before.

    Anyone have succesfully used an External Check or another key containing macros as part of a Calculated Item?
    Is there a way to get the real key of the External Check item with macro expanded?

    Thanks a lot!
  • kansatij
    Junior Member
    Zabbix Certified Specialist
    • Oct 2018
    • 4

    #2
    Yes, I have successfully used an External Check or another key containing macros as part of a Calculated Item.

    1) Example of key containing macro as a calculated item:
    Created below item and it is giving correct result

    Zabbix Agent Item key: net.tcp.port[{HOST.IP},10050]
    Calculated Item key: last("net.tcp.port[{HOST.IP},10050]")

    2) Example of external check containing macro as calculated item
    Created below item and it is also giving correct result

    External check Item key: cores.sh["{HOST.IP}", "{HOST.CONN}"]
    Calculated Item key: last("cores.sh["{HOST.IP}", "{HOST.CONN}"]")

    The issue which you are facing is not occurring due to usage of Macro it is either related to external check Item key doesn't exist already in your system or it is not exactly same as mentioned in calculated Item key.
    Also escape double quotes using \ as shown below:

    Instead of using last( "ntp_offset.sh["-t","{HOST.CONN}","-s","213.209.109.45"]" ) use this last("ntp_offset.sh["-t","{HOST.CONN}","-s","213.209.109.45"]" )
    Last edited by kansatij; 08-04-2019, 09:44.

    Comment

    • kansatij
      Junior Member
      Zabbix Certified Specialist
      • Oct 2018
      • 4

      #3
      In above post escape character is not visible in last line. Please find below its usage
      Instead of using last( "ntp_offset.sh["-t","{HOST.CONN}","-s","213.209.109.45"]" ) use this last("ntp_offset.sh[<esc>"-t<esc>",<esc>"{HOST.CONN}<esc>",<esc>"-s<esc>",<esc>"213.209.109.45<esc>"]" )

      Where <esc> is \ escape character

      Comment

      Working...