Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-23164

Template Zabbix API Meraki - returns only the last vpnStats endpoint object.

    XMLWordPrintable

Details

    • Team INT
    • Sprint 104 (Sep 2023), Sprint 105 (Oct 2023)
    • 1

    Description

      I don't know if this is the correct channel, but I'm using the zabbix template to collect metrics from the Meraki Dashboard API, to monitor my organization's devices.

      I'm having problems with the Meraki item: Get list of the vpn stats from the Cisco Meraki organization by HTTP template.

      This javascript makes a request on the /appliance/vpn/stats endpoint and performs a loop to retrieve the object for each of the "devices". However, the way the loop is implemented and its return, it always brings the last object found in the request.

      For example, I have more than 50 devices in my organization, the item Meraki: Get list of the networks correctly searches each device and its parameters. The item mentioned above, on the other hand, returns only a single device, which is the last object of the request's json return.

      Is it possible to analyze this problem and apply a fix? Below is the code I mentioned that has the bug.

      Link template: https://www.zabbix.com/br/integrations/meraki

      var params = JSON.parse(value);
      
      var request = new HttpRequest();
      
      request.addHeader('X-Cisco-Meraki-API-Key:' + params.token);
      request.addHeader('User-Agent: ZabbixServer/1.0 Zabbix');
      
      var response,
          error_msg = '',
          vpnStats = [],
          result = [];
      
      function getHttpData(url) {
          response = request.get(url);
          Zabbix.log(4, '[ Meraki API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);
      
          if (response !== null) {
              try {
                  response = JSON.parse(response);
              }
              catch (error) {
                  throw 'Failed to parse response received from Meraki API. Check debug log for more information.';
              }
          }
      
          if (request.getStatus() !== 200) {
              if (response.errors) {
                  throw response.errors.join(', ');
              } else {
                  throw 'Failed to receive data: invalid response status code.';
              }
          }
      
          if (typeof (response) !== 'object' || response === null) {
              throw 'Cannot process response data: received data is not an object.';
          }
      
          return response;
      };
      
      try {
      
          if (params.token === '\{' + '$MERAKI.TOKEN}') {
              throw 'Please change \{' + '$MERAKI.TOKEN} macro with the proper value.';
          }
      
          if (params.url.indexOf('http://') === -1 && params.url.indexOf('https://') === -1) {
              params.url = 'https://' + params.url;
          }
      
          if (!params.url.endsWith('/')) {
              params.url += '/';
          }
      
          if (typeof params.httpproxy !==  'undefined' && params.httpproxy !== '') {
              request.setProxy(params.httpproxy);
          }
      
          vpnStats = getHttpData(params.url + 'organizations/' + encodeURIComponent(params.organizationId) + '/appliance/vpn/stats');
      
          for (i in vpnStats) {
              if (typeof vpnStats[i].merakiVpnPeers !== 'undefined' && Array.isArray(vpnStats[i].merakiVpnPeers)) {
                  for (u in vpnStats[i].merakiVpnPeers) {
                      if (typeof vpnStats[i].merakiVpnPeers[u].latencySummaries !== 'undefined' && Array.isArray(vpnStats[i].merakiVpnPeers[u].latencySummaries)) {
                          for (l in vpnStats[i].merakiVpnPeers[u].latencySummaries) {
                              result = vpnStats[i].merakiVpnPeers[u].latencySummaries.map(function (x) {
      
                                  lps = vpnStats[i].merakiVpnPeers[u].lossPercentageSummaries.filter(function (y) \{ return y.senderUplink == x.senderUplink && y.receiverUplink == x.receiverUplink; });
                                  js = vpnStats[i].merakiVpnPeers[u].jitterSummaries.filter(function (y) \{ return y.senderUplink == x.senderUplink && y.receiverUplink == x.receiverUplink; });
                                  ms = vpnStats[i].merakiVpnPeers[u].mosSummaries.filter(function (y) \{ return y.senderUplink == x.senderUplink && y.receiverUplink == x.receiverUplink; });
                                  Object.assign(x, lps[0], js[0], ms[0]);
      
                                  if ('networkId' in vpnStats[i]) {
                                      x.networkId = vpnStats[i].networkId;
                                  }
                                  if ('networkName' in vpnStats[i]) {
                                      x.networkName = vpnStats[i].networkName;
                                  }
      
                                  if ('networkId' in vpnStats[i].merakiVpnPeers[u]) {
                                      x.peerNetworkId = vpnStats[i].merakiVpnPeers[u].networkId;
                                  }
                                  if ('networkName' in vpnStats[i].merakiVpnPeers[u]) {
                                      x.peerNetworkName = vpnStats[i].merakiVpnPeers[u].networkName;
                                  }
      
                                  return x;
                              });
                          }
                      }
                  }
              }
          }
      
      
      } catch (error) {
          error_msg = error;
      };
      
      return JSON.stringify({
          'vpnStats': result,
          'error': error_msg.toString()
      });
      

      Attachments

        1. avg_loss_l69.png
          avg_loss_l69.png
          301 kB
        2. dash_meraki_l69.png
          dash_meraki_l69.png
          180 kB
        3. postman_l69.png
          postman_l69.png
          82 kB
        4. postman_l69_2.png
          postman_l69_2.png
          68 kB

        Issue Links

          Activity

            People

              egordymov Evgenii Gordymov
              direlys Dierlys
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: