Meraki API PING livetool to keep the VPN going with Interesting Traffic

network_jlmp
Conversationalist

Meraki API PING livetool to keep the VPN going with Interesting Traffic

Hi All,


I'm new to APIs. We reached out to Meraki support in order to resolve an issue with VPN going down without interesting traffic. The solution offered was using the API Ping livetools.

Here is the script from the Developer website:

 

import requests

url = "https://api.meraki.com/api/v1/devices/xxxx-xxxx-xxxx/liveTools/ping"

payload = '''{
"target": "10.1.19.1",
"count": 5
}'''

headers = {
"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
"Accept": "application/json"
}

response = requests.request('POST', url, headers=headers, data = payload)

print(response.text.encode('utf8'))

 

Here is the response we are getting when running the script:

network_jlmp_0-1717689532339.png

 

Is there something I need to change to capture the actual ping response?

 

6 Replies 6
alemabrahao
Kind of a big deal
Kind of a big deal

I believe the problem is the response using utf8. Try this script.

import requests
import json

url = "https://api.meraki.com/api/v1/devices/xxxx-xxxx-xxxx/liveTools/ping"

payload = '''{
"target": "10.1.19.1",
"count": 5
}'''

headers = {
"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
"Accept": "application/json"
}

response = requests.request('POST', url, headers=headers, data = payload)

# Parse the JSON response
response_json = json.loads(response.text)

# Pretty print the JSON
print(json.dumps(response_json, indent=4))

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
network_jlmp
Conversationalist

Thank you for the solution. Its prettier now. 😄
- Now its a bit clearer to me. POST initiate the ping, GET prints the result of the ping.

- The POST generates a pingID that is used as a parameter for the GET command.

 

Below is the result if the POST command:

   {
      "pingId": "ZZZZZZZZZZZZZZZZZZZZZZZZ",
      "url": "/devices/XXXX-XXXX-XXXX/liveTools/ping/ZZZZZZZZZZZZZZZZZZZZZZZZ",
      "request": {
            "serial": "XXXX-XXXX-XXXX",
            "target": "10.1.19.1",
            "count": 5
       },
      "status": "new"
   }

 

In order to run the GET command, i need to take pingid and use it as parameter on the below command:

import requests
import json

url = "https://api.meraki.com/api/v1/devices/XXXX-XXXX-XXXX/liveTools/ping/ZZZZZZZZZZZZZZZZZZZZZZZZ"

payload = None

headers = {
"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Accept": "application/json"
}

response = requests.request('GET', url, headers=headers, data = payload)

response_json = json.loads(response.text)

print(json.dumps(response_json, indent=4))


Is there a way to get the pingID to auto-populate my GET script? I will be running this scripts via Task Scheduler. 

alemabrahao
Kind of a big deal
Kind of a big deal


pingId = post_response_json['pingId']

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
PhilipDAth
Kind of a big deal
Kind of a big deal

Beautifull answer.

PhilipDAth
Kind of a big deal
Kind of a big deal

Going sideways - why does it matter if that VPN goes down when there is no traffic?  As long as it comes up invisibly when there is traffic?

 

Another option is to use the OS task scheduler to regularly run the ping command to send traffic as well - but I'm not sure if there is anything to be gained.

network_jlmp
Conversationalist

This is a Meraki to non-meraki S2S VPN. For some reason, the tunnel won't come up without manually pinging the remote site from the Meraki Dashboard.

Get notified when there are additional replies to this discussion.