This file contains 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
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
Nutanix API v2 で Host stats を取得してみる。(Python での別パターン)
http://blog.ntnx.jp/entry/2018/10/30/235548