Last active
November 5, 2018 21:53
-
-
Save AndrewWCarson/ee89532412a151ae7f1c17cde830b217 to your computer and use it in GitHub Desktop.
Run a speedtest-cli across all devices in Addigy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # Libraries | |
| import sys | |
| import requests | |
| import json | |
| import re | |
| # Constants | |
| client_id = 'YOUR CLIENT ID HERE' | |
| client_secret = 'YOUR CLIENT SECRET HERE' | |
| headers = { | |
| 'client-id': client_id, | |
| 'client-secret': client_secret | |
| } | |
| domain_url = 'https://prod.addigy.com' | |
| devices_url = '/api/devices' | |
| commands_url = '/api/devices/commands' | |
| policies_url = '/api/policies' | |
| command = '/Library/Addigy/speedtest-cli' | |
| # Start creating the JSON data string | |
| payload = '{"agents_ids":["' | |
| # Error & Success Codes | |
| HTTPS_SUCCESS = 200 | |
| REQUEST_ERR = 'Bad request:' | |
| # Get all the devices from Addigy. | |
| response = requests.get(domain_url + devices_url, params={'client_id':client_id, 'client_secret':client_secret}) | |
| if response.status_code != HTTPS_SUCCESS: | |
| sys.exit(REQUEST_ERR + str(response.status_code) + ":" + devices_url) | |
| # Parse the JSON. | |
| devices_json = json.loads(response.text) | |
| # Build the payload... | |
| # For each device, get the devices Addigy agent ID and add it to the JSON data. | |
| for i, device in enumerate(devices_json): | |
| device = devices_json[i] | |
| payload += device['agentid'] | |
| if i != len(devices_json) - 1: | |
| payload += '", "' | |
| # Close the agents_ids JSON and add the command | |
| payload += '"],"command":"' + command + '"}' | |
| print("This is what properly formatted JSON data for the endpoint looks like.") | |
| print(payload) | |
| # Get all the devices from Addigy. | |
| response = requests.post(domain_url + commands_url, headers=headers, data=payload) | |
| if response.status_code != HTTPS_SUCCESS: | |
| sys.exit(REQUEST_ERR + str(response.status_code) + ":" + commands_url) | |
| commands_json = json.loads(response.text) | |
| print(commands_json) |
Author
It does seems to work with python 3.7.0 on macOS 10.13.6 ...
Did you get to the collecting the results addition...
Author
I'm working on it. A blog post will be coming down the pike with some API goodies soon.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I haven't used this in a while, but it should still work just fine. This just grabs agent-ids from all Addigy devices in your organization and then runs a command across them. I have a separate script command for collecting the results.