Network Device Loss and Latency History - response is empty []

Maria97
New here

Network Device Loss and Latency History - response is empty []

I am very new to the Meraki API, and am trying to get the latency for a specific device, but when I ran the request it returns an empty list, even though the response is 200. I'm not sure what I am doing wrong. Here's my code: 

 

headers = {
        'X-Cisco-Meraki-API-Key': MERAKI_API_KEY,
        'Content-Type''application/json',
    }

 

r = requests.get(f"https://api.meraki.com/api/v0/networks/{net_id}/devices/{serial_num}/lossAndLatencyHistory?uplink=wan1&ip=1.2.3.4", headers=headers)
 
print(r)
 
print(r.text)
-------------
OUTPUT:
<Response [200]>
[]
 
network id and serial are  stored in those variables, and the ip address is different. 
 
I appreciate any help.
 
 

 

 

4 Replies 4
Edgar-VO
Building a reputation

Hi there,

 

I think you require also the timespan as a parameter. I use the same calls with API in python. I get the right result.

I put a part of my python code in it... Maybe you can use it. 

 

 

        my_serial = my_device['serial']
        my_dest = {}

        ##################################################################################
        # Get destination IP address which it pings
        ##################################################################################

        my_dst_mon = dashboard.connectivity_monitoring_destinations.getNetworkConnectivityMonitoringDestinations(my_network_id)
        my_dest = my_dst_mon['destinations']

        try:
            my_device_name = my_device['name']
        except:
            my_device_name = my_device['serial']
        #
        # Get first destination IP address
        #

        for i in my_dest:
            my_dst_ip = i['ip']
            break
        
        param = {}
        param['timespan'] = 200
        
        my_latency_results = dashboard.devices.getNetworkDeviceLossAndLatencyHistory(my_network_id,my_serial,my_dst_ip,**param)
        my_network_uplink = dashboard.uplink_settings.getNetworkUplinkSettings(my_network_id)
Edgar-VO
Building a reputation

On small addition....

 

with the line added 

 

my_latency = my_latency_results[-1]
 
You get the latest latency record
 
Cheers
Ed.
rhbirkelund
Kind of a big deal
Kind of a big deal

You'll also need to convert the reply, since it is returning an object with json. Try including this;

 

import json

from pprint import pprint

 

[...]

 

r = requests(...)

if r.status_code == 200:

   rjson = r.json()

   pprint(rjson)

else:

   raise SystemExit(f"Unexpected status code {r.status_code}")

 

LinkedIn ::: https://blog.rhbirkelund.dk/

Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution 🙂

All code examples are provided as is. Responsibility for Code execution lies solely your own.
Edgar-VO
Building a reputation

actually, there is no need for that... 

 

If you do a

 

print(my_latency_results)

 

Then you get all the results

If you use 

 

my_latency = my_latency_results[-1]

print(my_latency) then you get the latest result which might look like this

 

{
    "startTime": "2018-10-09T22:20:27Z",
    "endTime": "2018-10-09T22:21:27Z",
    "lossPercent": 0,
    "latencyMs": 44
  }
]

 

and the latency = my_latency['latencyMs']

and loss will be : loss = my_latency['lossPercent']

 

Get notified when there are additional replies to this discussion.