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:
Is there something I need to change to capture the actual ping response?
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))
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.
pingId = post_response_json['pingId']
Beautifull answer.
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.
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.