Ad Widget

Collapse

Convert API-obtained value into parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Adriano Trindade
    Junior Member
    • May 2022
    • 19

    #1

    Convert API-obtained value into parameter

    Hello!

    I use an "HTTP Agent" item type to query Zabbix API successfully.

    The first step in obtaining API internal data is running the "user.login" method and obtaining an ID and access token from localhost. This item does just that, and feeds two dependent items that store the ID and result (token).

    At this point, I have a host with two dependent itens storing the resulting ID and the token successfully. Until this point everything is fine.

    On the next step, I need to query Zabbix API for a list of proxies in the system. For this, I created an discovery rule (HTTP Agent) that queries the API object "proxy.get" to obtain a list of proxies, in order to feed a LLD macro with the proxy names, so I can create an item for each proxy. My environment have almost 300 proxies, so I need to automate that discovery in order to generate alerts when a proxy delay is too high, and to keep the proxy list updated as I add and remove proxies.

    My problem is: how I insert the data from "ID" and "Token" items obtained on the master items inside the "proxy.get" request body? I tought about using macros, but I couldn“t find a way to feed the data obtained from the items into two macros. so I don't know if it's a good approach.

    Another possibility is to reference the data from the items directly inside the request body (that looks more elegant), but I have tried in many ways and had no luck with that.

    What I am missing on this problem? Is there a third approach that I don't know or something I'm doing wrong?

    Thanks in advance for any help.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    I can see, what you are trying to do, but ... you really cannot use one items value in other item as parameter..
    For this either write a external script, which you can call and what returns all your proxies (python maybe?).
    Or you can use a script type item and do everything in that script (JS)...
    Or use preprocessing of that http item (type javascript) and write whole logic in that JS...

    Comment

    • Adriano Trindade
      Junior Member
      • May 2022
      • 19

      #3
      Thanks on your reply!

      Every time I have to use a script to do something that Zabbix can't, I see room for improvement of the Zabbix software.

      The simple possibility to reference some collected data in a macro-like way would avoid me having a solution outside Zabbix (a script) and would open many other possibilities for the Zabbix platform.

      As I can't do what I need solely inside Zabbix, I will follow your advice and make a script to do what I need.

      Thanks again,

      Comment

      Working...