Skip to content

Instantly share code, notes, and snippets.

@bkabrda
Created March 31, 2021 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkabrda/eccdd0ae7760052102f64425ffff6bff to your computer and use it in GitHub Desktop.
Save bkabrda/eccdd0ae7760052102f64425ffff6bff to your computer and use it in GitHub Desktop.
import requests, json, csv
api_key = '<apikey>'
application_key = '<appkey>'
url = "https://app.datadoghq.com/reports/v2/overview?api_key="+api_key+"&application_key="+application_key+"&window=3h&metrics=avg%3Asystem.cpu.idle%2Cavg%3Aaws.ec2.cpuutilization%2Cavg%3Avsphere.cpu.usage%2Cavg%3Aazure.vm.processor_total_pct_user_time%2Cavg%3Asystem.cpu.iowait%2Cavg%3Asystem.load.norm.15&with_apps=true&with_sources=true&with_aliases=true&with_meta=true&with_mute_status=true&with_tags=true"
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
r = requests.get(url,headers=headers)
print("status:", r.status_code)
def get_host_agentVersion(data):
host_agent = agent_version(data)
with open ("host_agent_all.json",'w') as outfile:
json.dump(host_agent, outfile)
print("saved host_agent_all.json")
def agent_version(data):
host_agent = []
for hosts in data["rows"]:
if "agent_version" in hosts["meta"]:
host_agent.append({"host_name": hosts["host_name"],"agent_version": hosts["meta"]["agent_version"], "os": hosts.get("meta", {}).get("nixV", [])})
print("extract host and agent version")
return host_agent
if r.status_code == 200:
data = r.json()
with open ("JSON_API_permalink.json",'w') as outfile:
json.dump(r.json(), outfile)
print("saved JSON_API_permalink.json")
get_host_agentVersion(data)
# example output in host_agent_all.json for a single host:
#
# {
# "host_name": "example.host.com",
# "agent_version": "6.26.0-rc.7",
# "os": [
# "ubuntu",
# "18.04",
# ""
# ]
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment