Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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

This comment has been minimized.

Owner

gowatana commented Oct 30, 2018

下記の投稿むけ。

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