Ad Widget

Collapse

Get Values from an API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • caiovernaglia
    Junior Member
    • Dec 2019
    • 2

    #1

    Get Values from an API

    Hello there.

    I have a few equipments that I wanna collect some data through API calling. But there's a catch.
    The process to collect is that:
    1. call a endpoint for login (http://host/login.fcgi) and parse username and password on Body formatted as JSON
    Code:
    {
         "login": "username,
         "password": "password"
    }
    The response of this call is a session token, that i have to use on all others call.
    Code:
    {
         "session":"API_TOKEN"
    }
    2. call the objetc endpoint with the session token as a Query Parameter (http://host/load_objetcs.fcgi?session="API_TOKEN". The object that i want is parsed in Body as JSON


    Till there, no problem at all, i can setup a macro (ie.: {$API_TOKEN}) and use that on all others calls. But this session has a fixed "log out" time. Every 30 minutes i've to redo the login and retrieve another Token.

    I was woundering if i can set up the macro with an item value, this way i can call the login endpoint every 15m and use it's value to set a macro. Then set up others itens that will use this macro as a Query Parameter.


    The Endpoints that i have are:

    Login: host/login.fcgi

    Load Objects: host/load_objects.fcgi?session="API_TOKEN"

    and others but with the same logic


    Any ideas on how I can acomplish that?

    Thanks!

  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Unfortunately you cannot use item value as macro value directly...
    You can have that item value as macro value only, if you have some script, which it updates macro value over API. You can do it in script type item at once... get token and update macro over api. Or use JS preprocessing to do your API call...

    Comment

    Working...