Ad Widget

Collapse

How to get a HTTP token from one item and use it in another item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • claudio_ract
    Junior Member
    • Mar 2024
    • 4

    #1

    How to get a HTTP token from one item and use it in another item

    Hi Guys,

    I have a 3par storage and I am trying to monitor it by HTTP.

    To simplyfy, i will use two API.
    • API 1: /api/v1/credentials
    $ curl -k -H "Accept:application/json" -H "Content-Type:application/json" --data-binary '{"user":"3paruser","password":"3parpassword"}' 'http://10.10.10.10:8008/api/v1/credentials'
    HTML Code:
    {"key":"0-1474a9cd79710b419b1d0fe9e0be1ace-8871fc65"}
    • API 2: /api/v1/credentials
    $ curl -k -H "X-HP3PAR-WSAPI-SessionKey: 0-18a4bdb7fd67ff95203b32581bae7ef2-e02d0366" http://10.160.107.34:8008/api/v1/cpgs -s
    HTML Code:
    {"total":7,"members":[{"id":0,"uuid":"8518cb0e-6c7e-4bfc-bd70-731758789ea6","name":"SSD_r1","numFPVVs":0,"numTPV Vs":5,"numTDVVs":0,"UsrUsage":{"totalMiB":4751744, "rawTotalMiB":9503488,"usedMiB":4751744,"rawUsedMi B":9503488},"SAUsage":{"totalMiB":16384,"rawTotalM iB":49152,"usedMiB":6144,"rawUsedMiB":18432},"SDUs age":{"totalMiB":165504,"rawTotalMiB":331008,"used MiB":0,"rawUsedMiB":0},"privateSpaceMiB":{"base":4 751744,"rawBase":9503488,"snapshot":0,"rawSnapshot ":0},"sharedSpaceMiB":0,"rawSharedSpaceMiB":0,"fre eSpaceMiB":165504,"rawFreeSpaceMiB":331008,"totalS paceMiB":4917248,"rawTotalSpaceMiB":9834496,"SAGro wth":
    .
    .
    .

    How to get a HTTP token from API 1 item and use it in API 2 to collect some information about my storage ?



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

    #2
    It is not possible to use one items value in other items parameters unfortunately...
    Use script type item: use JS to do both queries in one run... https://www.zabbix.com/documentation...emtypes/script

    Comment

    • claudio_ract
      Junior Member
      • Mar 2024
      • 4

      #3
      Originally posted by cyber
      It is not possible to use one items value in other items parameters unfortunately...
      Use script type item: use JS to do both queries in one run... https://www.zabbix.com/documentation...emtypes/script
      Perfect. after spending all my day studying script itens and JS, follow bellow the code that worked fine (there are two input parameters in item created: user and password):

      Code:
      var parameters = JSON.parse(value);
      var senha = parameters.password;
      var usuario = parameters.user;
      
      var request = new HttpRequest();
      var payload = parameters.user + " " + parameters.password;
      
      json_request = JSON.stringify({"user": usuario,"password": senha})
      
      
      request.addHeader('Content-Type: application/json');
      res = request.post('http://ip_adress:8008/api/v1/credentials', json_request);
      
      if (request.getStatus() != 201) {
      throw 'Response code: '+request.getStatus();
      }
      
      res = JSON.parse(res);
      
      request.addHeader('X-HP3PAR-WSAPI-SessionKey: '+res.key);
      res = request.get('http://10.160.107.34:8008/api/v1/cpgs');
      
      //return JSON.stringify(res.key);
      return JSON.stringify(res);

      Comment

      • ANigma91
        Junior Member
        • Apr 2022
        • 21

        #4
        Originally posted by claudio_ract
        Hi Guys,

        I have a 3par storage and I am trying to monitor it by HTTP.

        To simplyfy, i will use two API.
        • API 1: /api/v1/credentials
        $ curl -k -H "Accept:application/json" -H "Content-Type:application/json" --data-binary '{"user":"3paruser","password":"3parpassword"}' 'http://10.10.10.10:8008/api/v1/credentials'
        HTML Code:
        {"key":"0-1474a9cd79710b419b1d0fe9e0be1ace-8871fc65"}
        • API 2: /api/v1/credentials
        $ curl -k -H "X-HP3PAR-WSAPI-SessionKey: 0-18a4bdb7fd67ff95203b32581bae7ef2-e02d0366" http://10.160.107.34:8008/api/v1/cpgs -s
        HTML Code:
        {"total":7,"members":[{"id":0,"uuid":"8518cb0e-6c7e-4bfc-bd70-731758789ea6","name":"SSD_r1","numFPVVs":0,"numTPV Vs":5,"numTDVVs":0,"UsrUsage":{"totalMiB":4751744, "rawTotalMiB":9503488,"usedMiB":4751744,"rawUsedMi B":9503488},"SAUsage":{"totalMiB":16384,"rawTotalM iB":49152,"usedMiB":6144,"rawUsedMiB":18432},"SDUs age":{"totalMiB":165504,"rawTotalMiB":331008,"used MiB":0,"rawUsedMiB":0},"privateSpaceMiB":{"base":4 751744,"rawBase":9503488,"snapshot":0,"rawSnapshot ":0},"sharedSpaceMiB":0,"rawSharedSpaceMiB":0,"fre eSpaceMiB":165504,"rawFreeSpaceMiB":331008,"totalS paceMiB":4917248,"rawTotalSpaceMiB":9834496,"SAGro wth":
        .
        .
        .
        How to get a HTTP token from API 1 item and use it in API 2 to collect some information about my storage ?


        Good afternoon! Can you tell me what kind of template you use for monitoring 3par

        Comment

        Working...