Ad Widget

Collapse

Use HTTP agent to read JSON-RPC 2.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doba
    Junior Member
    • Nov 2020
    • 7

    #1

    Use HTTP agent to read JSON-RPC 2.0

    Hi
    I would like to connect to the Teltonika modem device using json-rpc 2 and using HTTP agent in zabbix server.
    But I can not use a name, password to get data immediately in one step.

    When I read the manual from the teltonika site, the first step is to get a token. The token expires after 300 s, so I read the item every 240s (4m). The second step is to get data using the token.

    First I made an HTTP agent to POST json and get a token in response. I have successfully got json answer. I have set preprocessing using Jsonpath and store token every 4 minutes. In the next step, I would like to use a token to login and get data.
    Is it possible to use (link) value from the first step to send another HTTP POST request?


    First step - sucesfully DONE

    #first request

    #preprocessing rule

    In my zabbix key:request , item name:auth
    Second step - I haven´t done yet automatically. Tested with token manually and works. See the picture below.

    #second request

    Can I substitute token with the latest value of token saved in key request (from my first step)? Something like: {my_host:request.last()} ? Is there another option?
    Last edited by doba; 06-11-2020, 13:50.
  • doba
    Junior Member
    • Nov 2020
    • 7

    #2
    Hi
    Is it possible to save a value of the item to macro via Javascript preprocessing?
    First rule is JSON path that work, second doesn´t.
    I tried this code, but I got an error.
    Click image for larger version

Name:	preprocessing1.PNG
Views:	1400
Size:	8.3 KB
ID:	412825
    Click image for larger version

Name:	preprocess_dalsi.PNG
Views:	1388
Size:	6.8 KB
ID:	412826


    Thanks in advance. D.

    Comment

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

      #3
      Originally posted by doba
      Can I substitute token with the latest value of token saved in key request (from my first step)? Something like: {my_host:request.last()} ? Is there another option?
      I think directly it is not possible...

      As docs (https://www.zabbix.com/documentation...ed_by_location) say
      {host:key.func(param)} can only be used in
      → Trigger-based notifications and commands
      → Problem update notifications and commands
      → Map element/shape labels
      → Link labels in maps
      → Graph names
      → Trigger expressions

      So, not on HTTP items "query" field...

      But you can use user macros there (https://www.zabbix.com/documentation..._location_user)... So, with a bit of coding (JS preprocessing...) you should be able to update a host level macro, where you keep that acquired value... Just don't ask me for any examples..​ I suck at coding..​ But I have seen similar approach to update some date related global macros. Or you move that first step, acquiring a token, into a script somewhere on zabbix server, and update that macro from there, gives you more coding language options....

      Comment

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

        #4
        You need to do a API call inside that JS to set a macro value.

        Comment

        Working...