Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created October 30, 2018 14:25
Show Gist options
  • Save gowatana/c982ad59e365d06a1444ec20362e27e8 to your computer and use it in GitHub Desktop.
Save gowatana/c982ad59e365d06a1444ec20362e27e8 to your computer and use it in GitHub Desktop.
#!/bin/python
import sys
import json
import requests
import datetime
args = sys.argv
conf_file = args[1]
insecure_warn = requests.packages.urllib3.exceptions.InsecureRequestWarning
with open(conf_file, "r") as file:
conf = file.read()
conf = json.loads(conf)
prism_addr = conf["prism_address"]
prism_user = conf["user_name"]
prism_pass = conf["password"]
def main():
base_url = 'https://' + prism_addr + ':9440/PrismGateway/services/rest/v2.0/'
requests.packages.urllib3.disable_warnings(insecure_warn)
s = requests.Session()
s.auth = (prism_user, prism_pass)
s.headers.update({'Content-Type': 'application/json; charset=utf-8'})
ts = datetime.datetime.now()
ts_str = ts.isoformat()
data = s.get(base_url + 'hosts', verify=False).json()
for entity in data['entities']:
hv_name = entity['name']
stats = entity['stats']
#stats = entity['usage_stats']
for stat_key in stats:
stat_value = stats[stat_key]
to_csv_list = (ts_str, hv_name, stat_key, stat_value)
print(','.join(to_csv_list))
if __name__ == '__main__':
main()
@gowatana
Copy link
Author

下記の投稿むけ。

Nutanix API v2 で Host stats を取得してみる。(Python での別パターン)
http://blog.ntnx.jp/entry/2018/10/30/235548

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment