Ad Widget

Collapse

HTTP agent to access API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • linkwood
    Junior Member
    • Feb 2019
    • 1

    #1

    HTTP agent to access API

    I'm trying to access an API with a HTTP agent.
    So far this works fine, as long as I do not have to authenticate.
    Now I need to authenticate (with an user.login request) an I receive an auth token.
    This token needs to be sent with any further request.

    Do I have to create a item with the authentication and save the token? And then create other items to do the real work?
    Or, can I do this in one item?
    Any suggestions?
  • HellLordKB
    Junior Member
    • Feb 2015
    • 10

    #2
    I also have this issue. The http agent check item in zabbix supports NTLM, basic auth and no auth. I need to be able call an api with a Bearer Token aka auth token. This is a two step process where i call one URL and pass either an api access key or an api access key and secret key and have the http agent item capture the Bearer token and pass that token string in on the next call in the X-Auth_Token header.

    how can I achieve this?

    Comment

    • kloczek
      Senior Member
      • Jun 2006
      • 1771

      #3
      Originally posted by linkwood
      I'm trying to access an API with a HTTP agent.
      So far this works fine, as long as I do not have to authenticate.
      Now I need to authenticate (with an user.login request) an I receive an auth token.
      This token needs to be sent with any further request.

      Do I have to create a item with the authentication and save the token? And then create other items to do the real work?
      Or, can I do this in one item?
      Any suggestions?
      Try to start from my zapish as probably simplest ever example of using zabbix API calls.
      On first use of the zapish zabbix_api() shell function in your script will ask you about zabbix server AP GW URL, username and password. Then thiose data will be used to authenticate to API GW and received auth token will be stored ~/.zapish.rc. As long as this file exest and contain valid toked all next zabbix_api() will be using that stored token on doing all zabbix API calls without propting for GW URL, username and password.
      zapish - Zabbix API SHell binding. Contribute to kloczek/zapish development by creating an account on GitHub.
      http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
      https://kloczek.wordpress.com/
      zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
      My zabbix templates https://github.com/kloczek/zabbix-templates

      Comment

      • olsoncr
        Junior Member
        • Nov 2019
        • 7

        #4
        this also works:

        Comment

        • dimir
          Zabbix developer
          • Apr 2011
          • 1080

          #5
          You can use Script item which appeared in Zabbix 5.2 . An example JavaScript code that uses HttpRequest with access token that is first fetched could be found in one of the official templates:


          Comment

          Working...